From 487ceb4c73ee5cc3f4e4b5d357fce77042dbaa66 Mon Sep 17 00:00:00 2001 From: Matthijs Hatzmann Date: Wed, 12 Jan 2022 15:24:20 +0100 Subject: [PATCH] feat: add constraintName to JoinColumn Add a constraintName to JoinColumn decorators to allow specifying foreignKey name. Use constraintName when building JoinTable entities as well. Partially solves: #1355 --- .../JunctionEntityMetadataBuilder.ts | 13 ++++++------- src/metadata/ColumnMetadata.ts | 5 +++++ src/metadata/ForeignKeyMetadata.ts | 5 +++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/metadata-builder/JunctionEntityMetadataBuilder.ts b/src/metadata-builder/JunctionEntityMetadataBuilder.ts index 240de46127..f5785d77a4 100644 --- a/src/metadata-builder/JunctionEntityMetadataBuilder.ts +++ b/src/metadata-builder/JunctionEntityMetadataBuilder.ts @@ -160,11 +160,10 @@ export class JunctionEntityMetadataBuilder { options: { length: !inverseReferencedColumn.length && - (DriverUtils.isMySQLFamily( - this.connection.driver, - ) || - this.connection.driver.options.type === - "aurora-mysql") && + (this.connection.driver instanceof + MysqlDriver || + this.connection.driver instanceof + AuroraDataApiDriver) && (inverseReferencedColumn.generationStrategy === "uuid" || inverseReferencedColumn.type === "uuid") @@ -219,7 +218,7 @@ export class JunctionEntityMetadataBuilder { referencedColumns: referencedColumns, onDelete: relation.onDelete || "CASCADE", onUpdate: - this.connection.driver.options.type === "oracle" + this.connection.driver instanceof OracleDriver ? "NO ACTION" : relation.onUpdate || "CASCADE", }), @@ -233,7 +232,7 @@ export class JunctionEntityMetadataBuilder { ? relation.inverseRelation.onDelete : "CASCADE", onUpdate: - this.connection.driver.options.type === "oracle" + this.connection.driver instanceof OracleDriver ? "NO ACTION" : relation.inverseRelation ? relation.inverseRelation.onUpdate diff --git a/src/metadata/ColumnMetadata.ts b/src/metadata/ColumnMetadata.ts index 14a414b829..1d2ce8aa1f 100644 --- a/src/metadata/ColumnMetadata.ts +++ b/src/metadata/ColumnMetadata.ts @@ -284,6 +284,11 @@ export class ColumnMetadata { */ constraintName?: string + /** + * If this column is foreign key then this specifies the name for it. + */ + constraintName?: string + /** * Specifies a value transformer that is to be used to (un)marshal * this column when reading or writing to the database. diff --git a/src/metadata/ForeignKeyMetadata.ts b/src/metadata/ForeignKeyMetadata.ts index 7f380e0d81..5cd587363e 100644 --- a/src/metadata/ForeignKeyMetadata.ts +++ b/src/metadata/ForeignKeyMetadata.ts @@ -75,6 +75,11 @@ export class ForeignKeyMetadata { */ givenName?: string + /** + * User specified unique constraint name. + */ + givenName?: string + // --------------------------------------------------------------------- // Constructor // ---------------------------------------------------------------------