commit 249fc4f761e1a700e4ec558328a5d20cdc94940c Author: timoschneider Date: Fri Apr 12 21:18:31 2024 +0200 created experimental database diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b1ea853 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +docker-compose.yaml +database \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7416c8d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM postgres:alpine3.18 + +ADD init /docker-entrypoint-initdb.d \ No newline at end of file diff --git a/init/00_InitDB.sql b/init/00_InitDB.sql new file mode 100644 index 0000000..ef79d71 --- /dev/null +++ b/init/00_InitDB.sql @@ -0,0 +1,32 @@ +DROP TABLE IF EXISTS Users; +DROP TABLE IF EXISTS Posts; +DROP TABLE IF EXISTS Reaction; + +CREATE TABLE Users +( + id bigserial PRIMARY KEY, + username varchar(255) NOT NULL, + password varchar(255) NOT NULL, + deleted timestamp WITH TIME ZONE default NULL +); + +CREATE TABLE Posts +( + id bigserial PRIMARY KEY, + author bigserial REFERENCES Users(id) NOT NULL, + reference bigserial REFERENCES Posts(id) NOT NULL, + -- init with (select last_val from posts_id_seq) + title varchar(255) NOT NULL, + content varchar(1023) NOT NULL, + postDate timestamp WITH TIME ZONE NOT NULL DEFAULT now(), + postLocation Point NOT NULL, + deleted timestamp WITH TIME ZONE default NULL +); + +CREATE TABLE Reaction +( + id bigserial PRIMARY KEY, + post bigserial REFERENCES Posts(id) NOT NULL, + positive boolean DEFAULT NULL, + deleted timestamp WITH TIME ZONE default NULL +)