-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migrations being generated for FK even if there are no changes (#…
…5869) * Fix migrations being generated for FK even if there are no changes * Fix tslint errors Co-authored-by: Svetlozar Argirov <[email protected]>
- Loading branch information
Showing
6 changed files
with
104 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,36 @@ | ||
import "reflect-metadata"; | ||
import {createTestingConnections, closeTestingConnections, /*reloadTestingDatabases*/} from "../../../utils/test-utils"; | ||
import {Connection} from "../../../../src/connection/Connection"; | ||
import { Category, Post } from "./entity"; | ||
|
||
describe("migrations > generate command", () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
migrations: [], | ||
enabledDrivers: ["postgres"], | ||
schemaCreate: false, | ||
dropSchema: true, | ||
entities: [Post, Category], | ||
logging: true, | ||
schema: "public", | ||
})); | ||
// beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("can recognize model changes", () => Promise.all(connections.map(async connection => { | ||
const sqlInMemory = await connection.driver.createSchemaBuilder().log(); | ||
sqlInMemory.upQueries.length.should.be.greaterThan(0); | ||
sqlInMemory.downQueries.length.should.be.greaterThan(0); | ||
}))); | ||
|
||
it("does not generate when no model changes", () => Promise.all(connections.map(async connection => { | ||
await connection.driver.createSchemaBuilder().build(); | ||
|
||
const sqlInMemory = await connection.driver.createSchemaBuilder().log(); | ||
|
||
console.log(sqlInMemory.upQueries); | ||
sqlInMemory.upQueries.length.should.be.equal(0); | ||
sqlInMemory.downQueries.length.should.be.equal(0); | ||
|
||
}))); | ||
}); |
15 changes: 15 additions & 0 deletions
15
test/functional/migrations/generate-command/entity/category.entity.ts
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,15 @@ | ||
import {PrimaryColumn} from "../../../../../src/decorator/columns/PrimaryColumn"; | ||
import {Entity} from "../../../../../src/decorator/entity/Entity"; | ||
import {BaseEntity} from "../../../../../src/repository/BaseEntity"; | ||
import {Column} from "../../../../../src/decorator/columns/Column"; | ||
|
||
@Entity("category_test", { schema: "public" }) | ||
export class Category extends BaseEntity { | ||
|
||
@PrimaryColumn() | ||
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,3 @@ | ||
export {Post} from "./post.entity"; | ||
export {Category} from "./category.entity"; | ||
export {Tag} from "./tag.entity"; |
26 changes: 26 additions & 0 deletions
26
test/functional/migrations/generate-command/entity/post.entity.ts
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,26 @@ | ||
import {Entity} from "../../../../../src/decorator/entity/Entity"; | ||
import {BaseEntity} from "../../../../../src/repository/BaseEntity"; | ||
import {PrimaryGeneratedColumn} from "../../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
import {Column} from "../../../../../src/decorator/columns/Column"; | ||
import {ManyToMany, JoinTable} from "../../../../../src"; | ||
import {Category} from "./category.entity"; | ||
|
||
@Entity("post_test", { schema: "public" }) | ||
export class Post extends BaseEntity { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
title: string; | ||
|
||
@Column({ | ||
default: "This is default text." | ||
}) | ||
text: string; | ||
|
||
@ManyToMany(type => Category) | ||
@JoinTable() | ||
categories: Category[]; | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
test/functional/migrations/generate-command/entity/tag.entity.ts
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,21 @@ | ||
import {PrimaryColumn} from "../../../../../src/decorator/columns/PrimaryColumn"; | ||
import {ManyToOne} from "../../../../../src/decorator/relations/ManyToOne"; | ||
import {JoinColumn} from "../../../../../src/decorator/relations/JoinColumn"; | ||
import {Entity} from "../../../../../src/decorator/entity/Entity"; | ||
import {BaseEntity} from "../../../../../src/repository/BaseEntity"; | ||
import {Column} from "../../../../../src/decorator/columns/Column"; | ||
import {Post} from "./post.entity"; | ||
|
||
@Entity("tag_test", { schema: "public" }) | ||
export class Tag extends BaseEntity { | ||
|
||
@PrimaryColumn() | ||
id: number; | ||
|
||
@Column() | ||
name: string; | ||
|
||
@ManyToOne(() => Post) | ||
@JoinColumn({ name: "tag_to_post" }) | ||
posts: Post | null; | ||
} |