@golemio/pid 2.10.2-dev.1104369146 → 2.10.2-dev.1105087628

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var dbm;
4
+ var type;
5
+ var seed;
6
+ var fs = require('fs');
7
+ var path = require('path');
8
+ var Promise;
9
+
10
+ /**
11
+ * We receive the dbmigrate dependency from dbmigrate initially.
12
+ * This enables us to not have to rely on NODE_PATH.
13
+ */
14
+ exports.setup = function(options, seedLink) {
15
+ dbm = options.dbmigrate;
16
+ type = dbm.dataType;
17
+ seed = seedLink;
18
+ Promise = options.Promise;
19
+ };
20
+
21
+ exports.up = function(db) {
22
+ var filePath = path.join(__dirname, 'sqls', '20231213075143-stop-time-origin-route-name-up.sql');
23
+ return new Promise( function( resolve, reject ) {
24
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
25
+ if (err) return reject(err);
26
+ console.log('received data: ' + data);
27
+
28
+ resolve(data);
29
+ });
30
+ })
31
+ .then(function(data) {
32
+ return db.runSql(data);
33
+ });
34
+ };
35
+
36
+ exports.down = function(db) {
37
+ var filePath = path.join(__dirname, 'sqls', '20231213075143-stop-time-origin-route-name-down.sql');
38
+ return new Promise( function( resolve, reject ) {
39
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
40
+ if (err) return reject(err);
41
+ console.log('received data: ' + data);
42
+
43
+ resolve(data);
44
+ });
45
+ })
46
+ .then(function(data) {
47
+ return db.runSql(data);
48
+ });
49
+ };
50
+
51
+ exports._meta = {
52
+ "version": 1
53
+ };
@@ -0,0 +1,77 @@
1
+ drop procedure vehiclepositions_data_retention(int, int);
2
+ alter table vehiclepositions_stop_times_history drop column origin_route_name;
3
+
4
+
5
+ CREATE PROCEDURE vehiclepositions_data_retention(inout numberOfRows int, in dataRetentionMinutes int)
6
+ LANGUAGE plpgsql
7
+ SET search_path FROM CURRENT
8
+ AS $procedure$
9
+ declare
10
+ idsForDelete varchar(255)[];
11
+ begin
12
+ select array_agg(t.id) from vehiclepositions_trips t
13
+ left join vehiclepositions_positions p on
14
+ p.id = t.last_position_id
15
+ where
16
+ p.valid_to < (NOW() - (dataRetentionMinutes || ' minutes')::interval)
17
+ or (gtfs_trip_id is null and p.created_at < NOW() - (dataRetentionMinutes || ' minutes')::interval) -- entries with valid to is null
18
+ into idsForDelete;
19
+
20
+ INSERT INTO vehiclepositions_trips_history
21
+ select * from vehiclepositions_trips where id = ANY(idsForDelete)
22
+ on conflict do nothing;
23
+
24
+ INSERT INTO vehiclepositions_positions_history
25
+ select * from vehiclepositions_positions where trips_id = ANY(idsForDelete)
26
+ on conflict do nothing;
27
+
28
+ insert into vehiclepositions_stop_times_history (
29
+ rt_trip_id,
30
+ gtfs_date,
31
+ gtfs_trip_id,
32
+ gtfs_direction_id,
33
+ gtfs_route_short_name,
34
+ gtfs_route_type,
35
+ run_number,
36
+ vehicle_registration_number,
37
+ gtfs_stop_id,
38
+ gtfs_stop_sequence,
39
+ current_stop_arrival,
40
+ current_stop_departure,
41
+ current_stop_arr_delay,
42
+ current_stop_dep_delay,
43
+ created_at,
44
+ updated_at
45
+ )
46
+ select
47
+ rt_trip.id,
48
+ rt_trip.gtfs_date,
49
+ rt_trip.gtfs_trip_id,
50
+ rt_trip.gtfs_direction_id,
51
+ rt_trip.gtfs_route_short_name,
52
+ rt_trip.gtfs_route_type,
53
+ rt_trip.run_number,
54
+ rt_trip.vehicle_registration_number,
55
+ stop_time.stop_id,
56
+ stop_time.stop_sequence,
57
+ stop_time.stop_arrival,
58
+ stop_time.stop_departure,
59
+ stop_time.stop_arr_delay,
60
+ stop_time.stop_dep_delay,
61
+ now(),
62
+ now()
63
+ from
64
+ vehiclepositions_trips rt_trip
65
+ join
66
+ v_vehiclepositions_past_stop_times stop_time on stop_time.rt_trip_id = rt_trip.id
67
+ where
68
+ rt_trip.id = ANY(idsForDelete)
69
+ on conflict do nothing;
70
+
71
+
72
+ delete from vehiclepositions_positions where trips_id = ANY(idsForDelete);
73
+ delete from vehiclepositions_trips where id = ANY(idsForDelete);
74
+
75
+ select array_length(idsForDelete,1) into numberOfRows;
76
+ end;
77
+ $procedure$;
@@ -0,0 +1,77 @@
1
+ alter table vehiclepositions_stop_times_history add column origin_route_name varchar(20);
2
+
3
+ CREATE OR REPLACE PROCEDURE vehiclepositions_data_retention(inout numberOfRows int, in dataRetentionMinutes int)
4
+ LANGUAGE plpgsql
5
+ SET search_path FROM CURRENT
6
+ AS $procedure$
7
+ declare
8
+ idsForDelete varchar(255)[];
9
+ begin
10
+ select array_agg(t.id) from vehiclepositions_trips t
11
+ left join vehiclepositions_positions p on
12
+ p.id = t.last_position_id
13
+ where
14
+ p.valid_to < (NOW() - (dataRetentionMinutes || ' minutes')::interval)
15
+ or (gtfs_trip_id is null and p.created_at < NOW() - (dataRetentionMinutes || ' minutes')::interval) -- entries with valid to is null
16
+ into idsForDelete;
17
+
18
+ INSERT INTO vehiclepositions_trips_history
19
+ select * from vehiclepositions_trips where id = ANY(idsForDelete)
20
+ on conflict do nothing;
21
+
22
+ INSERT INTO vehiclepositions_positions_history
23
+ select * from vehiclepositions_positions where trips_id = ANY(idsForDelete)
24
+ on conflict do nothing;
25
+
26
+ insert into vehiclepositions_stop_times_history (
27
+ rt_trip_id,
28
+ gtfs_date,
29
+ gtfs_trip_id,
30
+ gtfs_direction_id,
31
+ gtfs_route_short_name,
32
+ gtfs_route_type,
33
+ run_number,
34
+ vehicle_registration_number,
35
+ gtfs_stop_id,
36
+ gtfs_stop_sequence,
37
+ current_stop_arrival,
38
+ current_stop_departure,
39
+ current_stop_arr_delay,
40
+ current_stop_dep_delay,
41
+ created_at,
42
+ updated_at,
43
+ origin_route_name
44
+ )
45
+ select
46
+ rt_trip.id,
47
+ rt_trip.gtfs_date,
48
+ rt_trip.gtfs_trip_id,
49
+ rt_trip.gtfs_direction_id,
50
+ rt_trip.gtfs_route_short_name,
51
+ rt_trip.gtfs_route_type,
52
+ rt_trip.run_number,
53
+ rt_trip.vehicle_registration_number,
54
+ stop_time.stop_id,
55
+ stop_time.stop_sequence,
56
+ stop_time.stop_arrival,
57
+ stop_time.stop_departure,
58
+ stop_time.stop_arr_delay,
59
+ stop_time.stop_dep_delay,
60
+ now(),
61
+ now(),
62
+ rt_trip.origin_route_name
63
+ from
64
+ vehiclepositions_trips rt_trip
65
+ join
66
+ v_vehiclepositions_past_stop_times stop_time on stop_time.rt_trip_id = rt_trip.id
67
+ where
68
+ rt_trip.id = ANY(idsForDelete)
69
+ on conflict do nothing;
70
+
71
+
72
+ delete from vehiclepositions_positions where trips_id = ANY(idsForDelete);
73
+ delete from vehiclepositions_trips where id = ANY(idsForDelete);
74
+
75
+ select array_length(idsForDelete,1) into numberOfRows;
76
+ end;
77
+ $procedure$;
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@golemio/pid",
3
- "version": "2.10.2-dev.1104369146",
3
+ "version": "2.10.2-dev.1105087628",
4
4
  "description": "Golemio PID Module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",