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

Commit 1b9c5ab

Browse files
committed
added test for typeorm#3997
1 parent 67cf4c3 commit 1b9c5ab

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn} from "../../../../src";
2+
import {User} from "./User";
3+
4+
@Entity()
5+
export class Photo {
6+
7+
@PrimaryGeneratedColumn()
8+
id: number;
9+
10+
@Column()
11+
name: string;
12+
13+
@Column()
14+
userId: string;
15+
16+
@ManyToOne(_type => User, type => type.photos)
17+
@JoinColumn({ name: 'userId' })
18+
user: User;
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {Column, Entity, OneToMany, PrimaryGeneratedColumn} from "../../../../src";
2+
import {Photo} from "./Photo";
3+
4+
@Entity()
5+
export class User {
6+
@PrimaryGeneratedColumn()
7+
id: number;
8+
9+
@Column()
10+
name: string;
11+
12+
@Column("decimal", { precision: 9, scale: 6 })
13+
height: number;
14+
15+
@OneToMany(_type => Photo, type => type.user, { cascade: true })
16+
photos: Photo[];
17+
}
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 {closeTestingConnections, createTestingConnections} from "../../utils/test-utils";
4+
import {Photo} from "./entity/Photo";
5+
import {User} from "./entity/User";
6+
7+
describe("github issues > #3997 synchronize=true always failing when using decimal column type with a foreign key constraint", () => {
8+
let connections: Connection[];
9+
before(async () => connections = await createTestingConnections({
10+
schemaCreate: false,
11+
dropSchema: true,
12+
entities: [User, Photo],
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)