Files
buzz-sheet/drizzle/0022_weapon_conditions.sql
gunshiz c9e0fe02e3
CI / Verify (push) Failing after 42s
CI / Build immutable images and deploy (push) Has been skipped
feat(weapons) : add conditions and unsaved changes warning
2026-09-04 00:33:03 +07:00

29 lines
1.8 KiB
SQL

CREATE TABLE "guides"."weapon_condition" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"guide_id" uuid NOT NULL,
"note" text,
"sort_order" integer DEFAULT 0 NOT NULL
);
--> statement-breakpoint
ALTER TABLE "guides"."weapon_condition" ADD CONSTRAINT "weapon_condition_guide_id_guide_id_fk" FOREIGN KEY ("guide_id") REFERENCES "guides"."guide"("id") ON DELETE cascade ON UPDATE no action;
--> statement-breakpoint
CREATE INDEX "weapon_condition_order_idx" ON "guides"."weapon_condition" USING btree ("guide_id","sort_order");
--> statement-breakpoint
ALTER TABLE "guides"."weapon_recommendation" ADD COLUMN "condition_id" uuid;
--> statement-breakpoint
INSERT INTO "guides"."weapon_condition" ("guide_id", "sort_order") SELECT DISTINCT "guide_id", 0 FROM "guides"."weapon_recommendation";
--> statement-breakpoint
UPDATE "guides"."weapon_recommendation" AS recommendation SET "condition_id" = condition."id" FROM "guides"."weapon_condition" AS condition WHERE condition."guide_id" = recommendation."guide_id";
--> statement-breakpoint
ALTER TABLE "guides"."weapon_recommendation" ALTER COLUMN "condition_id" SET NOT NULL;
--> statement-breakpoint
ALTER TABLE "guides"."weapon_recommendation" ADD CONSTRAINT "weapon_recommendation_condition_id_weapon_condition_id_fk" FOREIGN KEY ("condition_id") REFERENCES "guides"."weapon_condition"("id") ON DELETE cascade ON UPDATE no action;
--> statement-breakpoint
DROP INDEX IF EXISTS "guides"."weapon_recommendation_order_idx";
--> statement-breakpoint
CREATE INDEX "weapon_recommendation_order_idx" ON "guides"."weapon_recommendation" USING btree ("condition_id","sort_order");
--> statement-breakpoint
ALTER TABLE "guides"."weapon_recommendation" DROP CONSTRAINT IF EXISTS "weapon_recommendation_guide_id_guide_id_fk";
--> statement-breakpoint
ALTER TABLE "guides"."weapon_recommendation" DROP COLUMN "guide_id";