Adds website_submissions table + shared-secret POST endpoint so the marketing site can dual-write inquiries alongside its NocoDB write. Race-safe via INSERT ... ON CONFLICT, idempotent on submission_id, refuses every request when WEBSITE_INTAKE_SECRET is unset. Also repairs pre-existing 0020/0021/0022 prevId collision (renumbered + journal re-sorted) so db:generate works again. 11 unit tests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
30 lines
1.8 KiB
SQL
30 lines
1.8 KiB
SQL
CREATE TABLE "client_merge_candidates" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"port_id" text NOT NULL,
|
|
"client_a_id" text NOT NULL,
|
|
"client_b_id" text NOT NULL,
|
|
"score" integer NOT NULL,
|
|
"reasons" jsonb NOT NULL,
|
|
"status" text DEFAULT 'pending' NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"resolved_at" timestamp with time zone,
|
|
"resolved_by" text
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "migration_source_links" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"source_system" text NOT NULL,
|
|
"source_id" text NOT NULL,
|
|
"target_entity_type" text NOT NULL,
|
|
"target_entity_id" text NOT NULL,
|
|
"applied_id" text NOT NULL,
|
|
"applied_by" text,
|
|
"applied_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
ALTER TABLE "client_merge_candidates" ADD CONSTRAINT "client_merge_candidates_port_id_ports_id_fk" FOREIGN KEY ("port_id") REFERENCES "public"."ports"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "client_merge_candidates" ADD CONSTRAINT "client_merge_candidates_client_a_id_clients_id_fk" FOREIGN KEY ("client_a_id") REFERENCES "public"."clients"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "client_merge_candidates" ADD CONSTRAINT "client_merge_candidates_client_b_id_clients_id_fk" FOREIGN KEY ("client_b_id") REFERENCES "public"."clients"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
CREATE INDEX "idx_cmc_port_status" ON "client_merge_candidates" USING btree ("port_id","status");--> statement-breakpoint
|
|
CREATE UNIQUE INDEX "idx_cmc_pair" ON "client_merge_candidates" USING btree ("port_id","client_a_id","client_b_id");--> statement-breakpoint
|
|
CREATE UNIQUE INDEX "idx_msl_source_target" ON "migration_source_links" USING btree ("source_system","source_id","target_entity_type"); |