From eb8e14ff6d27995e2b1a5d32f6f146526570571c Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Sat, 2 Nov 2024 16:24:39 +0100 Subject: [PATCH] Adapt DB layout to multiple authors and contributors --- create_db.sql | 67 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/create_db.sql b/create_db.sql index f32822e..2fc4dfa 100644 --- a/create_db.sql +++ b/create_db.sql @@ -5,50 +5,65 @@ DROP TABLE IF EXISTS issues; DROP TABLE IF EXISTS users; CREATE TABLE users ( - 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, + 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, PRIMARY KEY (id) ); CREATE TABLE issues ( - id INT AUTO_INCREMENT, - published BOOL NOT NULL, + id INT AUTO_INCREMENT, + published BOOL NOT NULL, PRIMARY KEY (id) ); CREATE TABLE articles ( - 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, - author_id INT NOT NULL, - issue_id INT NOT NULL, - edited_id INT, - is_in_issue BOOL NOT NULL, - auto_generated BOOL NOT NULL, + 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, + issue_id INT NOT NULL, + edited_id INT, + is_in_issue BOOL NOT NULL, + auto_generated BOOL NOT NULL, PRIMARY KEY (id), FOREIGN KEY (author_id) REFERENCES users (id), FOREIGN KEY (issue_id) REFERENCES issues (id) ); CREATE TABLE tags ( - id INT AUTO_INCREMENT, - name VARCHAR(50) NOT NULL UNIQUE, + id INT AUTO_INCREMENT, + name VARCHAR(50) NOT NULL UNIQUE, PRIMARY KEY (id) ); +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) +); + CREATE TABLE articles_tags ( - article_id INT, - tag_id INT, + article_id INT, + tag_id INT, PRIMARY KEY (article_id, tag_id), FOREIGN KEY (article_id) REFERENCES articles (id), FOREIGN KEY (tag_id) REFERENCES tags (id)