-
-
Save POMXARK/a88339b59873fcba87d731cafa2ed865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE users ( | |
id INT AUTO_INCREMENT PRIMARY KEY, | |
username VARCHAR(255) NOT NULL UNIQUE, | |
password VARCHAR(255) NOT NULL | |
); | |
CREATE TABLE conversations ( | |
id INT AUTO_INCREMENT PRIMARY KEY, | |
name VARCHAR(255) NOT NULL, | |
created_at DATETIME DEFAULT CURRENT_TIMESTAMP | |
); | |
CREATE TABLE messages ( | |
id INT AUTO_INCREMENT PRIMARY KEY, | |
conversation_id INT NOT NULL, | |
sender_id INT NOT NULL, | |
body TEXT NOT NULL, | |
read TINYINT(1) DEFAULT 0, | |
created_at DATETIME DEFAULT CURRENT_TIMESTAMP, | |
FOREIGN KEY (conversation_id) REFERENCES conversations(id), | |
FOREIGN KEY (sender_id) REFERENCES users(id) | |
); | |
CREATE TABLE conversation_participants ( | |
conversation_id INT NOT NULL, | |
user_id INT NOT NULL, | |
PRIMARY KEY (conversation_id, user_id), | |
FOREIGN KEY (conversation_id) REFERENCES conversations(id), | |
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