fix(db-*): migration batch not incrementing past 1 (#12215)
When `payload migrate` is run and a record with name "dev" is returned having `batch: -1`, then the `batch` is not incrementing as expected as it is stuck at 1. This change makes it so the batch is incremented from the correct latest batch, ignoring the `name: "dev"` migration.
This commit is contained in:
@@ -42,10 +42,6 @@ export const migrate: DrizzleAdapter['migrate'] = async function migrate(
|
|||||||
limit: 0,
|
limit: 0,
|
||||||
sort: '-name',
|
sort: '-name',
|
||||||
}))
|
}))
|
||||||
if (Number(migrationsInDB?.[0]?.batch) > 0) {
|
|
||||||
latestBatch = Number(migrationsInDB[0]?.batch)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (migrationsInDB.find((m) => m.batch === -1)) {
|
if (migrationsInDB.find((m) => m.batch === -1)) {
|
||||||
const { confirm: runMigrations } = await prompts(
|
const { confirm: runMigrations } = await prompts(
|
||||||
@@ -67,6 +63,13 @@ export const migrate: DrizzleAdapter['migrate'] = async function migrate(
|
|||||||
if (!runMigrations) {
|
if (!runMigrations) {
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
}
|
}
|
||||||
|
// ignore the dev migration so that the latest batch number increments correctly
|
||||||
|
migrationsInDB = migrationsInDB.filter((m) => m.batch !== -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Number(migrationsInDB?.[0]?.batch) > 0) {
|
||||||
|
latestBatch = Number(migrationsInDB[0]?.batch)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const newBatch = latestBatch + 1
|
const newBatch = latestBatch + 1
|
||||||
|
|||||||
Reference in New Issue
Block a user