mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user