From 34a3de1fce4595cc5c83f9d96a41a33b85107a79 Mon Sep 17 00:00:00 2001 From: j Date: Sat, 23 Mar 2024 00:59:46 -0400 Subject: [PATCH] renamed to fix sequence --- .../001_create_user_mentions_table.sql | 28 +++++++++++++++++++ .../002_create_oauth_tokens_table.sql | 9 ++++++ 2 files changed, 37 insertions(+) create mode 100644 src/db/migrations/001_create_user_mentions_table.sql create mode 100644 src/db/migrations/002_create_oauth_tokens_table.sql diff --git a/src/db/migrations/001_create_user_mentions_table.sql b/src/db/migrations/001_create_user_mentions_table.sql new file mode 100644 index 0000000..bcd5883 --- /dev/null +++ b/src/db/migrations/001_create_user_mentions_table.sql @@ -0,0 +1,28 @@ +CREATE TABLE IF NOT EXISTS user_mentions ( + -- Unique identifier for each record. Auto-incremented to ensure uniqueness. + id INTEGER PRIMARY KEY AUTOINCREMENT, + + -- The unique identifier of the comment from the r/Drama platform. Not unique in this table + -- because a single comment can mention multiple users. + rdrama_comment_id TEXT NOT NULL, + + -- The mentioned Reddit username in a standardized format (e.g., u/username). Lowercased + -- to ensure consistency and prevent duplicate entries due to case differences. + username TEXT NOT NULL, + + -- The content of the message sent to the mentioned user, if any. Allows tracking + -- of what communication has been made, useful for audit purposes or resending messages. + message TEXT, + + -- Timestamp when the mention was processed and, if applicable, when a message was sent. + -- Defaults to the current timestamp at the time of record creation. + sent_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + + -- Enforces uniqueness for each comment-username pair to prevent processing and notifying + -- the same user mention in the same comment more than once. + CONSTRAINT unique_comment_user UNIQUE (rdrama_comment_id, username) +); + +-- Consider adding indexes based on query patterns for improved performance, such as: +-- CREATE INDEX idx_username ON user_mentions(username); +-- CREATE INDEX idx_rdrama_comment_id ON user_mentions(rdrama_comment_id); diff --git a/src/db/migrations/002_create_oauth_tokens_table.sql b/src/db/migrations/002_create_oauth_tokens_table.sql new file mode 100644 index 0000000..2e2897e --- /dev/null +++ b/src/db/migrations/002_create_oauth_tokens_table.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS oauth_tokens ( + id INTEGER PRIMARY KEY, + token_identifier TEXT NOT NULL UNIQUE, -- Static identifier for the OAuth token + access_token TEXT NOT NULL, + token_type TEXT NOT NULL, + expires_in INTEGER NOT NULL, + expiry_timestamp INTEGER NOT NULL, + scope TEXT NOT NULL +);