-
-
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.
feat: add support for non-generated columns with uuid_generate_v4() d…
…efault (#9065) * fix: support postgres column with varchar datatype and uuid_generate_v4() default Closes: #9063 * added test Co-authored-by: Dmitry Zotov <dmzt08@gmail.com>
- Loading branch information
1 parent
eb8f0c6
commit dadb658
Showing
3 changed files
with
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
Column, | ||
Entity, | ||
Generated, | ||
PrimaryGeneratedColumn, | ||
} from "../../../../src" | ||
|
||
@Entity() | ||
export class Post { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Column({ generated: "uuid" }) | ||
generatedUuid1: string | ||
|
||
@Generated("uuid") | ||
@Column({ type: "uuid" }) | ||
generatedUuid2: string | ||
|
||
@Column({ type: "uuid", default: () => "uuid_generate_v4()" }) | ||
generatedUuid3: string | ||
|
||
@Column({ type: "character varying", default: () => "uuid_generate_v4()" }) | ||
nonGeneratedUuid1: string | ||
|
||
@Column({ type: "character varying", default: () => "gen_random_uuid()" }) | ||
nonGeneratedUuid2: 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,63 @@ | ||
import "../../utils/test-setup" | ||
import { | ||
createTestingConnections, | ||
closeTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils" | ||
import { DataSource } from "../../../src" | ||
import { expect } from "chai" | ||
|
||
describe("github issues > #9063 Support postgres column with varchar datatype and uuid_generate_v4() default", () => { | ||
let connections: DataSource[] | ||
before( | ||
async () => | ||
(connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["postgres"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
})), | ||
) | ||
beforeEach(() => reloadTestingDatabases(connections)) | ||
after(() => closeTestingConnections(connections)) | ||
|
||
it("it should be able to set special keyword as column name for simple-enum types", () => | ||
Promise.all( | ||
connections.map(async (connection) => { | ||
const queryRunner = connection.createQueryRunner() | ||
const table = await queryRunner.getTable("post") | ||
const generatedUuid1 = | ||
table!.findColumnByName("generatedUuid1")! | ||
const generatedUuid2 = | ||
table!.findColumnByName("generatedUuid2")! | ||
const generatedUuid3 = | ||
table!.findColumnByName("generatedUuid3")! | ||
const nonGeneratedUuid1 = | ||
table!.findColumnByName("nonGeneratedUuid1")! | ||
const nonGeneratedUuid2 = | ||
table!.findColumnByName("nonGeneratedUuid2")! | ||
|
||
expect(generatedUuid1.isGenerated).to.be.true | ||
expect(generatedUuid1.type).to.equal("uuid") | ||
expect(generatedUuid1.default).to.be.undefined | ||
|
||
expect(generatedUuid2.isGenerated).to.be.true | ||
expect(generatedUuid2.type).to.equal("uuid") | ||
expect(generatedUuid2.default).to.be.undefined | ||
|
||
expect(generatedUuid3.isGenerated).to.be.true | ||
expect(generatedUuid3.type).to.equal("uuid") | ||
expect(generatedUuid3.default).to.be.undefined | ||
|
||
expect(nonGeneratedUuid1.isGenerated).to.be.false | ||
expect(nonGeneratedUuid1.type).to.equal("character varying") | ||
expect(nonGeneratedUuid1.default).to.equal("uuid_generate_v4()") | ||
|
||
expect(nonGeneratedUuid2.isGenerated).to.be.false | ||
expect(nonGeneratedUuid2.type).to.equal("character varying") | ||
expect(nonGeneratedUuid2.default).to.equal("gen_random_uuid()") | ||
|
||
await queryRunner.release() | ||
}), | ||
)) | ||
}) |