Skip to content

Commit

Permalink
feat: add kit_last_seen table migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcur committed Mar 18, 2024
1 parent 3f43425 commit a110522
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions migrations/2024-03-15-155708_create_kit_last_seen/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE kit_last_seen;
11 changes: 11 additions & 0 deletions migrations/2024-03-15-155708_create_kit_last_seen/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE kit_last_seen (
kit_id int4 NOT NULL,
datetime_last_seen timestamptz NOT NULL,
CONSTRAINT kit_last_seen_pkey PRIMARY KEY (kit_id)
);

CREATE INDEX ix_kit_last_seen_datetime_last_seen ON public.kit_last_seen USING btree (datetime_last_seen);

-- foreign keys
ALTER TABLE public.kit_last_seen
ADD CONSTRAINT kit_last_seen_kit_id_fkey FOREIGN KEY (kit_id) REFERENCES kits (id) ON DELETE CASCADE ON UPDATE CASCADE;
2 changes: 2 additions & 0 deletions migrations/2024-03-15-161913_populate_kit_last_seen/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- no-op
SELECT 1;
10 changes: 10 additions & 0 deletions migrations/2024-03-15-161913_populate_kit_last_seen/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
INSERT INTO kit_last_seen
SELECT
kit_id,
MAX(datetime_start) AS datetime_last_seen
FROM
aggregate_measurements
GROUP BY
kit_id
ON CONFLICT
DO NOTHING;

0 comments on commit a110522

Please sign in to comment.