Files
buzz-sheet/drizzle/0045_simple_argent.sql
gunshiz 13b6c646fe
CI / Build immutable images and deploy (push) Successful in 6m36s
feat(artifact) : add tier-list conditions
2026-09-17 17:02:46 +07:00

27 lines
1.8 KiB
SQL

CREATE TABLE "guides"."artifact_condition" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"guide_id" uuid NOT NULL,
"name" varchar(120),
"note" text,
"sort_order" integer DEFAULT 0 NOT NULL
);
--> statement-breakpoint
INSERT INTO "guides"."artifact_condition" ("guide_id", "sort_order")
SELECT DISTINCT "guide_id", 0 FROM "guides"."artifact_group";
--> statement-breakpoint
ALTER TABLE "guides"."artifact_group" DROP CONSTRAINT "artifact_group_guide_id_guide_id_fk";
--> statement-breakpoint
DROP INDEX "guides"."artifact_group_order_idx";--> statement-breakpoint
ALTER TABLE "guides"."artifact_group" ADD COLUMN "condition_id" uuid;--> statement-breakpoint
UPDATE "guides"."artifact_group" AS "artifact_group"
SET "condition_id" = "artifact_condition"."id"
FROM "guides"."artifact_condition" AS "artifact_condition"
WHERE "artifact_condition"."guide_id" = "artifact_group"."guide_id";
--> statement-breakpoint
ALTER TABLE "guides"."artifact_group" ALTER COLUMN "condition_id" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "guides"."artifact_condition" ADD CONSTRAINT "artifact_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 "artifact_condition_order_idx" ON "guides"."artifact_condition" USING btree ("guide_id","sort_order");--> statement-breakpoint
ALTER TABLE "guides"."artifact_group" ADD CONSTRAINT "artifact_group_condition_id_artifact_condition_id_fk" FOREIGN KEY ("condition_id") REFERENCES "guides"."artifact_condition"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "artifact_group_order_idx" ON "guides"."artifact_group" USING btree ("condition_id","sort_order");--> statement-breakpoint
ALTER TABLE "guides"."artifact_group" DROP COLUMN "guide_id";