Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide width to ColumnMetadataArgs for JoinTable
fix: @jointable does not respect inverseJoinColumns referenced column width Closes: #6442
- Loading branch information
1 parent
9abab82
commit be097d7
Showing
4 changed files
with
119 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { PrimaryColumn, Generated, Column, Entity } from "../../../../../src"; | ||
|
||
@Entity() | ||
export class FooEntity { | ||
@PrimaryColumn({ type: "int", width: 10, unsigned: true, nullable: false }) | ||
@Generated() | ||
public id: number; | ||
} | ||
|
||
@Entity() | ||
export class BarEntity { | ||
@PrimaryColumn({ type: "int", width: 10, unsigned: true }) | ||
@Generated() | ||
public id: number; | ||
|
||
@Column("varchar", { nullable: false, length: 50 }) | ||
public code: 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,34 @@ | ||
import { PrimaryColumn, Generated, ManyToMany, Entity, Column, JoinTable } from "../../../../../src"; | ||
|
||
@Entity() | ||
export class FooEntity { | ||
@PrimaryColumn({ type: "int", width: 10, unsigned: true, nullable: false }) | ||
@Generated() | ||
public id: number; | ||
|
||
@ManyToMany(() => BarEntity) | ||
@JoinTable({ | ||
name: "foo_bars", | ||
joinColumns: [ | ||
{ | ||
name: "foo_id", | ||
} | ||
], | ||
inverseJoinColumns: [ | ||
{ | ||
name: "bar_id", | ||
} | ||
] | ||
}) | ||
public fooBars: BarEntity[]; | ||
} | ||
|
||
@Entity() | ||
export class BarEntity { | ||
@PrimaryColumn({ type: "int", width: 10, unsigned: true }) | ||
@Generated() | ||
public id: number; | ||
|
||
@Column("varchar", { nullable: false, length: 50 }) | ||
public code: 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,66 @@ | ||
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 > #6642 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(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should generate a drop and create step", async () => { | ||
return Promise.all( | ||
connections.map(async function (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) { | ||
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 { | ||
connection.close(); | ||
} | ||
}) | ||
); | ||
}); | ||
}); |