-
-
Notifications
You must be signed in to change notification settings - Fork 831
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
11 additions
and
10 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
|
||
DROP INDEX IF EXISTS idx_derived_user_id_updated_at; | ||
DROP INDEX IF EXISTS idx_derived_user_id_data_type; | ||
DROP INDEX IF EXISTS idx_file_data_user_id_data_type; | ||
DROP INDEX IF EXISTS idx_file_data_user_id_updated_at; | ||
|
||
DROP TABLE IF EXISTS derived; | ||
DROP TABLE IF EXISTS file_data; | ||
|
||
DROP TYPE IF EXISTS derived_data_type; | ||
DROP TYPE IF EXISTS file_data_type; |
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 |
---|---|---|
@@ -1,27 +1,28 @@ | ||
-- Create the data_type enum | ||
CREATE TYPE derived_data_type AS ENUM ('img_jpg_preview', 'vid_hls_preview', 'meta'); | ||
CREATE TYPE file_data_type AS ENUM ('img_jpg_preview', 'vid_hls_preview', 'derived'); | ||
|
||
-- Create the derived table | ||
CREATE TABLE derived ( | ||
CREATE TABLE file_data ( | ||
file_id BIGINT NOT NULL, | ||
user_id BIGINT NOT NULL, | ||
data_type derived_data_type NOT NULL, | ||
data_type file_data_type NOT NULL, | ||
size BIGINT NOT NULL, | ||
latest_bucket s3region NOT NULL, | ||
replicated_buckets s3region[] NOT NULL, | ||
-- following field contains list of buckets from where we need to delete the data as the given data_type will not longer be persisted in that dc | ||
delete_from_buckets s3region[] NOT NULL DEFAULT '{}', | ||
pending_sync BOOLEAN NOT NULL DEFAULT false, | ||
last_sync_time BIGINT NOT NULL DEFAULT 0, | ||
created_at BIGINT NOT NULL DEFAULT now_utc_micro_seconds(), | ||
updated_at BIGINT NOT NULL DEFAULT now_utc_micro_seconds(), | ||
PRIMARY KEY (file_id, data_type) | ||
); | ||
|
||
-- Add primary key | ||
ALTER TABLE derived ADD PRIMARY KEY (file_id, data_type); | ||
ALTER TABLE file_data ADD PRIMARY KEY (file_id, data_type); | ||
|
||
-- Add index for user_id and data_type | ||
CREATE INDEX idx_derived_user_id_data_type ON derived (user_id, data_type); | ||
CREATE INDEX idx_file_data_user_id_data_type ON file_data (user_id, data_type); | ||
|
||
-- Add index for user_id and updated_at for efficient querying | ||
CREATE INDEX idx_derived_user_id_updated_at ON derived (user_id, updated_at); | ||
CREATE INDEX idx_file_data_user_id_updated_at ON file_data (user_id, updated_at); |