31 lines
1.4 KiB
SQL
31 lines
1.4 KiB
SQL
ALTER TABLE "catalog"."catalog_character" ADD COLUMN "talents" jsonb DEFAULT '[]'::jsonb NOT NULL;--> statement-breakpoint
|
|
WITH ranked_groups AS (
|
|
SELECT "id", row_number() OVER (PARTITION BY "guide_id" ORDER BY "sort_order", "id") AS "position"
|
|
FROM "guides"."artifact_group"
|
|
)
|
|
DELETE FROM "guides"."artifact_group"
|
|
WHERE "id" IN (SELECT "id" FROM ranked_groups WHERE "position" > 2);--> statement-breakpoint
|
|
WITH ranked_groups AS (
|
|
SELECT "id", row_number() OVER (PARTITION BY "guide_id" ORDER BY "sort_order", "id") AS "position"
|
|
FROM "guides"."artifact_group"
|
|
)
|
|
UPDATE "guides"."artifact_group" AS artifact_group
|
|
SET "name" = CASE ranked_groups."position" WHEN 1 THEN 'Late Game' ELSE 'Early Game' END,
|
|
"sort_order" = ranked_groups."position" - 1
|
|
FROM ranked_groups
|
|
WHERE artifact_group."id" = ranked_groups."id";--> statement-breakpoint
|
|
INSERT INTO "guides"."artifact_group" ("guide_id", "name", "sort_order")
|
|
SELECT guide."id", 'Late Game', 0
|
|
FROM "guides"."guide" AS guide
|
|
WHERE NOT EXISTS (
|
|
SELECT 1 FROM "guides"."artifact_group" AS artifact_group
|
|
WHERE artifact_group."guide_id" = guide."id" AND artifact_group."sort_order" = 0
|
|
);--> statement-breakpoint
|
|
INSERT INTO "guides"."artifact_group" ("guide_id", "name", "sort_order")
|
|
SELECT guide."id", 'Early Game', 1
|
|
FROM "guides"."guide" AS guide
|
|
WHERE NOT EXISTS (
|
|
SELECT 1 FROM "guides"."artifact_group" AS artifact_group
|
|
WHERE artifact_group."guide_id" = guide."id" AND artifact_group."sort_order" = 1
|
|
);
|