Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit fc55277

Browse files
committed
added test for typeorm#7523
1 parent 36b14cb commit fc55277

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {Column, Entity, PrimaryGeneratedColumn} from "../../../../src";
2+
3+
enum FooEnum { FOO, BAR }
4+
5+
class ParentEntity {
6+
@PrimaryGeneratedColumn()
7+
ud: number
8+
9+
@Column({
10+
type: 'enum',
11+
enum: FooEnum,
12+
enumName: 'foo_enum',
13+
})
14+
foo: FooEnum;
15+
}
16+
17+
@Entity()
18+
export class ChildEntity1 extends ParentEntity {}
19+
20+
@Entity()
21+
export class ChildEntity2 extends ParentEntity {}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import "reflect-metadata";
2+
import {Connection} from "../../../src";
3+
import {createTestingConnections, closeTestingConnections} from "../../utils/test-utils";
4+
import {ChildEntity1, ChildEntity2} from "./entity/Test";
5+
6+
describe("github issues > #7523 Do not create duplicate CREATE TYPE migration query when same 'enumName's are exists", () => {
7+
let connections: Connection[];
8+
before(async () => connections = await createTestingConnections({
9+
enabledDrivers: ["postgres"],
10+
schemaCreate: false,
11+
dropSchema: true,
12+
entities: [ChildEntity1, ChildEntity2],
13+
}));
14+
after(() => closeTestingConnections(connections));
15+
16+
it("should recognize model changes", () => Promise.all(connections.map(async connection => {
17+
const sqlInMemory = await connection.driver.createSchemaBuilder().log();
18+
sqlInMemory.upQueries.length.should.be.greaterThan(0);
19+
sqlInMemory.downQueries.length.should.be.greaterThan(0);
20+
})));
21+
22+
it("should not generate queries when no model changes", () => Promise.all(connections.map(async connection => {
23+
await connection.driver.createSchemaBuilder().build();
24+
const sqlInMemory = await connection.driver.createSchemaBuilder().log();
25+
sqlInMemory.upQueries.length.should.be.equal(0);
26+
sqlInMemory.downQueries.length.should.be.equal(0);
27+
})));
28+
});

0 commit comments

Comments
 (0)