Skip to content

Commit

Permalink
fix: Drop and recreate
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 committed Jan 10, 2025
1 parent e15945b commit 0db8dbb
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions packages/db/drizzle/0052_graceful_taskmaster.sql
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
ALTER TABLE "environment_policy_approval" DROP CONSTRAINT "environment_policy_approval_policy_id_environment_policy_id_fk";
--> statement-breakpoint
ALTER TABLE "environment_policy_approval" DROP CONSTRAINT "environment_policy_approval_release_id_release_id_fk";
--> statement-breakpoint
ALTER TABLE "environment_policy_approval" DROP CONSTRAINT "environment_policy_approval_user_id_user_id_fk";
--> statement-breakpoint
DROP INDEX IF EXISTS "environment_policy_approval_policy_id_release_id_index";
--> statement-breakpoint
ALTER TABLE "environment_policy_approval" RENAME TO "environment_approval";
--> statement-breakpoint
ALTER TABLE "environment_approval" RENAME COLUMN "policy_id" TO "environment_id";
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "environment_approval" ADD CONSTRAINT "environment_approval_environment_id_environment_id_fk" FOREIGN KEY ("environment_id") REFERENCES "public"."environment"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "environment_approval" ADD CONSTRAINT "environment_approval_release_id_release_id_fk" FOREIGN KEY ("release_id") REFERENCES "public"."release"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "environment_approval" ADD CONSTRAINT "environment_approval_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "environment_approval_environment_id_release_id_index" ON "environment_approval" USING btree ("environment_id","release_id");
DROP TABLE IF EXISTS "environment_policy_approval";
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "environment_approval" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
"environment_id" uuid NOT NULL,
"release_id" uuid NOT NULL,
"status" approval_status_type NOT NULL DEFAULT 'pending',
"user_id" uuid,
FOREIGN KEY ("environment_id") REFERENCES "public"."environment"("id") ON DELETE CASCADE,
FOREIGN KEY ("release_id") REFERENCES "public"."release"("id") ON DELETE CASCADE,
FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE SET NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "environment_approval_environment_id_release_id_index"
ON "environment_approval" ("environment_id", "release_id");

0 comments on commit 0db8dbb

Please sign in to comment.