-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
fix: resolve postgres array enum migration issue #6126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fd3e6a1
fix: resolve postgres array enum migration issue
TheNoim 0493a5a
test: add tests for pull request #6126
TheNoim 55a2964
style: match sql query style for issue #4350
TheNoim 11ee0db
test: fix issue 4350 tests
TheNoim 3319432
test: add cockroachdb to test for issue 4350
TheNoim 4c273f4
revert: add cockroachdb to test for issue 4350
TheNoim 29ee16b
fix: migration of non-array to array enum and array enum to non-array
TheNoim dd8a787
test: migration of non-array to array enum and array enum to non-array
TheNoim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,16 @@ | ||
| import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
| import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
| import {Column} from "../../../../src/decorator/columns/Column"; | ||
|
|
||
| export enum TestEnum1 { | ||
| VALUE1 = "VALUE1" | ||
| } | ||
|
|
||
| @Entity({ name: "post" }) | ||
| export class Post1 { | ||
| @PrimaryGeneratedColumn() | ||
| id: number; | ||
|
|
||
| @Column({ enum: TestEnum1, enumName: "TestEnum", type: "enum", array: true }) | ||
| testEnum: TestEnum1[]; | ||
| } |
This file contains hidden or 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,17 @@ | ||
| import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
| import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
| import {Column} from "../../../../src/decorator/columns/Column"; | ||
|
|
||
| export enum TestEnum2 { | ||
| VALUE1 = "VALUE1", | ||
| VALUE2 = "VALUE2" | ||
| } | ||
|
|
||
| @Entity({ name: "post" }) | ||
| export class Post2 { | ||
| @PrimaryGeneratedColumn() | ||
| id: number; | ||
|
|
||
| @Column({ enum: TestEnum2, enumName: "TestEnum", type: "enum", array: true }) | ||
| testEnum: TestEnum2[]; | ||
| } |
This file contains hidden or 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,13 @@ | ||
| import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
| import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
| import {Column} from "../../../../src/decorator/columns/Column"; | ||
| import {TestEnum2} from "./Post2"; | ||
|
|
||
| @Entity({ name: "post" }) | ||
| export class Post3 { | ||
| @PrimaryGeneratedColumn() | ||
| id: number; | ||
|
|
||
| @Column({ enum: TestEnum2, enumName: "TestEnum", type: "enum", array: false, nullable: true }) | ||
| testEnum: TestEnum2; | ||
| } |
This file contains hidden or 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,13 @@ | ||
| import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
| import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
| import {Column} from "../../../../src/decorator/columns/Column"; | ||
| import {TestEnum2} from "./Post2"; | ||
|
|
||
| @Entity({ name: "post" }) | ||
| export class Post4 { | ||
| @PrimaryGeneratedColumn() | ||
| id: number; | ||
|
|
||
| @Column({ enum: TestEnum2, enumName: "TestEnum", type: "enum", array: true }) | ||
| testEnum: TestEnum2[]; | ||
| } |
This file contains hidden or 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,118 @@ | ||
| import "reflect-metadata"; | ||
| import {closeTestingConnections, createTestingConnections} from "../../utils/test-utils"; | ||
| import {Post1, TestEnum1} from "./entity/Post1"; | ||
| import {Post2, TestEnum2} from "./entity/Post2"; | ||
| import {Post3} from "./entity/Post3"; | ||
| import {Post4} from "./entity/Post4"; | ||
| import {Connection} from "../../../src"; | ||
| import {expect} from "chai"; | ||
|
|
||
| describe("github issues > #4350 Array of enums column doesn't work at all", () => { | ||
| let connections: Connection[]; | ||
| afterEach(() => closeTestingConnections(connections)); | ||
| after(() => closeTestingConnections(connections)); | ||
|
|
||
| it("should migrate postgres enums correctly", async () => { | ||
TheNoim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| connections = await createTestingConnections({ | ||
| entities: [__dirname + "/entity/Post1{.js,.ts}"], | ||
| schemaCreate: true, | ||
| dropSchema: true, | ||
| enabledDrivers: ["postgres"] | ||
TheNoim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| await Promise.all(connections.map(async connection => { | ||
| let repo = connection.getRepository(Post1); | ||
|
|
||
| let post = new Post1(); | ||
| post.testEnum = [TestEnum1.VALUE1]; | ||
|
|
||
| post = await repo.save(post); | ||
|
|
||
| post.id.should.exist; | ||
| post.testEnum.should.be.an("array").that.includes(TestEnum1.VALUE1); | ||
| })); | ||
|
|
||
| await closeTestingConnections(connections); | ||
|
|
||
| connections = await createTestingConnections({ | ||
| entities: [__dirname + "/entity/Post2{.js,.ts}"], | ||
| schemaCreate: true, | ||
| dropSchema: false, | ||
| enabledDrivers: ["postgres"] | ||
| }); | ||
|
|
||
| await Promise.all(connections.map(async connection => { | ||
| let repo = connection.getRepository(Post2); | ||
|
|
||
| let post = await repo.findOne() as Post2; | ||
|
|
||
| expect(post).to.exist; | ||
| post.testEnum = [...post.testEnum, TestEnum2.VALUE2]; | ||
|
|
||
| post = await repo.save(post); | ||
|
|
||
| post.id.should.exist; | ||
| post.testEnum.should.be.an("array").that.includes(TestEnum2.VALUE1).and.that.includes(TestEnum2.VALUE2); | ||
| })); | ||
| }); | ||
|
|
||
| it('should migrate enum array to non array and back', async () => { | ||
| connections = await createTestingConnections({ | ||
| entities: [__dirname + "/entity/Post2{.js,.ts}"], | ||
| schemaCreate: true, | ||
| dropSchema: false, | ||
| enabledDrivers: ["postgres"] | ||
| }); | ||
|
|
||
| await Promise.all(connections.map(async connection => { | ||
| let repo = connection.getRepository(Post2); | ||
|
|
||
| let post = await repo.findOne() as Post2; | ||
|
|
||
| expect(post).to.exist; | ||
|
|
||
| post.id.should.exist; | ||
| post.testEnum.should.be.an("array").that.includes(TestEnum2.VALUE1).and.that.includes(TestEnum2.VALUE2); | ||
| })); | ||
|
|
||
| await closeTestingConnections(connections); | ||
|
|
||
| connections = await createTestingConnections({ | ||
| entities: [__dirname + "/entity/Post3{.js,.ts}"], | ||
| schemaCreate: true, | ||
| dropSchema: false, | ||
| enabledDrivers: ["postgres"] | ||
| }); | ||
|
|
||
| await Promise.all(connections.map(async connection => { | ||
| let repo = connection.getRepository(Post3); | ||
|
|
||
| let post = await repo.findOne() as Post3; | ||
|
|
||
| expect(post).to.exist; | ||
|
|
||
| expect(post.testEnum).to.exist; | ||
|
|
||
| post.testEnum.should.not.be.an('array'); | ||
| })); | ||
|
|
||
| await closeTestingConnections(connections); | ||
|
|
||
| connections = await createTestingConnections({ | ||
| entities: [__dirname + "/entity/Post4{.js,.ts}"], | ||
| schemaCreate: true, | ||
| dropSchema: false, | ||
| enabledDrivers: ["postgres"] | ||
| }); | ||
|
|
||
| await Promise.all(connections.map(async connection => { | ||
| let repo = connection.getRepository(Post4); | ||
|
|
||
| let post = await repo.findOne() as Post4; | ||
|
|
||
| expect(post).to.exist; | ||
|
|
||
| post.testEnum.should.be.an('array'); | ||
| })); | ||
| }) | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.