-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use full path for table lookups (#8097)
The changes made as part of #7575 fixed some issues and introduced others. The problem became that the table name would be compared against the EntityMetadata tablePath. This would fail in some cases because while the EntityMetadata would specify database, it'd be the "default"/current database & would be omitted from the table name. To work around that this PR introduces the database & schema on the table objects as well as a fully-qualified table path property which will always include all of them for comparing against EntityMetadata.
- Loading branch information
1 parent
e9366b3
commit 22676a0
Showing
5 changed files
with
211 additions
and
53 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
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,10 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from "../../../../src"; | ||
|
||
@Entity() | ||
export class Example { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
name: 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,82 @@ | ||
import "reflect-metadata"; | ||
import { Connection } from "../../../src"; | ||
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { Example } from "./entity/Example"; | ||
import { expect } from "chai"; | ||
|
||
describe("github issues > #7867 Column not renamed when schema/database is set", () => { | ||
|
||
describe('schema is set', () => { | ||
let connections: Connection[]; | ||
before(async () => { | ||
connections = await createTestingConnections({ | ||
entities: [ Example ], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
driverSpecific: { | ||
schema: "public" | ||
}, | ||
enabledDrivers: [ "postgres" ], | ||
}); | ||
}); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should correctly change column name", () => Promise.all(connections.map(async connection => { | ||
const postMetadata = connection.getMetadata(Example); | ||
const nameColumn = postMetadata.findColumnWithPropertyName("name")!; | ||
nameColumn.propertyName = "title"; | ||
nameColumn.build(connection); | ||
|
||
await connection.synchronize(); | ||
|
||
const queryRunner = connection.createQueryRunner(); | ||
const postTable = await queryRunner.getTable("example"); | ||
await queryRunner.release(); | ||
|
||
expect(postTable!.findColumnByName("name")).to.be.undefined; | ||
postTable!.findColumnByName("title")!.should.be.exist; | ||
|
||
// revert changes | ||
nameColumn.propertyName = "name"; | ||
nameColumn.build(connection); | ||
}))); | ||
}); | ||
|
||
describe('database is set', () => { | ||
let connections: Connection[]; | ||
before(async () => { | ||
connections = await createTestingConnections({ | ||
entities: [ Example ], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
driverSpecific: { | ||
database: "test" | ||
}, | ||
enabledDrivers: [ "mysql" ], | ||
}); | ||
}); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should correctly change column name", () => Promise.all(connections.map(async connection => { | ||
const postMetadata = connection.getMetadata(Example); | ||
const nameColumn = postMetadata.findColumnWithPropertyName("name")!; | ||
nameColumn.propertyName = "title"; | ||
nameColumn.build(connection); | ||
|
||
await connection.synchronize(); | ||
|
||
const queryRunner = connection.createQueryRunner(); | ||
const postTable = await queryRunner.getTable("example"); | ||
await queryRunner.release(); | ||
|
||
expect(postTable!.findColumnByName("name")).to.be.undefined; | ||
postTable!.findColumnByName("title")!.should.be.exist; | ||
|
||
// revert changes | ||
nameColumn.propertyName = "name"; | ||
nameColumn.build(connection); | ||
}))); | ||
}); | ||
}); |