40 lines
1.2 KiB
MySQL
40 lines
1.2 KiB
MySQL
|
CREATE TABLE users (
|
||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||
|
username VARCHAR(50) NOT NULL UNIQUE,
|
||
|
password VARCHAR(255) NOT NULL,
|
||
|
`email` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
|
||
|
`group` ENUM('admin', 'user') DEFAULT 'user',
|
||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||
|
contact VARCHAR(255) NULL
|
||
|
`phone_number` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL
|
||
|
);
|
||
|
|
||
|
CREATE TABLE love_wall (
|
||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||
|
user_id INT,
|
||
|
content TEXT NOT NULL,
|
||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
||
|
);
|
||
|
|
||
|
CREATE TABLE articles (
|
||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||
|
title VARCHAR(255) NOT NULL,
|
||
|
content TEXT NOT NULL,
|
||
|
`type` ENUM('activity', 'news') NOT NULL,
|
||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||
|
);
|
||
|
|
||
|
CREATE TABLE comments (
|
||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||
|
user_id INT,
|
||
|
content TEXT NOT NULL,
|
||
|
love_wall_id INT DEFAULT NULL,
|
||
|
article_id INT DEFAULT NULL,
|
||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||
|
FOREIGN KEY (user_id) REFERENCES users(id),
|
||
|
FOREIGN KEY (love_wall_id) REFERENCES love_wall(id),
|
||
|
FOREIGN KEY (article_id) REFERENCES articles(id)
|
||
|
);
|
||
|
|