InQuire/schema.sql

57 lines
2.1 KiB
SQL

DROP TABLE IF EXISTS user;
DROP TABLE IF EXISTS question;
DROP TABLE IF EXISTS subject;
CREATE TABLE user (
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
lecturer INTEGER NOT NULL
);
CREATE TABLE question (
question_id INTEGER PRIMARY KEY AUTOINCREMENT,
subject_id INTEGER NOT NULL,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
question_text TEXT NOT NULL,
upvotes INTEGER NOT NULL,
has_answer BOOLEAN DEFAULT 0,
answer TEXT,
user_id INTEGER,
FOREIGN KEY (subject_id) REFERENCES subject (subject_id),
FOREIGN KEY (user_id) REFERENCES user (user_id)
);
CREATE TABLE subject (
subject_id INTEGER PRIMARY KEY AUTOINCREMENT,
subject_name TEXT UNIQUE NOT NULL,
user_id INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES user (user_id)
);
CREATE TABLE subject_day (
subject_day_id INTEGER PRIMARY KEY AUTOINCREMENT,
subject_id INTEGER,
topic TEXT NOT NULL,
FOREIGN KEY (subject_id) REFERENCES subject(subject_id)
);
INSERT INTO user (username, password, lecturer) VALUES ('admin','admin',1);
INSERT INTO user (username, password, lecturer) VALUES ('jassem','jassem',1);
INSERT INTO user (username, password, lecturer) VALUES ('user','user',0);
INSERT INTO user (username, password, lecturer) VALUES ('max','max',0);
INSERT INTO user (username, password, lecturer) VALUES ('leniwy_student31','password',0);
INSERT INTO subject (subject_name, user_id) VALUES ('Nudny przedmiot',1);
INSERT INTO subject (subject_name, user_id) VALUES ('TPI - najlepszy przedmiot',2);
INSERT INTO question (subject_id, question_text, upvotes, user_id) VALUES (1, 'Nudne pytanie',0, 1);
INSERT INTO question (subject_id, question_text, upvotes, user_id) VALUES (2, 'Czy pytania będą proste?',78, 1);
INSERT INTO question (subject_id, question_text, upvotes, user_id) VALUES (2, 'Czy to będzie na egzaminie?',111, 1);
INSERT INTO question (subject_id, question_text, upvotes, user_id) VALUES (2, 'Nic nie rozumiem.',6, 1);
INSERT INTO question (subject_id, question_text, upvotes, user_id) VALUES (2, 'Chcę zdaaaaać',9, 1);
select * from user;
select * from question;
select * from subject;