Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: custom name for typeorm_metadata table (#8528)
This new feature adds a new connection option `metadataTableName` that allows for renaming of the `typeorm_metadata` table Closes: #7266 Co-authored-by: Tadas Varanauskas <tadas@bitlocus.com>
- Loading branch information
1 parent
ece0da0
commit f8154eb
Showing
13 changed files
with
104 additions
and
5 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
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
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,12 @@ | ||
import { PrimaryGeneratedColumn, UpdateDateColumn } from "../../../../src"; | ||
|
||
import { Entity } from "../../../../src/decorator/entity/Entity"; | ||
|
||
@Entity("foo") | ||
export class Foo { | ||
@PrimaryGeneratedColumn({ name: "id" }) | ||
id: number; | ||
|
||
@UpdateDateColumn({ name: "updated_at" }) | ||
updatedAt: Date; | ||
} |
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,13 @@ | ||
import { Connection, ViewColumn, ViewEntity } from "../../../../src"; | ||
|
||
import { Foo } from "./Foo"; | ||
|
||
@ViewEntity({ | ||
name: "foo_view", | ||
expression: (connection: Connection) => | ||
connection.createQueryBuilder(Foo, "foo").select(`foo.updatedAt`), | ||
}) | ||
export class FooView { | ||
@ViewColumn() | ||
updatedAt: Date; | ||
} |
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,48 @@ | ||
import "reflect-metadata"; | ||
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { Connection } from "../../../src/connection/Connection"; | ||
import { expect } from "chai"; | ||
import { Foo } from "./entities/Foo"; | ||
import { FooView } from "./entities/FooView"; | ||
|
||
const customTypeormMetadataTableName = "custom_typeorm_metadata_table_name"; | ||
|
||
describe("github issues > #7266 rename table typeorm_metadata name.", () => { | ||
let connections: Connection[]; | ||
|
||
before(async () => connections = await createTestingConnections({ | ||
entities: [Foo, FooView], | ||
enabledDrivers: ["postgres", "mysql", "mariadb"], | ||
metadataTableName: customTypeormMetadataTableName, | ||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should create the typeorm metadata table with a custom name when provided", () => Promise.all(connections.map(async (connection) => { | ||
const queryRunner = connection.createQueryRunner(); | ||
|
||
expect(connection.metadataTableName).to.equal(customTypeormMetadataTableName); | ||
|
||
const hasCustomMetadataTableName = | ||
await queryRunner.hasTable(customTypeormMetadataTableName); | ||
|
||
expect(hasCustomMetadataTableName).to.be.true; | ||
|
||
const hasDefaultMetadataTableName = | ||
await queryRunner.hasTable("typeorm_metadata"); | ||
|
||
expect(hasDefaultMetadataTableName).to.be.false; | ||
|
||
await queryRunner.release(); | ||
}))); | ||
|
||
it("should have correct views using the custom named metadata table", () => Promise.all(connections.map(async (connection) => { | ||
const queryRunner = connection.createQueryRunner(); | ||
|
||
const fooView = await queryRunner.getView("foo_view"); | ||
|
||
expect(fooView).to.be.exist; | ||
|
||
await queryRunner.release(); | ||
}))); | ||
}); |
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