From a46eb0a7e18df52a39e5f39ae2c4e67a89c945d9 Mon Sep 17 00:00:00 2001 From: mjr128 Date: Sat, 6 Dec 2025 15:36:34 +0100 Subject: [PATCH] fix: release query runner when there is no migration to revert (#11232) Co-authored-by: Adrien PEREZ --- src/migration/MigrationExecutor.ts | 2 ++ test/github-issues/11231/issue-11231.ts | 30 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/github-issues/11231/issue-11231.ts diff --git a/src/migration/MigrationExecutor.ts b/src/migration/MigrationExecutor.ts index bff8db8c6..60ae265a6 100644 --- a/src/migration/MigrationExecutor.ts +++ b/src/migration/MigrationExecutor.ts @@ -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 } diff --git a/test/github-issues/11231/issue-11231.ts b/test/github-issues/11231/issue-11231.ts new file mode 100644 index 000000000..e695c9ce5 --- /dev/null +++ b/test/github-issues/11231/issue-11231.ts @@ -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 + }), + )) +})