Skip to content

Instantly share code, notes, and snippets.

@mutationevent
Created December 20, 2022 09:51
Show Gist options
  • Save mutationevent/2a59a9ed9bf0b1993d395c34f694d07f to your computer and use it in GitHub Desktop.
Save mutationevent/2a59a9ed9bf0b1993d395c34f694d07f to your computer and use it in GitHub Desktop.
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