Make company skills migration idempotent
This commit is contained in:
parent
5de5fb507a
commit
82f253c310
1 changed files with 42 additions and 20 deletions
|
|
@ -1,21 +1,43 @@
|
||||||
CREATE TABLE "company_skills" (
|
DO $$
|
||||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
BEGIN
|
||||||
"company_id" uuid NOT NULL,
|
IF NOT EXISTS (
|
||||||
"slug" text NOT NULL,
|
SELECT 1
|
||||||
"name" text NOT NULL,
|
FROM information_schema.tables
|
||||||
"description" text,
|
WHERE table_schema = 'public' AND table_name = 'company_skills'
|
||||||
"markdown" text NOT NULL,
|
) THEN
|
||||||
"source_type" text DEFAULT 'local_path' NOT NULL,
|
CREATE TABLE "company_skills" (
|
||||||
"source_locator" text,
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||||
"source_ref" text,
|
"company_id" uuid NOT NULL,
|
||||||
"trust_level" text DEFAULT 'markdown_only' NOT NULL,
|
"slug" text NOT NULL,
|
||||||
"compatibility" text DEFAULT 'compatible' NOT NULL,
|
"name" text NOT NULL,
|
||||||
"file_inventory" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
"description" text,
|
||||||
"metadata" jsonb,
|
"markdown" text NOT NULL,
|
||||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
"source_type" text DEFAULT 'local_path' NOT NULL,
|
||||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
"source_locator" text,
|
||||||
);
|
"source_ref" text,
|
||||||
|
"trust_level" text DEFAULT 'markdown_only' NOT NULL,
|
||||||
|
"compatibility" text DEFAULT 'compatible' NOT NULL,
|
||||||
|
"file_inventory" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||||||
|
"metadata" jsonb,
|
||||||
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||||
|
);
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
--> statement-breakpoint
|
--> statement-breakpoint
|
||||||
ALTER TABLE "company_skills" ADD CONSTRAINT "company_skills_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
DO $$
|
||||||
CREATE UNIQUE INDEX "company_skills_company_slug_idx" ON "company_skills" USING btree ("company_id","slug");--> statement-breakpoint
|
BEGIN
|
||||||
CREATE INDEX "company_skills_company_name_idx" ON "company_skills" USING btree ("company_id","name");
|
IF NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM pg_constraint
|
||||||
|
WHERE conname = 'company_skills_company_id_companies_id_fk'
|
||||||
|
) THEN
|
||||||
|
ALTER TABLE "company_skills"
|
||||||
|
ADD CONSTRAINT "company_skills_company_id_companies_id_fk"
|
||||||
|
FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id")
|
||||||
|
ON DELETE no action ON UPDATE no action;
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "company_skills_company_slug_idx" ON "company_skills" USING btree ("company_id","slug");--> statement-breakpoint
|
||||||
|
CREATE INDEX IF NOT EXISTS "company_skills_company_name_idx" ON "company_skills" USING btree ("company_id","name");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue