-
-
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: Array type default value should not generate SQL commands withou…
…t change (#7409) * fix(1532) Array type default value should not generate SQL commands without change * Update PostgresDriver.ts * removed `arrayCast` from `normalizeDefault` since casting for default value is already removed in `PostgresQueryRunner.loadTables()` method; * removed support for function definition in `default` because function syntax suppose to support raw sql, we don't have to confuse things by applying custom modifications. * Update User.ts removed incorrect `default` definition with functions Co-authored-by: AlexMesser <dmzt08@gmail.com>
- Loading branch information
1 parent
01a215a
commit 7f06e44
Showing
3 changed files
with
63 additions
and
11 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,27 @@ | ||
import {PrimaryColumn, Column} from "../../../../src"; | ||
import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
|
||
@Entity() | ||
export class User { | ||
|
||
@PrimaryColumn() | ||
id: number; | ||
|
||
@Column({ type: "varchar", array: true }) | ||
array: string[]; | ||
|
||
@Column({ type: "varchar", array: true, nullable: false }) | ||
nonNullArray: string[]; | ||
|
||
@Column({ type: "varchar", array: true, nullable: false, default: [] }) | ||
emptyArrayDefault: string[]; | ||
|
||
@Column({ type: "varchar", array: true, nullable: false, default: ["a", "b", "c"] }) | ||
filledArrayDefault: string[]; | ||
|
||
@Column({ type: "varchar", array: true, nullable: false, default: "{}" }) | ||
emptyArrayDefaultString: string[]; | ||
|
||
@Column({ type: "varchar", array: true, nullable: false, default: "{a,b,c}" }) | ||
filledArrayDefaultString: 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 {Connection} from "../../../src"; | ||
import {createTestingConnections, closeTestingConnections} from "../../utils/test-utils"; | ||
import {User} from "./entity/User"; | ||
|
||
describe("github issues > #1532 Array type default value doesnt work. PostgreSQL", () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
migrations: [], | ||
enabledDrivers: ["postgres"], | ||
schemaCreate: false, | ||
dropSchema: true, | ||
entities: [User], | ||
})); | ||
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(); | ||
sqlInMemory.upQueries.length.should.be.equal(0); | ||
sqlInMemory.downQueries.length.should.be.equal(0); | ||
}))); | ||
}); |