feat(db): 0003 分类域——taxonomy/term/content_terms

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-10-20 19:48:04 +08:00
parent 60581047ef
commit bc1dcc2ef9
5 changed files with 1620 additions and 2 deletions
@@ -0,0 +1,36 @@
CREATE TABLE "content_terms" (
"site_id" uuid NOT NULL,
"content_entry_id" uuid NOT NULL,
"term_id" uuid NOT NULL,
"is_primary" boolean NOT NULL,
CONSTRAINT "content_terms_site_id_content_entry_id_term_id_pk" PRIMARY KEY("site_id","content_entry_id","term_id")
);
--> statement-breakpoint
CREATE TABLE "taxonomies" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"site_id" uuid NOT NULL,
"key" text NOT NULL,
"object_type" text NOT NULL,
"public_base_path" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "terms" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"site_id" uuid NOT NULL,
"taxonomy_id" uuid NOT NULL,
"source_id" text NOT NULL,
"slug" text NOT NULL,
"name" text NOT NULL,
"parent_term_id" uuid,
"data" jsonb NOT NULL
);
--> statement-breakpoint
ALTER TABLE "content_terms" ADD CONSTRAINT "content_terms_site_id_sites_id_fk" FOREIGN KEY ("site_id") REFERENCES "public"."sites"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "content_terms" ADD CONSTRAINT "content_terms_content_entry_id_content_entries_id_fk" FOREIGN KEY ("content_entry_id") REFERENCES "public"."content_entries"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "content_terms" ADD CONSTRAINT "content_terms_term_id_terms_id_fk" FOREIGN KEY ("term_id") REFERENCES "public"."terms"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "taxonomies" ADD CONSTRAINT "taxonomies_site_id_sites_id_fk" FOREIGN KEY ("site_id") REFERENCES "public"."sites"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "terms" ADD CONSTRAINT "terms_site_id_sites_id_fk" FOREIGN KEY ("site_id") REFERENCES "public"."sites"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "terms" ADD CONSTRAINT "terms_taxonomy_id_taxonomies_id_fk" FOREIGN KEY ("taxonomy_id") REFERENCES "public"."taxonomies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "terms" ADD CONSTRAINT "terms_parent_term_id_terms_id_fk" FOREIGN KEY ("parent_term_id") REFERENCES "public"."terms"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "taxonomies_uq" ON "taxonomies" USING btree ("site_id","key","object_type");--> statement-breakpoint
CREATE UNIQUE INDEX "terms_identity_uq" ON "terms" USING btree ("site_id","taxonomy_id","source_id");
File diff suppressed because it is too large Load Diff
+7
View File
@@ -22,6 +22,13 @@
"when": 1792496109431,
"tag": "0002_fancy_silver_centurion",
"breakpoints": true
},
{
"idx": 3,
"version": "7",
"when": 1792496827818,
"tag": "0003_groovy_phil_sheldon",
"breakpoints": true
}
]
}