2024-04-02 19:38:16 +02:00
|
|
|
DROP TABLE IF EXISTS articles_tags;
|
2024-12-27 10:30:15 +01:00
|
|
|
DROP TABLE IF EXISTS articles_contributors;
|
|
|
|
DROP TABLE IF EXISTS articles_authors;
|
2024-04-02 19:38:16 +02:00
|
|
|
DROP TABLE IF EXISTS tags;
|
|
|
|
DROP TABLE IF EXISTS articles;
|
|
|
|
DROP TABLE IF EXISTS issues;
|
|
|
|
DROP TABLE IF EXISTS users;
|
|
|
|
|
|
|
|
CREATE TABLE users (
|
2024-11-02 16:24:39 +01:00
|
|
|
id INT AUTO_INCREMENT,
|
|
|
|
username VARCHAR(255) NOT NULL UNIQUE,
|
|
|
|
password VARCHAR(60) NOT NULL,
|
|
|
|
first_name VARCHAR(255) NOT NULL,
|
|
|
|
last_name VARCHAR(255) NOT NULL,
|
|
|
|
email VARCHAR(255) NOT NULL,
|
|
|
|
profile_pic_link VARCHAR(255),
|
|
|
|
role INT NOT NULL,
|
2024-08-25 11:24:03 +02:00
|
|
|
PRIMARY KEY (id)
|
2024-04-02 19:38:16 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE issues (
|
2024-11-02 16:24:39 +01:00
|
|
|
id INT AUTO_INCREMENT,
|
|
|
|
published BOOL NOT NULL,
|
2024-08-25 11:24:03 +02:00
|
|
|
PRIMARY KEY (id)
|
2024-04-02 19:38:16 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE articles (
|
2024-11-02 16:24:39 +01:00
|
|
|
id INT AUTO_INCREMENT,
|
|
|
|
title VARCHAR(255) NOT NULL,
|
|
|
|
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
banner_link VARCHAR(255),
|
|
|
|
summary TEXT NOT NULL,
|
|
|
|
published BOOL NOT NULL,
|
|
|
|
rejected BOOL NOT NULL,
|
2024-12-27 10:30:15 +01:00
|
|
|
creator_id INT NOT NULL,
|
2024-11-02 16:24:39 +01:00
|
|
|
issue_id INT NOT NULL,
|
|
|
|
edited_id INT,
|
|
|
|
is_in_issue BOOL NOT NULL,
|
|
|
|
auto_generated BOOL NOT NULL,
|
2024-08-25 11:24:03 +02:00
|
|
|
PRIMARY KEY (id),
|
2024-12-27 10:30:15 +01:00
|
|
|
FOREIGN KEY (creator_id) REFERENCES users (id),
|
2024-08-25 11:24:03 +02:00
|
|
|
FOREIGN KEY (issue_id) REFERENCES issues (id)
|
2024-04-02 19:38:16 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE tags (
|
2024-11-02 16:24:39 +01:00
|
|
|
id INT AUTO_INCREMENT,
|
|
|
|
name VARCHAR(50) NOT NULL UNIQUE,
|
2024-08-25 11:24:03 +02:00
|
|
|
PRIMARY KEY (id)
|
2024-04-02 19:38:16 +02:00
|
|
|
);
|
|
|
|
|
2024-11-02 16:24:39 +01:00
|
|
|
CREATE TABLE articles_authors (
|
|
|
|
article_id INT,
|
|
|
|
author_id INT,
|
|
|
|
PRIMARY KEY (article_id, author_id),
|
|
|
|
FOREIGN KEY (article_id) REFERENCES articles (id),
|
|
|
|
FOREIGN KEY (author_id) REFERENCES users (id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE articles_contributors (
|
|
|
|
article_id INT,
|
|
|
|
contributor_id INT,
|
|
|
|
PRIMARY KEY (article_id, contributor_id),
|
|
|
|
FOREIGN KEY (article_id) REFERENCES articles (id),
|
|
|
|
FOREIGN KEY (contributor_id) REFERENCES users (id)
|
|
|
|
);
|
|
|
|
|
2024-04-02 19:38:16 +02:00
|
|
|
CREATE TABLE articles_tags (
|
2024-11-02 16:24:39 +01:00
|
|
|
article_id INT,
|
|
|
|
tag_id INT,
|
2024-08-25 11:24:03 +02:00
|
|
|
PRIMARY KEY (article_id, tag_id),
|
|
|
|
FOREIGN KEY (article_id) REFERENCES articles (id),
|
|
|
|
FOREIGN KEY (tag_id) REFERENCES tags (id)
|
2024-04-02 19:38:16 +02:00
|
|
|
);
|