From dd86f38b5a03b2890491e6519d8233e86dd4a3c3 Mon Sep 17 00:00:00 2001 From: Buravit Yenjit Date: Tue, 1 Apr 2025 13:42:07 +0700 Subject: [PATCH] feat: add migration for knowledgeHub --- .../00004_create_knowledge_hub_tables.sql | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 backend/migrations/00004_create_knowledge_hub_tables.sql diff --git a/backend/migrations/00004_create_knowledge_hub_tables.sql b/backend/migrations/00004_create_knowledge_hub_tables.sql new file mode 100644 index 0000000..4d8b722 --- /dev/null +++ b/backend/migrations/00004_create_knowledge_hub_tables.sql @@ -0,0 +1,41 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE knowledge_articles ( + uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(), + title TEXT NOT NULL, + content TEXT NOT NULL, + author TEXT NOT NULL, + publish_date TIMESTAMPTZ NOT NULL, + read_time TEXT NOT NULL, + categories TEXT[] NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +CREATE TABLE table_of_contents ( + uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(), + article_id UUID NOT NULL, + title TEXT NOT NULL, + "order" INT NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + CONSTRAINT fk_toc_article FOREIGN KEY (article_id) REFERENCES knowledge_articles(uuid) ON DELETE CASCADE +); + +CREATE TABLE related_articles ( + uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(), + article_id UUID NOT NULL, + related_title TEXT NOT NULL, + related_tag TEXT NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + CONSTRAINT fk_related_article FOREIGN KEY (article_id) REFERENCES knowledge_articles(uuid) ON DELETE CASCADE +); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE IF EXISTS related_articles; +DROP TABLE IF EXISTS table_of_contents; +DROP TABLE IF EXISTS knowledge_articles; +-- +goose StatementEnd \ No newline at end of file