From 678374dfeab38ccf6b2bad71d7cbad856c87a0d5 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Thu, 11 Apr 2024 00:05:43 +0200 Subject: [PATCH] Back to being a hypertable --- .../20240410220437_restore-hypertable.sql | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 supabase/migrations/20240410220437_restore-hypertable.sql diff --git a/supabase/migrations/20240410220437_restore-hypertable.sql b/supabase/migrations/20240410220437_restore-hypertable.sql new file mode 100644 index 0000000..410e692 --- /dev/null +++ b/supabase/migrations/20240410220437_restore-hypertable.sql @@ -0,0 +1,20 @@ +-- we areno longer using trigger.dev for sanity checking positions in +-- a reatime manner, so restore the hypertable. +delete from raw_bus_positions where id in (select raw_pos_id from potential_arrivals); +drop table potential_arrivals cascade; + +CREATE TABLE potential_arrivals( + id BIGINT GENERATED ALWAYS AS IDENTITY, + raw_pos_id BIGINT NOT NULL, + bus_id text NOT NULL, + bus_coords GEOGRAPHY(Point, 4326) NOT NULL, + measured_at TIMESTAMP WITH TIME ZONE NOT NULL, + stop_id bigint NOT NULL, + distance decimal NOT NULL +); + +SELECT create_hypertable('potential_arrivals', 'measured_at', chunk_time_interval => INTERVAL '10 minutes'); + +CREATE INDEX potential_arrives_raw_pos_id ON potential_arrivals (raw_pos_id); +CREATE INDEX potential_arrivals_measures ON potential_arrivals (bus_id, measured_at DESC); +CREATE INDEX potential_arrivals_spatial ON potential_arrivals USING GIST (bus_coords);