Skip to content

Commit f29bf74

Browse files
committed
migrate db to store chat history
1 parent 7c0ff31 commit f29bf74

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- Create users table
2+
CREATE TABLE IF NOT EXISTS users (
3+
id VARCHAR(255) PRIMARY KEY,
4+
email VARCHAR(255) UNIQUE NOT NULL,
5+
password_hash VARCHAR(255) NOT NULL,
6+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
7+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
8+
is_verified BOOLEAN NOT NULL DEFAULT FALSE
9+
);
10+
11+
-- Create tokens table
12+
CREATE TABLE IF NOT EXISTS tokens (
13+
id VARCHAR(255) PRIMARY KEY,
14+
user_id VARCHAR(255) NOT NULL,
15+
token VARCHAR(255) UNIQUE NOT NULL,
16+
expires_at TIMESTAMP NOT NULL,
17+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
18+
CONSTRAINT fk_tokens_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
19+
);
20+
21+
-- Create index on tokens.user_id
22+
CREATE INDEX IF NOT EXISTS idx_tokens_user_id ON tokens(user_id);
23+
24+
-- Create messages table
25+
CREATE TABLE IF NOT EXISTS messages (
26+
id VARCHAR(255) PRIMARY KEY,
27+
user_id VARCHAR(255) NOT NULL,
28+
content TEXT NOT NULL,
29+
role VARCHAR(50) NOT NULL,
30+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
31+
CONSTRAINT fk_messages_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
32+
);
33+
34+
-- Create index on messages.user_id
35+
CREATE INDEX IF NOT EXISTS idx_messages_user_id ON messages(user_id);

0 commit comments

Comments
 (0)