summaryrefslogtreecommitdiff
path: root/lib/Travelynx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travelynx')
-rw-r--r--lib/Travelynx/Command/database.pm29
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm15
2 files changed, 34 insertions, 10 deletions
diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm
index 7a714b1..4175d58 100644
--- a/lib/Travelynx/Command/database.pm
+++ b/lib/Travelynx/Command/database.pm
@@ -71,7 +71,28 @@ sub initialize_db {
);
}
-my @migrations = ();
+my @migrations = (
+
+ # v0 -> v1
+ sub {
+ my ($dbh) = @_;
+ return $dbh->do(
+ qq{
+ alter table user_actions
+ add column edited smallint;
+ drop table if exists monthly_stats;
+ create table journey_stats (
+ user_id integer not null references users (id),
+ year smallint not null,
+ month smallint not null,
+ data jsonb not null,
+ primary key (user_id, year, month)
+ );
+ update schema_version set version = 1;
+ }
+ );
+ },
+);
sub run {
my ( $self, $command ) = @_;
@@ -96,18 +117,18 @@ sub run {
}
for my $i ( $schema_version .. $#migrations ) {
printf( "Updating to v%d ...\n", $i + 1 );
- if ( not $migrations[$i]() ) {
+ if ( not $migrations[$i]($dbh) ) {
say "Aborting migration; rollback to v${schema_version}";
$dbh->rollback;
last;
}
}
- if ( get_schema_version($dbh) == $#migrations ) {
+ if ( get_schema_version($dbh) == @migrations ) {
$dbh->commit;
}
}
elsif ( $command eq 'has-current-schema' ) {
- if ( get_schema_version($dbh) == $#migrations ) {
+ if ( get_schema_version($dbh) == @migrations ) {
say "yes";
}
else {
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index a83adb0..dee69a6 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -285,7 +285,9 @@ sub monthly_history {
qw(Januar Februar März April Mai Juni Juli August September Oktober November Dezember)
);
- if ( not( $year =~ m{ ^ [0-9]{4} $ }x and $month =~ m{ ^ [0-9]{1,2} $ }x ) )
+ if ( $cancelled
+ or
+ not( $year =~ m{ ^ [0-9]{4} $ }x and $month =~ m{ ^ [0-9]{1,2} $ }x ) )
{
@journeys = $self->get_user_travels( cancelled => $cancelled );
}
@@ -301,12 +303,13 @@ sub monthly_history {
);
my $interval_end = $interval_start->clone->add( months => 1 );
@journeys = $self->get_user_travels(
- cancelled => $cancelled,
- verbose => 1,
- after => $interval_start,
- before => $interval_end
+ after => $interval_start,
+ before => $interval_end
+ );
+ $stats = $self->get_journey_stats(
+ year => $year,
+ month => $month
);
- $stats = $self->compute_journey_stats(@journeys);
}
$self->respond_to(