added rooms and uuids

This commit is contained in:
2025-12-14 20:04:04 +01:00
parent fe38d42a9e
commit 30f4155369
3 changed files with 24 additions and 22 deletions

View File

@@ -1,26 +1,28 @@
CREATE TABLE IF NOT EXISTS user (
CREATE TABLE IF NOT EXISTS user_ (
id SERIAL PRIMARY KEY,
uuid UUID UNIQUE,
email TEXT UNIQUE,
username TEXT NOT NULL UNIQUE,
password_hash TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS channel (
CREATE TABLE IF NOT EXISTS room_ (
id SERIAL PRIMARY KEY,
owner INT NOT NULL REFERENCES user(id) ON DELETE CASCADE,
uuid UUID UNIQUE,
owner INT NOT NULL REFERENCES user_(id) ON DELETE CASCADE,
name TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS membership (
user INT REFERENCES user(id),
channel INT REFERENCES channel(id),
PRIMARY KEY (user, channel)
CREATE TABLE IF NOT EXISTS membership_ (
user_id INT REFERENCES user_(id),
room INT REFERENCES room_(id),
PRIMARY KEY (user_id, room)
);
CREATE TABLE IF NOT EXISTS message (
CREATE TABLE IF NOT EXISTS message_ (
id BIGSERIAL PRIMARY KEY,
sender INT REFERENCES user(id) NOT NULL,
channel INT REFERENCES channel(id) NOT NULL,
sender INT REFERENCES user_(id) NOT NULL,
room INT REFERENCES room_(id) NOT NULL,
type VARCHAR(32) NOT NULL,
content TEXT NOT NULL
);

View File

@@ -1,24 +1,24 @@
INSERT INTO user (username, password_hash, email) VALUES
('alice', '$argon2id$v=19$m=19456,t=2,p=1$W0OzC/dmZQt7/xUJt4E9hA$cYiUC91a5yCQU9tDUadw0FKjUmTRv453cYwu1nfMKUQ', 'alice@example.com'),
('bob', '$argon2id$v=19$m=19456,t=2,p=1$1T7VaQps1X5Wj+TJHt8FIQ$/hA7PSITskjELwfNw+s6BvCJmUA4dDDrSGJvDvHx7Kc', 'bob@example.com'),
('carol', '$argon2id$v=19$m=19456,t=2,p=1$Kw4Re4lggxzDldu3vNl2PA$6DP4MPftfXI77g8EZRXYmWgcnVnAKLq0dkZOb/eBIC8', 'carol@example.com');
INSERT INTO user_ (username, email, uuid, password_hash) VALUES
('alice', 'alice@example.com', '019b1e35-f2a3-7270-bf69-559af5be14b2', '$argon2id$v=19$m=19456,t=2,p=1$z8LFtcIvrrl1QhQoYJs/Yw$IB6h0SqWw+sZuExdsx7Rofdy/IbQrCImB08goR27Tgk'),
('bob', 'bob@example.com', '019b1e36-3b8c-7f82-b845-6bfeb72466ce', '$argon2id$v=19$m=19456,t=2,p=1$mzO6Qx8ZH4/wrj14ZgKiuA$7bxNWCgsIVEfPgtueFbjbi8mDjbAHMYAHOGpxTJnEpQ'),
('carol', 'carol@example.com', '019b1e36-7706-76e2-b9ce-b37916ddfc99', '$argon2id$v=19$m=19456,t=2,p=1$5rw/7uIJIKMnyqNrYQt92Q$DJVEfgbaZtkflsmDEkSoR3uDQmujI4T73cWq9hOBgVI');
INSERT INTO channel (owner, name) VALUES
(1, 'General Discussion'),
(2, 'Tech Talk'),
(1, 'Random Memes');
INSERT INTO room_ (owner, name, uuid) VALUES
(1, 'General Discussion', '5dc599ee-1f5c-40c2-a22a-e40780d2d960'),
(2, 'Tech Talk', '6b14fe7b-2171-4464-95af-4888062b1b6d'),
(1, 'Random Memes', 'fb794f59-6b2d-4daa-8980-dc5255862657');
INSERT INTO membership (user, channel) VALUES
INSERT INTO membership_ (user_id, room) VALUES
(1, 1), -- Alice in General Discussion
(2, 1), -- Bob in General Discussion
(2, 2), -- Bob in Tech Talk
(3, 1), -- Carol in General Discussion
(1, 3); -- Alice in Random Memes
INSERT INTO message (sender, channel, type, content) VALUES
INSERT INTO message_ (sender, room, type, content) VALUES
(1, 1, 'text', 'Hey everyone, hows it going?'),
(2, 1, 'text', 'All good! Just trying to get through some work.'),
(3, 1, 'text', 'Hello! How are you guys?'),
(2, 2, 'text', 'Anyone seen the new tech updates?'),
(1, 3, 'image', 'Heres a funny meme I found!'),
(3, 1, 'text', 'I love how active this channel is!');
(3, 1, 'text', 'I love how active this room is!');