B3: catalog taxonomy CRUD (categories, vendors, technologies, functions)

Create/rename/deactivate for the four taxonomy tables. Deactivate not
delete; slug frozen after creation; FKs ON DELETE RESTRICT.
- src/db/schema.ts: four tables + relations (ON DELETE RESTRICT FKs)
- src/lib/slug.ts: slugify (lowercase, ASCII-fold, collapse runs) + 6 tests
- src/db/catalog.ts: listCatalog (active filter), deactivateCatalog (soft
  delete), per-entity create*/update* (slug generated at create, frozen on
  update; update patches only present fields)
- src/app/api/dev/catalog/route.ts: GET/POST/PATCH; Zod per entity; DB
  constraint errors mapped to 409 (dup slug) / 400 (dangling FK) via cause
  chain
- drizzle/0003_whole_crystal.sql
Verification: typecheck, lint, 36 unit tests (+6), build, db:migrate all
exit 0. Runtime smoke: create -> rename keeps slug -> deactivate hides from
pickers but row persists (all four types); partial PATCH preserves omitted
fields; validation 400/400/400/409.
This commit is contained in:
Tiel Coder
2026-11-18 01:00:10 +00:00
parent 26b31978e2
commit 9f7a65b136
9 changed files with 2425 additions and 3 deletions
+75
View File
@@ -0,0 +1,75 @@
CREATE TABLE "functions" (
"id" text PRIMARY KEY NOT NULL,
"slug" text NOT NULL,
"name" text NOT NULL,
"category_id" text NOT NULL,
"description" text,
"sort_order" integer DEFAULT 0 NOT NULL,
"active" boolean DEFAULT true NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone,
CONSTRAINT "functions_slug_unique" UNIQUE("slug")
);
--> statement-breakpoint
CREATE TABLE "skill_categories" (
"id" text PRIMARY KEY NOT NULL,
"slug" text NOT NULL,
"name" text NOT NULL,
"description" text,
"color_hex" text,
"icon" text,
"sort_order" integer DEFAULT 0 NOT NULL,
"active" boolean DEFAULT true NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone,
CONSTRAINT "skill_categories_slug_unique" UNIQUE("slug")
);
--> statement-breakpoint
CREATE TABLE "technologies" (
"id" text PRIMARY KEY NOT NULL,
"slug" text NOT NULL,
"name" text NOT NULL,
"vendor_id" text NOT NULL,
"category_id" text NOT NULL,
"model_number" text,
"version_label" text,
"docs_url" text,
"purchased_on" date,
"serial_number" text,
"retired_at" timestamp with time zone,
"successor_technology_id" text,
"sort_order" integer DEFAULT 0 NOT NULL,
"active" boolean DEFAULT true NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone,
CONSTRAINT "technologies_slug_unique" UNIQUE("slug")
);
--> statement-breakpoint
CREATE TABLE "vendors" (
"id" text PRIMARY KEY NOT NULL,
"slug" text NOT NULL,
"name" text NOT NULL,
"support_url" text,
"support_phone" text,
"notes" text,
"sort_order" integer DEFAULT 0 NOT NULL,
"active" boolean DEFAULT true NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone,
CONSTRAINT "vendors_slug_unique" UNIQUE("slug")
);
--> statement-breakpoint
ALTER TABLE "functions" ADD CONSTRAINT "functions_category_id_skill_categories_id_fk" FOREIGN KEY ("category_id") REFERENCES "public"."skill_categories"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "technologies" ADD CONSTRAINT "technologies_vendor_id_vendors_id_fk" FOREIGN KEY ("vendor_id") REFERENCES "public"."vendors"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "technologies" ADD CONSTRAINT "technologies_category_id_skill_categories_id_fk" FOREIGN KEY ("category_id") REFERENCES "public"."skill_categories"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "functions_slug_idx" ON "functions" USING btree ("slug");--> statement-breakpoint
CREATE INDEX "functions_active_idx" ON "functions" USING btree ("active");--> statement-breakpoint
CREATE INDEX "functions_category_idx" ON "functions" USING btree ("category_id");--> statement-breakpoint
CREATE INDEX "skill_categories_slug_idx" ON "skill_categories" USING btree ("slug");--> statement-breakpoint
CREATE INDEX "skill_categories_active_idx" ON "skill_categories" USING btree ("active");--> statement-breakpoint
CREATE INDEX "technologies_slug_idx" ON "technologies" USING btree ("slug");--> statement-breakpoint
CREATE INDEX "technologies_active_idx" ON "technologies" USING btree ("active");--> statement-breakpoint
CREATE INDEX "technologies_vendor_idx" ON "technologies" USING btree ("vendor_id");--> statement-breakpoint
CREATE INDEX "technologies_category_idx" ON "technologies" USING btree ("category_id");--> statement-breakpoint
CREATE INDEX "vendors_slug_idx" ON "vendors" USING btree ("slug");--> statement-breakpoint
CREATE INDEX "vendors_active_idx" ON "vendors" USING btree ("active");
File diff suppressed because it is too large Load Diff
+7
View File
@@ -22,6 +22,13 @@
"when": 1794959606685,
"tag": "0002_fearless_doctor_spectrum",
"breakpoints": true
},
{
"idx": 3,
"version": "7",
"when": 1794961261600,
"tag": "0003_whole_crystal",
"breakpoints": true
}
]
}