Skip to content

Instantly share code, notes, and snippets.

@POMXARK
Forked from mutationevent/mysql_chat_schema.sql
Created July 20, 2024 04:18
Show Gist options
  • Save POMXARK/a88339b59873fcba87d731cafa2ed865 to your computer and use it in GitHub Desktop.
Save POMXARK/a88339b59873fcba87d731cafa2ed865 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