summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Command/database.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-08-23 10:34:02 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-08-23 10:34:02 +0200
commitf6d56d3134f6045726cb1d4ed8700382575bb686 (patch)
tree82bdf8b59acfefd6fb001d6be807915834ee64a9 /lib/Travelynx/Command/database.pm
parentd08c1ead330f80ef1ae5f477f6d47a45f5793bb0 (diff)
Add proper journey comment support
Diffstat (limited to 'lib/Travelynx/Command/database.pm')
-rw-r--r--lib/Travelynx/Command/database.pm75
1 files changed, 75 insertions, 0 deletions
diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm
index c52a0a9..8df573f 100644
--- a/lib/Travelynx/Command/database.pm
+++ b/lib/Travelynx/Command/database.pm
@@ -705,6 +705,81 @@ my @migrations = (
}
);
},
+
+ # v16 -> v17
+ sub {
+ my ($db) = @_;
+ $db->query(
+ qq{
+ drop view journeys_str;
+ drop view in_transit_str;
+ alter table journeys add column user_data jsonb;
+ alter table in_transit add column user_data jsonb;
+ create view journeys_str as select
+ journeys.id as journey_id, user_id,
+ train_type, train_line, train_no, train_id,
+ extract(epoch from checkin_time) as checkin_ts,
+ extract(epoch from sched_departure) as sched_dep_ts,
+ extract(epoch from real_departure) as real_dep_ts,
+ dep_stations.ds100 as dep_ds100,
+ dep_stations.name as dep_name,
+ extract(epoch from checkout_time) as checkout_ts,
+ extract(epoch from sched_arrival) as sched_arr_ts,
+ extract(epoch from real_arrival) as real_arr_ts,
+ arr_stations.ds100 as arr_ds100,
+ arr_stations.name as arr_name,
+ cancelled, edited, route, messages, user_data,
+ dep_platform, arr_platform
+ from journeys
+ join stations as dep_stations on dep_stations.id = checkin_station_id
+ join stations as arr_stations on arr_stations.id = checkout_station_id
+ ;
+ create view in_transit_str as select
+ user_id,
+ train_type, train_line, train_no, train_id,
+ extract(epoch from checkin_time) as checkin_ts,
+ extract(epoch from sched_departure) as sched_dep_ts,
+ extract(epoch from real_departure) as real_dep_ts,
+ dep_stations.ds100 as dep_ds100,
+ dep_stations.name as dep_name,
+ extract(epoch from checkout_time) as checkout_ts,
+ extract(epoch from sched_arrival) as sched_arr_ts,
+ extract(epoch from real_arrival) as real_arr_ts,
+ arr_stations.ds100 as arr_ds100,
+ arr_stations.name as arr_name,
+ cancelled, route, messages, user_data,
+ dep_platform, arr_platform
+ from in_transit
+ join stations as dep_stations on dep_stations.id = checkin_station_id
+ left join stations as arr_stations on arr_stations.id = checkout_station_id
+ ;
+ }
+ );
+ for my $journey ( $db->select( 'journeys', [ 'id', 'messages' ] )
+ ->expand->hashes->each )
+ {
+ if ( $journey->{messages}
+ and @{ $journey->{messages} }
+ and $journey->{messages}[0][0] == 0 )
+ {
+ my $comment = $journey->{messages}[0][1];
+ $db->update(
+ 'journeys',
+ {
+ user_data =>
+ JSON->new->encode( { comment => $comment } ),
+ messages => undef
+ },
+ { id => $journey->{id} }
+ );
+ }
+ }
+ $db->query(
+ qq{
+ update schema_version set version = 17;
+ }
+ );
+ },
);
sub setup_db {