From e87b085227a7f0042059c0c5be38d2667bd7c051 Mon Sep 17 00:00:00 2001 From: Yanislav Igonin Date: Thu, 26 Aug 2021 17:50:27 +0300 Subject: [PATCH] feat: add initial migration --- migrations/1-init.sql | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 migrations/1-init.sql diff --git a/migrations/1-init.sql b/migrations/1-init.sql new file mode 100644 index 0000000..5635596 --- /dev/null +++ b/migrations/1-init.sql @@ -0,0 +1,43 @@ +-- UP +-- Threads +CREATE TABLE threads +( + id SERIAL NOT NULL, + is_deleted BOOLEAN NOT NULL, + created_at TIMESTAMP DEFAULT NOW() NOT NULL, + updated_at TIMESTAMP DEFAULT NOW() NOT NULL, + PRIMARY KEY (id) +); + +-- Posts +CREATE TABLE posts +( + id SERIAL NOT NULL, + thread_id INTEGER NOT NULL, + title VARCHAR NOT NULL, + text TEXT NOT NULL, + is_sage BOOLEAN NOT NULL, + created_at TIMESTAMP DEFAULT NOW() NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (thread_id) REFERENCES threads (id) +); + + +-- Files +CREATE TABLE files +( + id SERIAL PRIMARY KEY, + post_id INTEGER NOT NULL, + created_at TIMESTAMP DEFAULT NOW() NOT NULL, + name VARCHAR NOT NULL, + ext VARCHAR NOT NULL, + size INTEGER NOT NULL, + FOREIGN KEY (post_id) REFERENCES posts (id) +); + + + +-- DOWN +DROP TABLE files; +DROP TABLE posts; +DROP TABLE threads; \ No newline at end of file