Skip to content

Instantly share code, notes, and snippets.

@DonerKebab
Last active August 24, 2024 19:17
Show Gist options
  • Save DonerKebab/8c8d71970d84229ba561923ec21a6390 to your computer and use it in GitHub Desktop.
Save DonerKebab/8c8d71970d84229ba561923ec21a6390 to your computer and use it in GitHub Desktop.
### _ListingToSpelling
ALTER TABLE "Item"
ADD CONSTRAINT "Item_id_unique" UNIQUE (id);
ALTER TABLE "_ListingToSpelling"
ADD COLUMN "itemId" text SET NOT NULL;
UPDATE "_ListingToSpelling" ls
SET "itemId" = CAST(i.id as uuid)
FROM "Item" i
WHERE ls."A" = i.url;
ALTER TABLE "_ItemToLocalOptionGroup"
ALTER COLUMN "itemId" SET NOT NULL; ALTER COLUMN "itemId" SET NOT NULL
ALTER TABLE "_ListingToSpelling"
DROP CONSTRAINT "_ListingToSpelling_A_fkey";
ALTER TABLE "_ListingToSpelling"
ADD CONSTRAINT "_ListingToSpelling_itemId_fkey"
FOREIGN KEY ("itemId") REFERENCES "Item"(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE "_ListingToSpelling"
ADD CONSTRAINT "_ListingToSpelling_B_itemId_unique" UNIQUE ("B", "itemId");
ALTER TABLE "_ListingToSpelling"
DROP COLUMN "A";
### _ListingToSpelling
@DonerKebab
Copy link
Author

ALTER TABLE "Card"
ADD CONSTRAINT "Card_id_unique" UNIQUE (id);

ALTER TABLE "_CardToMake"
ADD COLUMN "cardId" text;

UPDATE "_CardToMake" ls
SET "cardId" = CAST(i.id as uuid)
FROM "Card" i
WHERE ls."A" = i.url;

ALTER TABLE "_CardToMake"
ALTER COLUMN "cardId" SET NOT NULL;

ALTER TABLE "_CardToMake"
DROP CONSTRAINT "_CardToMake_A_fkey";

ALTER TABLE "_CardToMake"
ADD CONSTRAINT "_CardToMake_cardId_fkey"
FOREIGN KEY ("cardId") REFERENCES "Card"(id) ON UPDATE CASCADE ON DELETE CASCADE;

ALTER TABLE "_CardToMake"
ADD CONSTRAINT "_CardToMake_B_itemId_unique" UNIQUE ("B", "cardId");

ALTER TABLE "_GlobalOptionGroupToItem"
DROP COLUMN "A";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment