micrach/migrations/1-init.sql
Yanislav Igonin 1c2b8b83f1 m;wemklw
2021-08-30 10:03:14 +03:00

43 lines
808 B
SQL

-- 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,
name VARCHAR NOT NULL,
ext VARCHAR NOT NULL,
size INTEGER NOT NULL,
created_at TIMESTAMP DEFAULT NOW() NOT NULL,
FOREIGN KEY (post_id) REFERENCES posts (id)
);
-- DOWN
DROP TABLE files;
DROP TABLE posts;
DROP TABLE threads;