31 lines
921 B
MySQL
31 lines
921 B
MySQL
|
CREATE TABLE IF NOT EXISTS channels (
|
||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||
|
name TEXT NOT NULL,
|
||
|
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP
|
||
|
);
|
||
|
CREATE TABLE IF NOT EXISTS files (
|
||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||
|
channelId INTEGER,
|
||
|
filePath TEXT,
|
||
|
fileType TEXT,
|
||
|
fileSize INTEGER,
|
||
|
originalName TEXT,
|
||
|
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||
|
FOREIGN KEY (channelId) REFERENCES channels (id) ON DELETE CASCADE
|
||
|
);
|
||
|
CREATE TABLE IF NOT EXISTS messages (
|
||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||
|
channelId INTEGER,
|
||
|
content TEXT,
|
||
|
fileId INTEGER NULL,
|
||
|
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||
|
FOREIGN KEY (channelId) REFERENCES channels (id) ON DELETE CASCADE,
|
||
|
FOREIGN KEY (fileId) REFERENCES files (id) ON DELETE
|
||
|
SET
|
||
|
NULL
|
||
|
);
|
||
|
CREATE VIRTUAL TABLE IF NOT EXISTS messages_fts USING fts5(
|
||
|
content,
|
||
|
content = 'messages',
|
||
|
content_rowid = 'id'
|
||
|
);
|