Slet users_threads, ændre users

user_id til cpr_num
slet email og address
This commit is contained in:
Mikkel
2022-06-02 16:06:07 +02:00
parent dc9f48cc1c
commit 213eec1813
2 changed files with 16 additions and 30 deletions

View File

@ -1,12 +1,10 @@
\i schema_drop.sql;
CREATE TABLE IF NOT EXISTS users (
user_id SERIAL PRIMARY KEY,
cpr_num INTEGER PRIMARY KEY,
first_name varchar(64) NOT NULL,
last_name varchar(64) NOT NULL,
password varchar(120) NOT NULL,
email varchar(64) NOT NULL UNIQUE,
address varchar(64) NOT NULL,
role varchar(64) NOT NULL CHECK ( role in ('student', 'parent', 'teacher') )
);
@ -26,28 +24,22 @@ CREATE TABLE IF NOT EXISTS messages (
message_id SERIAL PRIMARY KEY,
content text NOT NULL,
thread_id integer REFERENCES threads(thread_id) NOT NULL,
author_id integer REFERENCES users(user_id) NOT NULL,
author_cpr_num integer REFERENCES users(cpr_num) NOT NULL,
created_date timestamp NOT NULL DEFAULT now()
);
CREATE TABLE IF NOT EXISTS posts (
post_id SERIAL PRIMARY KEY,
group_id integer REFERENCES groups(group_id) NOT NULL,
author_id integer REFERENCES users(user_id) NOt NULL,
author_cpr_num integer REFERENCES users(cpr_num) NOt NULL,
title varchar(64) NOT NULL,
content text NOT NULL,
created_date timestamp NOT NULL DEFAULT now()
);
-- Relationships
CREATE TABLE IF NOT EXISTS users_threads (
user_id integer REFERENCES users(user_id) NOT NULL,
thread_id integer REFERENCES threads(thread_id) NOT NULL,
PRIMARY KEY (user_id, thread_id)
);
CREATE TABLE IF NOT EXISTS users_groups (
user_id integer REFERENCES users(user_id) NOT NULL,
user_cpr_num integer REFERENCES users(cpr_num) NOT NULL,
group_id integer REFERENCES groups(group_id) NOT NULL,
PRIMARY KEY (user_id, group_id)
PRIMARY KEY (user_cpr_num, group_id)
);