-
-
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: redundant migration with decimal default (#6879)
MySQL/MariaDB decimal column is represented like '0.0'. MysqlDriver.normalizeDefault didn't consider trailing zeros. User can bypass this by passing default as string, but we can't guide the zeros by type, so we should convert user input. undefined scale was compared with defined scale. Skip this comparison. Close #6140 Close #5407
- Loading branch information
Showing
7 changed files
with
82 additions
and
9 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
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
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,41 @@ | ||
import {PrimaryColumn, Column} from "../../../../src"; | ||
import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
|
||
@Entity() | ||
export class User { | ||
|
||
@PrimaryColumn() | ||
id: number; | ||
|
||
@Column("decimal", { default: -0, precision: 3, scale: 1 }) | ||
decimalWithDefault: number; | ||
|
||
@Column("decimal", { default: 100, precision: 3 }) | ||
noScale: number; | ||
|
||
@Column("decimal", { default: 10, precision: 3, scale: 0 }) | ||
zeroScale: number; | ||
|
||
@Column("decimal", { default: 9999999999 }) | ||
maxDefault: number; | ||
|
||
@Column("decimal", { default: -9999999999 }) | ||
minDefault: number; | ||
|
||
@Column("int", { default: -100 }) | ||
intDefault: number; | ||
|
||
@Column("float", { default: 3.5 }) | ||
floatDefault: number; | ||
|
||
@Column({ default: "New user" }) | ||
stringDefault: string; | ||
|
||
// ER_PARSE_ERROR | ||
// @Column("decimal", { default: 0, precision: 8, scale: -4 }) | ||
// negativeScale: number; | ||
|
||
// ER_INVALID_DEFAULT | ||
// @Column("decimal", { default: -12345.67890, precision: 8, scale: 4 }) | ||
// defaultOverflow: number; | ||
} |
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 > #5407 Wrong migration created because of default column value format", () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
migrations: [], | ||
enabledDrivers: ["mysql", "mariadb", "postgres", "better-sqlite3", "cockroachdb", "sqlite"], | ||
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); | ||
}))); | ||
}); |