fix: release query runner when there is no migration to revert (#11232)

Co-authored-by: Adrien PEREZ <adrien-perez@samse.fr>
This commit is contained in:
mjr128 2025-12-06 15:36:34 +01:00 committed by GitHub
parent 2d8c5158db
commit a46eb0a7e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View File

@ -417,6 +417,8 @@ export class MigrationExecutor {
this.connection.logger.logSchemaBuild(
`No migrations were found in the database. Nothing to revert!`,
)
// if query runner was created by us then release it
if (!this.queryRunner) await queryRunner.release()
return
}

View File

@ -0,0 +1,30 @@
import { expect } from "chai"
import "reflect-metadata"
import { DataSource } from "../../../src/data-source/DataSource"
import {
closeTestingConnections,
createTestingConnections,
} from "../../utils/test-utils"
describe("github issues > #11231 Error trying to revert last migration when there is none on Oracle", () => {
let dataSources: DataSource[]
before(
async () =>
(dataSources = await createTestingConnections({
entities: [],
enabledDrivers: ["oracle"],
migrations: [],
schemaCreate: false,
dropSchema: true,
})),
)
after(() => closeTestingConnections(dataSources))
it("should not throw when migrations list is empty", () =>
Promise.all(
dataSources.map(async (dataSource) => {
await dataSource.undoLastMigration()
expect(await dataSource.destroy()).to.not.throw
}),
))
})