fix(db-*): migrate:reset executes in a wrong order (#12445)
fixes https://github.com/payloadcms/payload/issues/12442
This commit is contained in:
@@ -28,6 +28,8 @@ export async function migrateReset(this: DrizzleAdapter): Promise<void> {
|
||||
|
||||
const req = await createLocalReq({}, payload)
|
||||
|
||||
existingMigrations.reverse()
|
||||
|
||||
// Rollback all migrations in order
|
||||
for (const migration of existingMigrations) {
|
||||
const migrationFile = migrationFiles.find((m) => m.name === migration.name)
|
||||
|
||||
@@ -21,6 +21,8 @@ export async function migrateReset(this: BaseDatabaseAdapter): Promise<void> {
|
||||
|
||||
const req = await createLocalReq({}, payload)
|
||||
|
||||
migrationFiles.reverse()
|
||||
|
||||
// Rollback all migrations in order
|
||||
for (const migration of migrationFiles) {
|
||||
// Create or update migration in database
|
||||
|
||||
@@ -577,6 +577,27 @@ describe('database', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should run migrate:reset', async () => {
|
||||
// known drizzle issue: https://github.com/payloadcms/payload/issues/4597
|
||||
// eslint-disable-next-line jest/no-conditional-in-test
|
||||
if (!isMongoose(payload)) {
|
||||
return
|
||||
}
|
||||
let error
|
||||
try {
|
||||
await payload.db.migrateReset()
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
const migrations = await payload.find({
|
||||
collection: 'payload-migrations',
|
||||
})
|
||||
|
||||
expect(error).toBeUndefined()
|
||||
expect(migrations.docs).toHaveLength(0)
|
||||
})
|
||||
|
||||
describe('predefined migrations', () => {
|
||||
it('mongoose - should execute migrateVersionsV1_V2', async () => {
|
||||
// eslint-disable-next-line jest/no-conditional-in-test
|
||||
|
||||
Reference in New Issue
Block a user