-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds tests to demonstrate the bug found in #6950
- Loading branch information
Showing
3 changed files
with
128 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Category } from "../../../functional/migrations/generate-command/entity"; | ||
import { Entity, BaseEntity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable } from "../../../../src"; | ||
import "reflect-metadata"; | ||
|
||
@Entity("post_test", { schema: "public" }) | ||
export class Post extends BaseEntity { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
title: string; | ||
|
||
@Column({ | ||
default: "This is default text." | ||
}) | ||
text: string; | ||
|
||
@Column({ | ||
default: null, | ||
}) | ||
comments: string; | ||
|
||
@ManyToMany(type => Category) | ||
@JoinTable() | ||
categories: Category[]; | ||
|
||
} |
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,29 @@ | ||
import { Category } from "../../../functional/migrations/generate-command/entity"; | ||
import { Entity, BaseEntity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable } from "../../../../src"; | ||
|
||
@Entity("post_test", { schema: "public" }) | ||
export class Post extends BaseEntity { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
title: string; | ||
|
||
@Column({ | ||
default: "This is default text." | ||
}) | ||
text: string; | ||
|
||
@Column({ | ||
nullable: true, | ||
default: null, | ||
type: 'text' | ||
}) | ||
comments: string | null; | ||
|
||
@ManyToMany(type => Category) | ||
@JoinTable() | ||
categories: Category[]; | ||
|
||
} |
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,71 @@ | ||
import "reflect-metadata"; | ||
import { Connection } from "../../../src"; | ||
|
||
import { Category } from "../../functional/migrations/generate-command/entity"; | ||
import { createTestingConnections, closeTestingConnections } from "../../utils/test-utils"; | ||
|
||
import { Post as Post1 } from './entity/post_with_null_1.entity' | ||
import { Post as Post2 } from './entity/post_with_null_1.entity' | ||
|
||
describe("github issues > #6950 postgres: Inappropiate migration generated for 'default: null'", () => { | ||
describe('null default', () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
migrations: [], | ||
enabledDrivers: ["postgres", "cockroachdb", "mysql"], | ||
schemaCreate: false, | ||
dropSchema: true, | ||
entities: [Post1, Category], | ||
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.skip("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(); | ||
|
||
sqlInMemory.upQueries.length.should.be.equal(0); | ||
sqlInMemory.downQueries.length.should.be.equal(0); | ||
|
||
}))); | ||
|
||
}) | ||
describe('null default and nullable ', () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
migrations: [], | ||
enabledDrivers: ["postgres", "cockroachdb", "mysql"], | ||
schemaCreate: false, | ||
dropSchema: true, | ||
entities: [Post2, Category], | ||
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.skip("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(); | ||
|
||
sqlInMemory.upQueries.length.should.be.equal(0); | ||
sqlInMemory.downQueries.length.should.be.equal(0); | ||
|
||
}))); | ||
|
||
}) | ||
}); |