Files
blog-doc/db/blog_db.sql
2025-10-17 17:41:28 +08:00

39 lines
927 B
SQL

CREATE TABLE "articles" (
"id" bigserial,
"title" varchar(50) NOT NULL,
"content" text,
"published" time,
PRIMARY KEY ("id")
);
CREATE TABLE "comments" (
"id" bigserial,
"content" varchar(255) NOT NULL,
"published" time,
"u_id" int4,
"a_id" int4 NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "news" (
"id" bigserial,
"title" varchar(50) NOT NULL,
"content" text,
"published" time,
"related" uuid,
PRIMARY KEY ("id")
);
CREATE TABLE "users" (
"id" bigserial,
"name" varchar(50) NOT NULL,
"profile" varchar(255) NOT NULL DEFAULT https://www.merlin.xin/public/profile,
"account" varchar(255) NOT NULL,
"password" varchar(255) NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "articles" ADD CONSTRAINT "fk_articles_comments_1" FOREIGN KEY ("id") REFERENCES "comments" ("a_id");
ALTER TABLE "users" ADD CONSTRAINT "fk_users_comments_1" FOREIGN KEY ("id") REFERENCES "comments" ("u_id");