blog/backend/migrations/20250505012740_v0.1.1.sql
SquidSpirit e72f5a5a8e
All checks were successful
Frontend CI / build (push) Successful in 1m29s
BLOG-43 feat: connect to database
2025-05-07 03:06:43 +08:00

31 lines
917 B
SQL

-- Add migration script here
CREATE TABLE "post" (
"id" SERIAL PRIMARY KEY NOT NULL,
"title" TEXT NOT NULL,
"description" TEXT NOT NULL,
"preview_image_url" TEXT NOT NULL,
"content" TEXT NOT NULL,
"published_time" TIMESTAMP,
"deleted_time" TIMESTAMP,
"created_time" TIMESTAMP NOT NULL,
"updated_time" TIMESTAMP NOT NULL
);
CREATE TABLE "label" (
"id" SERIAL PRIMARY KEY NOT NULL,
"name" TEXT NOT NULL,
"color" BIGINT NOT NULL CHECK ("color" >= 0 AND "color" <= 4294967295),
"deleted_time" TIMESTAMP,
"created_time" TIMESTAMP NOT NULL,
"updated_time" TIMESTAMP NOT NULL
);
CREATE TABLE "post_label" (
"post_id" INTEGER NOT NULL,
"label_id" INTEGER NOT NULL,
PRIMARY KEY ("post_id", "label_id"),
FOREIGN KEY ("post_id") REFERENCES "post" ("id") ON DELETE CASCADE,
FOREIGN KEY ("label_id") REFERENCES "label" ("id") ON DELETE CASCADE
);