mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fix: proper default value on generating migration when default value is a function calling [Postgres] (#9830)
Co-authored-by: Dmytro Boiko <dmitriy.b@tracktica.com>
This commit is contained in:
parent
f7f6817864
commit
bebba05388
@ -3717,7 +3717,7 @@ export class PostgresQueryRunner
|
||||
} else {
|
||||
tableColumn.default = dbColumn[
|
||||
"column_default"
|
||||
].replace(/::.+/g, "")
|
||||
].replace(/::[\w\s.\[\]\-"]+/g, "")
|
||||
tableColumn.default =
|
||||
tableColumn.default.replace(
|
||||
/^(-?\d+)$/,
|
||||
|
||||
17
test/github-issues/9829/entity/ExampleEntity.ts
Normal file
17
test/github-issues/9829/entity/ExampleEntity.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { Entity } from "../../../../src/decorator/entity/Entity"
|
||||
import { Column } from "../../../../src/decorator/columns/Column"
|
||||
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"
|
||||
|
||||
@Entity()
|
||||
export class ExampleEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column({
|
||||
type: "varchar",
|
||||
length: 3,
|
||||
unique: true,
|
||||
default: () => "('AA'|| COALESCE(NULL, '1'))",
|
||||
})
|
||||
someValue: string
|
||||
}
|
||||
33
test/github-issues/9829/issue-9829.ts
Normal file
33
test/github-issues/9829/issue-9829.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource } from "../../../src/index"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
} from "../../utils/test-utils"
|
||||
import { ExampleEntity } from "./entity/ExampleEntity"
|
||||
|
||||
describe("github issues > #9829 Incorrect default value with concat value of function", () => {
|
||||
let connections: DataSource[]
|
||||
before(
|
||||
async () =>
|
||||
(connections = await createTestingConnections({
|
||||
entities: [ExampleEntity],
|
||||
schemaCreate: true,
|
||||
dropSchema: true,
|
||||
enabledDrivers: ["postgres"],
|
||||
})),
|
||||
)
|
||||
after(() => closeTestingConnections(connections))
|
||||
it("should get default concat value", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
const queryRunner = connection.createQueryRunner()
|
||||
let table = await queryRunner.getTable("example_entity")
|
||||
|
||||
const nameColumn = table!.findColumnByName("someValue")!
|
||||
nameColumn!.default!.should.be.equal(
|
||||
"('AA'|| COALESCE(NULL, '1'))",
|
||||
)
|
||||
}),
|
||||
))
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user