From 941f9246088d4b7ab5421eb92a10f3f14429c29a Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 20:54:18 +0200 Subject: [PATCH] more robust sql scripts --- defaults.sql | 22 ++++++++++++++++++++++ init.sql | 23 ++++++++++------------- 2 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 defaults.sql diff --git a/defaults.sql b/defaults.sql new file mode 100644 index 0000000..ca02da9 --- /dev/null +++ b/defaults.sql @@ -0,0 +1,22 @@ +INSERT INTO difficulty VALUES('easy'); +INSERT INTO difficulty VALUES('medium'); +INSERT INTO difficulty VALUES('hard'); +INSERT INTO difficulty VALUES('fuck you'); + +INSERT INTO tag VALUES('math'); +INSERT INTO tag VALUES('AI'); +INSERT INTO tag VALUES('networking'); +INSERT INTO tag VALUES('games'); +INSERT INTO tag VALUES('rendering'); +INSERT INTO tag VALUES('simulation'); + +-- +INSERT INTO project (title, body) VALUES ( + 'test project', + 'desc' +); + +INSERT INTO assignment VALUES ( + '#/g/chad', + 1 +); diff --git a/init.sql b/init.sql index 6c89cc1..9e61c26 100644 --- a/init.sql +++ b/init.sql @@ -1,3 +1,4 @@ +DROP TABLE IF EXISTS project; CREATE TABLE project ( title VARCHAR(64) NOT NULL, body TEXT DEFAULT NULL, @@ -8,29 +9,25 @@ CREATE TABLE project ( span INT NOT NULL DEFAULT 7 -- time to last for in days ); +DROP TABLE IF EXISTS difficulty; CREATE TABLE difficulty ( diff VARCHAR(16) ); - -INSERT INTO difficulty VALUES('easy'); -INSERT INTO difficulty VALUES('medium'); -INSERT INTO difficulty VALUES('hard'); -INSERT INTO difficulty VALUES('fuck you'); +DROP TABLE IF EXISTS tag; CREATE TABLE tag ( t VARCHAR(16) ); --- Some default (not all) tags -INSERT INTO tag VALUES('math'); -INSERT INTO tag VALUES('AI'); -INSERT INTO tag VALUES('networking'); -INSERT INTO tag VALUES('games'); -INSERT INTO tag VALUES('rendering'); -INSERT INTO tag VALUES('simulation'); - +DROP TABLE IF EXISTS project_tag; CREATE TABLE project_tag ( project INT REFERENCES project(rowid), tag INT REFERENCES tag(rowid) ); + +DROP TABLE IF EXISTS assignment; +CREATE TABLE assignment ( + who VARCHAR(32) NOT NULL, + project INT NOT NULL REFERENCES project(rowid) +);