/* MITHOME-138: generated by `payload migrate:create`, plus a hand-written backfill in up(). */ import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres' export async function up({ db, payload, req }: MigrateUpArgs): Promise { await db.execute(sql` ALTER TABLE "home_about_usps" ADD COLUMN "key" varchar; ALTER TABLE "home_services_items" ADD COLUMN "key" varchar; ALTER TABLE "_home_v_version_about_usps" ADD COLUMN "key" varchar; ALTER TABLE "_home_v_version_services_items" ADD COLUMN "key" varchar;`) // MITHOME-138 (hand-written backfill): the editable key used to be the row // id itself; in the version tables the original row id is kept in `_uuid`. // The row ids stay, so the page renders the same rows. await db.execute(sql` UPDATE "home_about_usps" SET "key" = "id" WHERE "key" IS NULL; UPDATE "home_services_items" SET "key" = "id" WHERE "key" IS NULL; UPDATE "_home_v_version_about_usps" SET "key" = "_uuid" WHERE "key" IS NULL; UPDATE "_home_v_version_services_items" SET "key" = "_uuid" WHERE "key" IS NULL;`) } export async function down({ db, payload, req }: MigrateDownArgs): Promise { await db.execute(sql` ALTER TABLE "home_about_usps" DROP COLUMN "key"; ALTER TABLE "home_services_items" DROP COLUMN "key"; ALTER TABLE "_home_v_version_about_usps" DROP COLUMN "key"; ALTER TABLE "_home_v_version_services_items" DROP COLUMN "key";`) }