/
issue-4956.ts
78 lines (60 loc) · 2.63 KB
/
issue-4956.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import "reflect-metadata";
import {
closeTestingConnections,
createTestingConnections,
} from "../../utils/test-utils";
import { Connection } from "../../../src/connection/Connection";
import { afterEach } from "mocha";
import { expect } from "chai";
describe("github issues > #4956 create typeorm_metatable when running migrations.", () => {
let connections: Connection[];
afterEach(async () => {
await closeTestingConnections(connections);
});
it("should create typeorm_metadata table when running migrations with views", async () => {
connections = await createTestingConnections({
entities: [__dirname + "/entities/*{.js,.ts}"],
migrations: [__dirname + "/migrations/WithView{.js,.ts}"],
enabledDrivers: ["mysql", "mariadb"],
schemaCreate: false,
dropSchema: true,
});
await Promise.all(
connections.map(async (connection) => {
const queryRunner = connection.createQueryRunner();
const typeormMetadataTableName = "typeorm_metadata";
const hasMetadataTable = await queryRunner.hasTable(
typeormMetadataTableName
);
expect(hasMetadataTable).to.be.false;
await connection.runMigrations();
const hasPostMigrationMetadataTable =
await queryRunner.hasTable(typeormMetadataTableName);
expect(hasPostMigrationMetadataTable).to.be.true;
})
);
});
it("should not create typeorm_metadata table when running migrations if there are no views", async () => {
connections = await createTestingConnections({
entities: [__dirname + "/entities/Foo{.js,.ts}"],
migrations: [__dirname + "/migrations/WithoutView{.js,.ts}"],
enabledDrivers: ["mysql", "mariadb"],
schemaCreate: false,
dropSchema: true,
});
await Promise.all(
connections.map(async (connection) => {
const queryRunner = connection.createQueryRunner();
const typeormMetadataTableName = "typeorm_metadata";
const hasMetadataTable = await queryRunner.hasTable(
typeormMetadataTableName
);
expect(hasMetadataTable).to.be.false;
await connection.runMigrations();
const hasPostMigrationMetadataTable =
await queryRunner.hasTable(typeormMetadataTableName);
expect(hasPostMigrationMetadataTable).to.be.false;
})
);
});
});