CockroachDB can't recreate constraints with the same name (#15984)

* use a different constraint name whyen recreating constraints for cockroachdb

* implement cockroach specific logic in the appropriate helper

Co-authored-by: ian <licitdev@gmail.com>
This commit is contained in:
Brainslug
2022-11-14 13:21:23 +01:00
committed by GitHub
parent 32a363b803
commit 692b8c4807
3 changed files with 20 additions and 0 deletions

View File

@@ -10,4 +10,15 @@ export class SchemaHelperCockroachDb extends SchemaHelper {
): Promise<void> {
await this.changeToTypeByCopy(table, column, type, options);
}
constraintName(existingName: string): string {
const suffix = '_replaced';
// CockroachDB does not allow for dropping/creating constraints with the same
// name in a single transaction. reference issue #14873
if (existingName.endsWith(suffix)) {
return existingName.substring(0, existingName.length - suffix.length);
} else {
return existingName + suffix;
}
}
}

View File

@@ -90,4 +90,10 @@ export abstract class SchemaHelper extends DatabaseHelper {
async postColumnChange(): Promise<void> {
return;
}
constraintName(existingName: string): string {
// most vendors allow for dropping/creating constraints with the same name
// reference issue #14873
return existingName;
}
}

View File

@@ -253,6 +253,9 @@ export class RelationsService {
if (existingRelation?.schema) {
constraintName = existingRelation.schema.constraint_name || constraintName;
table.dropForeign(field, constraintName);
constraintName = this.helpers.schema.constraintName(constraintName);
existingRelation.schema.constraint_name = constraintName;
}
this.alterType(table, relation);