-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add kit_last_seen table migrations
- Loading branch information
Showing
4 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE kit_last_seen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- no-op | ||
SELECT 1; |
10 changes: 10 additions & 0 deletions
10
migrations/2024-03-15-161913_populate_kit_last_seen/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |