@golemio/pid 2.7.2-dev.872555684 → 2.7.2-dev.872750395
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.
|
@@ -40,6 +40,35 @@ create function convert_timestamp_ms_to_iso_string(timestamp_ms bigint, timezone
|
|
|
40
40
|
select TO_CHAR(DATE_TRUNC('second', TO_TIMESTAMP(timestamp_ms / 1000)) at TIME zone timezone, 'YYYY-MM-DD"T"HH24:MI:SS') || replace('+' || to_char(DATE_TRUNC('second', TO_TIMESTAMP(timestamp_ms / 1000)) at TIME zone timezone - DATE_TRUNC('second', TO_TIMESTAMP(timestamp_ms / 1000)) at TIME zone 'UTC', 'HH24:MMFM'), '+-', '-')
|
|
41
41
|
$$ LANGUAGE SQL IMMUTABLE;
|
|
42
42
|
|
|
43
|
+
CREATE or replace PROCEDURE vehiclepositions_data_retention(inout numberOfRows int, in dataRetentionMinutes int)
|
|
44
|
+
LANGUAGE plpgsql
|
|
45
|
+
AS $procedure$
|
|
46
|
+
declare
|
|
47
|
+
idsForDelete varchar(255)[];
|
|
48
|
+
begin
|
|
49
|
+
select array_agg(t.id) from pid.vehiclepositions_trips t
|
|
50
|
+
left join pid.vehiclepositions_positions p on
|
|
51
|
+
p.id = t.last_position_id
|
|
52
|
+
where
|
|
53
|
+
p.valid_to/1000 < extract(epoch from (NOW() - (dataRetentionMinutes || ' minutes')::interval))
|
|
54
|
+
or (gtfs_trip_id is null and p.created_at < NOW() - (dataRetentionMinutes || ' minutes')::interval) -- entries with valid to is null
|
|
55
|
+
into idsForDelete;
|
|
56
|
+
|
|
57
|
+
INSERT INTO pid.vehiclepositions_trips_history
|
|
58
|
+
select * from pid.vehiclepositions_trips where id = ANY(idsForDelete)
|
|
59
|
+
on conflict do nothing;
|
|
60
|
+
|
|
61
|
+
INSERT INTO pid.vehiclepositions_positions_history
|
|
62
|
+
select * from pid.vehiclepositions_positions where trips_id = ANY(idsForDelete)
|
|
63
|
+
on conflict do nothing;
|
|
64
|
+
|
|
65
|
+
delete from pid.vehiclepositions_positions where trips_id = ANY(idsForDelete);
|
|
66
|
+
delete from pid.vehiclepositions_trips where id = ANY(idsForDelete);
|
|
67
|
+
|
|
68
|
+
select array_length(idsForDelete,1) into numberOfRows;
|
|
69
|
+
end;
|
|
70
|
+
$procedure$;
|
|
71
|
+
|
|
43
72
|
|
|
44
73
|
-- recreate views
|
|
45
74
|
create view v_vehiclepositions_alerts_last_position as
|
|
@@ -40,6 +40,35 @@ create function convert_timestamptz_to_iso_string(timestamp_tz timestamptz, targ
|
|
|
40
40
|
select to_char(timestamp_tz at time zone target_timezone, 'YYYY-MM-DD"T"HH24:MI:SS+' || to_char((select timestamp_tz at time zone target_timezone) - (select timestamp_tz at time zone 'UTC'), 'HH24":00"'))
|
|
41
41
|
$$ LANGUAGE SQL IMMUTABLE;
|
|
42
42
|
|
|
43
|
+
CREATE or replace PROCEDURE vehiclepositions_data_retention(inout numberOfRows int, in dataRetentionMinutes int)
|
|
44
|
+
LANGUAGE plpgsql
|
|
45
|
+
AS $procedure$
|
|
46
|
+
declare
|
|
47
|
+
idsForDelete varchar(255)[];
|
|
48
|
+
begin
|
|
49
|
+
select array_agg(t.id) from pid.vehiclepositions_trips t
|
|
50
|
+
left join pid.vehiclepositions_positions p on
|
|
51
|
+
p.id = t.last_position_id
|
|
52
|
+
where
|
|
53
|
+
p.valid_to < (NOW() - (dataRetentionMinutes || ' minutes')::interval)
|
|
54
|
+
or (gtfs_trip_id is null and p.created_at < NOW() - (dataRetentionMinutes || ' minutes')::interval) -- entries with valid to is null
|
|
55
|
+
into idsForDelete;
|
|
56
|
+
|
|
57
|
+
INSERT INTO pid.vehiclepositions_trips_history
|
|
58
|
+
select * from pid.vehiclepositions_trips where id = ANY(idsForDelete)
|
|
59
|
+
on conflict do nothing;
|
|
60
|
+
|
|
61
|
+
INSERT INTO pid.vehiclepositions_positions_history
|
|
62
|
+
select * from pid.vehiclepositions_positions where trips_id = ANY(idsForDelete)
|
|
63
|
+
on conflict do nothing;
|
|
64
|
+
|
|
65
|
+
delete from pid.vehiclepositions_positions where trips_id = ANY(idsForDelete);
|
|
66
|
+
delete from pid.vehiclepositions_trips where id = ANY(idsForDelete);
|
|
67
|
+
|
|
68
|
+
select array_length(idsForDelete,1) into numberOfRows;
|
|
69
|
+
end;
|
|
70
|
+
$procedure$;
|
|
71
|
+
|
|
43
72
|
|
|
44
73
|
-- recreate views
|
|
45
74
|
create view v_vehiclepositions_alerts_last_position as
|