Skip to content

Instantly share code, notes, and snippets.

@ashutoshpw
Created September 17, 2022 13:49
Show Gist options
  • Save ashutoshpw/001b3f1ebfe210a22a31fd08249d249c to your computer and use it in GitHub Desktop.
Save ashutoshpw/001b3f1ebfe210a22a31fd08249d249c to your computer and use it in GitHub Desktop.
message-app
CREATE TABLE users (
id INT,
status VARCHAR,
email VARCHAR NOT NULL,
username VARCHAR NOT NULL,
created_at DATETIME NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE messages (
id INT,
from_user INT NOT NULL,
to_user INT NOT NULL,
content TEXT NOT NULL,
status VARCHAR,
created_at DATETIME NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE rooms (
id NOT NULL,
title VARCHAR NOT NULL,
status VARCHAR NOT NULL,
created_at DATETIME NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE room_participants (
id NOT NULL,
room_id NOT NULL,
user_id NOT NULL,
status VARCHAR NOT NULL,
created_at DATETIME NOT NULL,
PRIMARY KEY (id)
);
ALTER TABLE
messages
ADD
CONSTRAINT FK_4214bc7f_43de_457e_883d_c417672681a5 FOREIGN KEY (from_user) REFERENCES users(id);
ALTER TABLE
messages
ADD
CONSTRAINT FK_18b0b261_d1e4_4b72_9c4d_f2df15cd7e59 FOREIGN KEY (to_user) REFERENCES users(id);
ALTER TABLE
room_participants
ADD
CONSTRAINT FK_44666a2d_a5f4_4a8d_92bb_f5ff470d3211 FOREIGN KEY (room_id) REFERENCES rooms(id);
ALTER TABLE
room_participants
ADD
CONSTRAINT FK_f6d555dd_90e1_49cb_940a_26cb41296375 FOREIGN KEY (user_id) REFERENCES users(id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment