forked from typeorm/typeorm
/
issue-6442.ts
67 lines (58 loc) · 2.77 KB
/
issue-6442.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
import "reflect-metadata";
import {
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases,
setupSingleTestingConnection
} from "../../utils/test-utils";
import { Connection, createConnection } from "../../../src";
import { fail } from "assert";
import { Query } from "../../../src/driver/Query";
import { MysqlConnectionOptions } from "../../../src/driver/mysql/MysqlConnectionOptions";
describe("github issues > #6442 JoinTable does not respect inverseJoinColumns referenced column width", () => {
let connections: Connection[];
before(async () => {
return connections = await createTestingConnections({
entities: [__dirname + "/entity/v1/*{.js,.ts}"],
schemaCreate: true,
dropSchema: true,
enabledDrivers: ["mysql"]
});
});
beforeEach(async () => await reloadTestingDatabases(connections));
after(async () => await closeTestingConnections(connections));
it("should generate column widths equal to the referenced column widths", async () => {
await Promise.all(connections.map(async (connection) => {
const options = setupSingleTestingConnection(
connection.options.type,
{
name: `${connection.name}-v2`,
entities: [__dirname + "/entity/v2/*{.js,.ts}"],
dropSchema: false,
schemaCreate: false
}
) as MysqlConnectionOptions;
if (!options) {
await connection.close();
fail();
}
const migrationConnection = await createConnection(options);
try {
const sqlInMemory = await migrationConnection.driver
.createSchemaBuilder()
.log();
const upQueries = sqlInMemory.upQueries.map(
(query: Query) => query.query
);
upQueries.should.eql([
"CREATE TABLE `foo_bars` (`foo_id` int(10) UNSIGNED NOT NULL, `bar_id` int(10) UNSIGNED NOT NULL, INDEX `IDX_319290776f044043e3ef3ba5a8` (`foo_id`), INDEX `IDX_b7fd4be386fa7cdb87ef8b12b6` (`bar_id`), PRIMARY KEY (`foo_id`, `bar_id`)) ENGINE=InnoDB",
"ALTER TABLE `foo_bars` ADD CONSTRAINT `FK_319290776f044043e3ef3ba5a8d` FOREIGN KEY (`foo_id`) REFERENCES `foo_entity`(`id`) ON DELETE CASCADE ON UPDATE NO ACTION",
"ALTER TABLE `foo_bars` ADD CONSTRAINT `FK_b7fd4be386fa7cdb87ef8b12b69` FOREIGN KEY (`bar_id`) REFERENCES `bar_entity`(`id`) ON DELETE CASCADE ON UPDATE NO ACTION"
]);
} finally {
await connection.close();
await migrationConnection.close();
}
}));
});
});