fix(3536): fix sync schema issue with postgres enum in case capital letters in entity name

This commit is contained in:
Vladimir Poluch 2019-02-08 19:06:55 +01:00
parent 4916a645aa
commit 0338d5eedc
4 changed files with 47 additions and 3 deletions

View File

@ -13,7 +13,8 @@ feel free to ask us and community.
* fixed "deep relations" not loaded/mapped due to the built-in max length of Postgres ([#3118](https://github.com/typeorm/typeorm/issues/3118))
* updated all dependencies
* fixed types issue from [#3725](https://github.com/typeorm/typeorm/issues/3725)
* removed sql-function-support (`() => ` syntax) in parameters to prevent security considerations
* removed sql-function-support (`() => ` syntax) in parameters to prevent security considerations
* fix sync schema issue with postgres enum in case capital letters in entity name ([#3536](https://github.com/typeorm/typeorm/issues/3536))
### Features

View File

@ -1846,12 +1846,12 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
const columnName = columnOrName instanceof TableColumn ? columnOrName.name : columnOrName;
const schema = table.name.indexOf(".") === -1 ? this.driver.options.schema : table.name.split(".")[0];
const tableName = table.name.indexOf(".") === -1 ? table.name : table.name.split(".")[1];
let enumName = schema && withSchema ? `${schema}.${tableName}_${columnName.toLowerCase()}_enum` : `${tableName}_${columnName.toLowerCase()}_enum`;
let enumName = schema && withSchema ? `${schema}.${tableName}_${columnName}_enum` : `${tableName}_${columnName}_enum`;
if (toOld)
enumName = enumName + "_old";
return enumName.split(".").map(i => {
return disableEscape ? i : `"${i}"`;
}).join(".");
}).join(".").toLowerCase();
}
/**

View File

@ -0,0 +1,18 @@
import { Entity, PrimaryGeneratedColumn, Column } from "../../../../src";
export enum AccountPermission {
Thing1 = 1,
Thing2 = 4,
Thing3 = 3,
Thing4 = 2
}
@Entity("Roles")
export class Roles {
@PrimaryGeneratedColumn()
id: string;
@Column("enum", { enum: AccountPermission, array: true, default: "{}" })
accountPermission: AccountPermission[];
}

View File

@ -0,0 +1,25 @@
import "reflect-metadata";
import { Connection } from "../../../src/connection/Connection";
import { closeTestingConnections, createTestingConnections } from "../../utils/test-utils";
import { PromiseUtils } from "../../../src";
import { Roles } from "./entity/Roles";
describe("github issues > #3536 Sync only works once for enums on entities with capital letters in entity name", () => {
let connections: Connection[];
before(async () => {
connections = await createTestingConnections({
entities: [
Roles
],
enabledDrivers: ["postgres"],
dropSchema: true,
});
});
after(() => closeTestingConnections(connections));
it("should run without throw error", () => PromiseUtils.runInSequence(connections, async connection => {
await connection.synchronize();
await connection.synchronize();
}));
});