From ce6436ab0a058af7d012cb60ca7c9c18c6482743 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Mon, 27 Apr 2026 14:14:43 +0200 Subject: [PATCH] fix: manual migration for Agbs collection to resolve staging 500 error and cleanup failures --- package.json | 3 +- .../20260225_003500_add_pages_collection.json | 5 -- .../20260427_123000_add_agbs_collection.ts | 56 +++++++++++++++++++ src/migrations/index.ts | 7 +++ 4 files changed, 65 insertions(+), 6 deletions(-) delete mode 100644 src/migrations/20260225_003500_add_pages_collection.json create mode 100644 src/migrations/20260427_123000_add_agbs_collection.ts diff --git a/package.json b/package.json index cd3d2226..95899ff8 100644 --- a/package.json +++ b/package.json @@ -116,6 +116,7 @@ "pdf:datasheets": "tsx ./scripts/generate-pdf-datasheets.ts", "pdf:datasheets:legacy": "tsx ./scripts/generate-pdf-datasheets-pdf-lib.ts", "cms:migrate": "payload migrate", + "cms:migrate:create": "payload migrate:create", "cms:seed": "tsx ./scripts/seed-payload.ts", "assets:push:testing": "bash ./scripts/assets-sync.sh local testing", "assets:push:staging": "bash ./scripts/assets-sync.sh local staging", @@ -139,7 +140,7 @@ "prepare": "husky", "preinstall": "npx only-allow pnpm" }, - "version": "2.3.22-rc.3", + "version": "2.3.22-rc.4", "pnpm": { "onlyBuiltDependencies": [ "@parcel/watcher", diff --git a/src/migrations/20260225_003500_add_pages_collection.json b/src/migrations/20260225_003500_add_pages_collection.json deleted file mode 100644 index 5f743d8e..00000000 --- a/src/migrations/20260225_003500_add_pages_collection.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": "20260225_003500_add_pages_collection", - "name": "20260225_003500_add_pages_collection", - "batch": 3 -} diff --git a/src/migrations/20260427_123000_add_agbs_collection.ts b/src/migrations/20260427_123000_add_agbs_collection.ts new file mode 100644 index 00000000..a475bd9c --- /dev/null +++ b/src/migrations/20260427_123000_add_agbs_collection.ts @@ -0,0 +1,56 @@ +import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'; + +export async function up({ db }: MigrateUpArgs): Promise { + await db.execute(sql` + CREATE TABLE IF NOT EXISTS "agbs_collection" ( + "id" serial PRIMARY KEY NOT NULL, + "version_date" timestamp(3) with time zone NOT NULL, + "file_id" integer NOT NULL, + "is_current" boolean DEFAULT false, + "updated_at" timestamp(3) with time zone DEFAULT now() NOT NULL, + "created_at" timestamp(3) with time zone DEFAULT now() NOT NULL + ); + + CREATE TABLE IF NOT EXISTS "agbs_collection_locales" ( + "id" serial PRIMARY KEY NOT NULL, + "title" varchar, + "_locale" "enum__locales" NOT NULL, + "_parent_id" integer NOT NULL + ); + + DO $$ BEGIN + ALTER TABLE "agbs_collection_locales" ADD CONSTRAINT "agbs_collection_locales_locale_parent_id_unique" UNIQUE("_locale", "_parent_id"); + EXCEPTION WHEN duplicate_object THEN null; END $$; + + DO $$ BEGIN + ALTER TABLE "agbs_collection_locales" ADD CONSTRAINT "agbs_collection_locales_parent_id_fk" + FOREIGN KEY ("_parent_id") REFERENCES "agbs_collection"("id") ON DELETE cascade; + EXCEPTION WHEN duplicate_object THEN null; END $$; + + DO $$ BEGIN + ALTER TABLE "agbs_collection" ADD CONSTRAINT "agbs_collection_file_id_media_id_fk" + FOREIGN KEY ("file_id") REFERENCES "public"."media"("id") ON DELETE set null; + EXCEPTION WHEN duplicate_object THEN null; END $$; + + CREATE INDEX IF NOT EXISTS "agbs_collection_updated_at_idx" ON "agbs_collection" USING btree ("updated_at"); + CREATE INDEX IF NOT EXISTS "agbs_collection_created_at_idx" ON "agbs_collection" USING btree ("created_at"); + + -- Add to payload_locked_documents_rels + ALTER TABLE "payload_locked_documents_rels" ADD COLUMN IF NOT EXISTS "agbs_collection_id" integer; + DO $$ BEGIN + ALTER TABLE "payload_locked_documents_rels" ADD CONSTRAINT "payload_locked_documents_rels_agbs_collection_fk" + FOREIGN KEY ("agbs_collection_id") REFERENCES "public"."agbs_collection"("id") ON DELETE cascade; + EXCEPTION WHEN duplicate_object THEN null; END $$; + CREATE INDEX IF NOT EXISTS "payload_locked_documents_rels_agbs_collection_id_idx" + ON "payload_locked_documents_rels" USING btree ("agbs_collection_id"); + `); +} + +export async function down({ db }: MigrateDownArgs): Promise { + await db.execute(sql` + ALTER TABLE "payload_locked_documents_rels" DROP CONSTRAINT IF EXISTS "payload_locked_documents_rels_agbs_collection_fk"; + ALTER TABLE "payload_locked_documents_rels" DROP COLUMN IF EXISTS "agbs_collection_id"; + DROP TABLE IF EXISTS "agbs_collection_locales" CASCADE; + DROP TABLE IF EXISTS "agbs_collection" CASCADE; + `); +} diff --git a/src/migrations/index.ts b/src/migrations/index.ts index 11dcba3a..7ec91b1e 100644 --- a/src/migrations/index.ts +++ b/src/migrations/index.ts @@ -5,6 +5,8 @@ import * as migration_20260225_175000_native_localization from './20260225_17500 import * as migration_20260305_215000_products_featured_image from './20260305_215000_products_featured_image'; import * as migration_20260312_120000_pages_redirect_fields from './20260312_120000_pages_redirect_fields'; +import * as migration_20260427_123000_add_agbs_collection from './20260427_123000_add_agbs_collection'; + export const migrations = [ { up: migration_20260223_195005_products_collection.up, @@ -36,4 +38,9 @@ export const migrations = [ down: migration_20260312_120000_pages_redirect_fields.down, name: '20260312_120000_pages_redirect_fields', }, + { + up: migration_20260427_123000_add_agbs_collection.up, + down: migration_20260427_123000_add_agbs_collection.down, + name: '20260427_123000_add_agbs_collection', + }, ];