-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add features for tracking open content library activity per #490
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
backend/migrations/00021_add_open_content_activity_tables.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,36 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
CREATE TABLE open_content_urls ( | ||
id SERIAL NOT NULL, | ||
content_url CHARACTER VARYING(255) NOT NULL, | ||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE open_content_activities ( | ||
id SERIAL NOT NULL, | ||
request_ts TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP, | ||
open_content_provider_id INTEGER NOT NULL, | ||
facility_id INTEGER NOT NULL, | ||
user_id INTEGER NOT NULL, | ||
content_id INTEGER NOT NULL, | ||
open_content_url_id INTEGER NOT NULL, | ||
PRIMARY KEY (id), | ||
|
||
CONSTRAINT open_content_activities_open_content_provider_id_fkey FOREIGN KEY (open_content_provider_id) REFERENCES "open_content_providers" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
CONSTRAINT open_content_activities_facility_id_fkey FOREIGN KEY (facility_id) REFERENCES "facilities" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
CONSTRAINT open_content_activities_user_id_fkey FOREIGN KEY (user_id) REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
CONSTRAINT open_content_activities_open_content_url_id_fkey FOREIGN KEY (open_content_url_id) REFERENCES "open_content_urls" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
CONSTRAINT unique_user_facility_library_url_timestamp UNIQUE (user_id, facility_id, content_id, open_content_url_id, request_ts) | ||
); | ||
|
||
CREATE INDEX idx_open_content_activities_user_id ON public.open_content_activities USING btree (user_id); | ||
CREATE INDEX idx_open_content_activities_open_content_url_id ON public.open_content_activities USING btree (open_content_url_id); | ||
CREATE INDEX idx_open_content_activities_user_id_content_id_facility_id ON public.open_content_activities USING btree (user_id, content_id, facility_id); | ||
CREATE INDEX idx_open_content_activities_content_id_open_content_provider_id_facility_id ON public.open_content_activities USING btree (content_id, open_content_provider_id, facility_id); | ||
-- +goose StatementEnd | ||
|
||
-- +goose Down | ||
-- +goose StatementBegin | ||
DROP TABLE open_content_activities; | ||
DROP TABLE open_content_urls; | ||
-- +goose StatementEnd |