aboutsummaryrefslogtreecommitdiff
path: root/migrations/005_create_comments_tables.sql
diff options
context:
space:
mode:
authorAlexander Kavon <me+git@alexkavon.com>2024-01-24 04:11:59 -0500
committerAlexander Kavon <me+git@alexkavon.com>2024-01-24 04:11:59 -0500
commitd73dd37027e5d9b53cd56481c78d43c0942d2d68 (patch)
tree8fd4d757b09753b23226d26a2885403c37b7dc57 /migrations/005_create_comments_tables.sql
parent2741cbac9cdb671be6dcbb60057ecc7e2cb8836c (diff)
remove .sql.sql file extension for migration files, drop type enum on migrate down
Diffstat (limited to 'migrations/005_create_comments_tables.sql')
-rw-r--r--migrations/005_create_comments_tables.sql22
1 files changed, 22 insertions, 0 deletions
diff --git a/migrations/005_create_comments_tables.sql b/migrations/005_create_comments_tables.sql
new file mode 100644
index 0000000..3717c0c
--- /dev/null
+++ b/migrations/005_create_comments_tables.sql
@@ -0,0 +1,22 @@
+CREATE TYPE comment_state AS ENUM ('hidden', 'visible');
+
+CREATE TABLE comments(
+ id SERIAL NOT NULL PRIMARY KEY,
+ comment TEXT NOT NULL,
+ user_id INT NOT NULL REFERENCES users(id),
+ post_id INT NOT NULL REFERENCES posts(id) ON DELETE CASCADE,
+ reply_id INT REFERENCES comments(id) ON DELETE CASCADE,
+ state comment_state DEFAULT 'visible',
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
+);
+
+CREATE TRIGGER set_timestamp
+BEFORE UPDATE ON comments
+FOR EACH ROW
+EXECUTE PROCEDURE trigger_set_timestamp();
+
+---- create above / drop below ----
+
+DROP TABLE comments;
+DROP TYPE comment_state;