-
-
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: get length attribute of postgres array columns (#7239)
Change loadTables in PostgresQueryRunner to use pg_catalog to find length attribute of array columns. Previously, it relied on information_schema.columns character_maximum_length, which is null for array columns. This caused synchronize to always drop and recreate array columns. Closes: #6990
- Loading branch information
Showing
3 changed files
with
92 additions
and
7 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,15 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from "../../../../src"; | ||
|
||
@Entity() | ||
export class Foo { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column({ | ||
array: true, | ||
type: "varchar", | ||
length: 64, | ||
nullable: true, | ||
}) | ||
varchararray: 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,46 @@ | ||
import "reflect-metadata"; | ||
import { | ||
closeTestingConnections, | ||
createTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils"; | ||
import { Connection } from "../../../src/connection/Connection"; | ||
import { Foo } from "./entity/foo"; | ||
import { expect } from "chai"; | ||
|
||
describe("github issues > #6990 synchronize drops array columns in postgres if a length is set", () => { | ||
let connections: Connection[]; | ||
before( | ||
async () => | ||
(connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
subscribers: [__dirname + "/subscriber/*{.js,.ts}"], | ||
enabledDrivers: ["postgres"], | ||
})) | ||
); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should not drop varchar array column on synchronize using postgres driver", () => | ||
Promise.all( | ||
connections.map(async function (connection) { | ||
const foo = new Foo(); | ||
foo.id = 1; | ||
foo.varchararray = ["able", "baker", "charlie"]; | ||
await connection.manager.save(foo); | ||
|
||
await connection.synchronize(); | ||
|
||
const loadedFoo: | ||
| Foo | ||
| undefined = await connection.manager.findOne(Foo, 1); | ||
|
||
expect(loadedFoo).to.be.not.empty; | ||
expect(loadedFoo!.varchararray).to.deep.eq([ | ||
"able", | ||
"baker", | ||
"charlie", | ||
]); | ||
}) | ||
)); | ||
}); |