Skip to content

fix(db-postgres): keep generated down migrations idempotent#17490

Open
deepshekhardas wants to merge 1 commit into
payloadcms:mainfrom
deepshekhardas:fix/pr-16767-down-migrations-idempotent
Open

fix(db-postgres): keep generated down migrations idempotent#17490
deepshekhardas wants to merge 1 commit into
payloadcms:mainfrom
deepshekhardas:fix/pr-16767-down-migrations-idempotent

Conversation

@deepshekhardas

Copy link
Copy Markdown
Contributor

Rebased on latest main with conflict resolution.\n\nConflict resolved:\n- packages/drizzle/src/exports/postgres.ts: kept both PR's makePostgresDropsIdempotent export and upstream's migratePostgresLocalizeStatus export

Generated migrations sequence the dependent drops drizzle-kit emits,
but Postgres also drops foreign keys when its referenced table is
dropped with CASCADE. Subsequent ALTER TABLE … DROP CONSTRAINT / DROP
INDEX statements in the same script then fail because the objects are
already gone. Rewrite those drops to use IF EXISTS in db-postgres and
db-vercel-postgres before the SQL is written to the migration file.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant