summaryrefslogtreecommitdiff
path: root/database.sql
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-10-13 00:17:36 +0500
committerilotterytea <iltsu@alright.party>2025-10-13 00:17:36 +0500
commit9533a34322c5ec154860c42af98e0d4e8d44d945 (patch)
treef91b0d4adb2c3db6b27fa922b7742384b2eea11b /database.sql
parent976b0683324813b2bcbda391a83188489be3d5ad (diff)
feat: save words into the database
Diffstat (limited to 'database.sql')
-rw-r--r--database.sql32
1 files changed, 32 insertions, 0 deletions
diff --git a/database.sql b/database.sql
new file mode 100644
index 0000000..e453239
--- /dev/null
+++ b/database.sql
@@ -0,0 +1,32 @@
+CREATE TABLE IF NOT EXISTS channels (
+ id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
+ alias_id INTEGER NOT NULL UNIQUE,
+ alias_name TEXT NOT NULL UNIQUE,
+ joined_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP,
+ opted_out_at TIMESTAMP
+);
+
+CREATE TABLE IF NOT EXISTS users (
+ id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
+ alias_id INTEGER NOT NULL UNIQUE,
+ alias_name TEXT NOT NULL UNIQUE,
+ joined_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP,
+ opted_out_at TIMESTAMP
+);
+
+CREATE TABLE IF NOT EXISTS words (
+ id BIGINT PRIMARY KEY AUTO_INCREMENT,
+ name TEXT NOT NULL UNIQUE
+);
+
+CREATE TABLE IF NOT EXISTS channel_words (
+ id BIGINT PRIMARY KEY AUTO_INCREMENT,
+ channel_id INTEGER NOT NULL REFERENCES channels(id) ON DELETE CASCADE,
+ user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ word_id BIGINT NOT NULL REFERENCES words(id) ON DELETE CASCADE,
+ usage_count BIGINT NOT NULL DEFAULT 0,
+ first_used_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP,
+ last_used_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP,
+
+ UNIQUE (channel_id, user_id, word_id)
+); \ No newline at end of file