-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow clearing database inside a transaction (#8712)
* fix: allow clearing database inside a transaction Closes: #8527 * feat: added clear database inside transaction to sqlite and mysql databases * feat: added clear database inside transaction to aurora, cockroach, oracle, sap, sql server drivers Co-authored-by: Tadas Varanauskas <tadas@bitlocus.com>
- Loading branch information
1 parent
96ac8f7
commit f3cfdd2
Showing
10 changed files
with
100 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
import {Column} from "../../../../src/decorator/columns/Column"; | ||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
|
||
@Entity() | ||
export class TestEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import "reflect-metadata"; | ||
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { Connection } from "../../../src/connection/Connection"; | ||
import { expect } from "chai"; | ||
import { TestEntity } from "./entity/TestEntity"; | ||
|
||
describe("github issues > #8527 cannot clear database inside a transaction.", () => { | ||
let connections: Connection[]; | ||
|
||
before(async () => connections = await createTestingConnections({ | ||
entities: [TestEntity], | ||
enabledDrivers: [ | ||
"postgres", | ||
"sqlite", | ||
"mysql" | ||
], | ||
dropSchema: true, | ||
schemaCreate: true | ||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should not fail when clearing a database inside a transaction", () => Promise.all(connections.map(async (connection) => { | ||
const queryRunner = connection.createQueryRunner(); | ||
await queryRunner.startTransaction(); | ||
await expect(queryRunner.clearDatabase()).not.to.be.rejected; | ||
await queryRunner.commitTransaction(); | ||
await queryRunner.release(); | ||
}))); | ||
}); |