mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 11:45:59 +00:00
edit constraint (with recreate)
This commit is contained in:
@@ -259,6 +259,18 @@ export class AlterPlan {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (op.operationType == 'changeConstraint') {
|
||||||
|
const opDrop: AlterOperation = {
|
||||||
|
operationType: 'dropConstraint',
|
||||||
|
oldObject: op.oldObject,
|
||||||
|
};
|
||||||
|
const opCreate: AlterOperation = {
|
||||||
|
operationType: 'createConstraint',
|
||||||
|
newObject: op.newObject,
|
||||||
|
};
|
||||||
|
return [opDrop, opCreate];
|
||||||
|
}
|
||||||
|
|
||||||
return [op];
|
return [op];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ColumnInfo, DatabaseInfo, EngineDriver, NamedObjectInfo, TableInfo } from 'dbgate-types';
|
import { ColumnInfo, ConstraintInfo, DatabaseInfo, EngineDriver, NamedObjectInfo, TableInfo } from 'dbgate-types';
|
||||||
import uuidv1 from 'uuid/v1';
|
import uuidv1 from 'uuid/v1';
|
||||||
import { AlterPlan } from './alterPlan';
|
import { AlterPlan } from './alterPlan';
|
||||||
|
import stableStringify from 'json-stable-stringify';
|
||||||
|
|
||||||
type DbDiffSchemaMode = 'strict' | 'ignore' | 'ignoreImplicit';
|
type DbDiffSchemaMode = 'strict' | 'ignore' | 'ignoreImplicit';
|
||||||
|
|
||||||
@@ -178,6 +179,10 @@ export function testEqualColumns(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testEqualConstraints(a: ConstraintInfo, b: ConstraintInfo, opts: DbDiffOptions = {}) {
|
||||||
|
return stableStringify(a) == stableStringify(b);
|
||||||
|
}
|
||||||
|
|
||||||
export function testEqualTypes(a: ColumnInfo, b: ColumnInfo, opts: DbDiffOptions = {}) {
|
export function testEqualTypes(a: ColumnInfo, b: ColumnInfo, opts: DbDiffOptions = {}) {
|
||||||
if (a.dataType != b.dataType) {
|
if (a.dataType != b.dataType) {
|
||||||
// opts.DiffLogger.Trace("Column {0}, {1}: different types: {2}; {3}", a, b, a.DataType, b.DataType);
|
// opts.DiffLogger.Trace("Column {0}, {1}: different types: {2}; {3}", a, b, a.DataType, b.DataType);
|
||||||
@@ -210,6 +215,7 @@ function getTableConstraints(table: TableInfo) {
|
|||||||
if (table.primaryKey) res.push(table.primaryKey);
|
if (table.primaryKey) res.push(table.primaryKey);
|
||||||
if (table.foreignKeys) res.push(...table.foreignKeys);
|
if (table.foreignKeys) res.push(...table.foreignKeys);
|
||||||
if (table.indexes) res.push(...table.indexes);
|
if (table.indexes) res.push(...table.indexes);
|
||||||
|
if (table.uniques) res.push(...table.uniques);
|
||||||
if (table.checks) res.push(...table.checks);
|
if (table.checks) res.push(...table.checks);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -265,6 +271,15 @@ function planAlterTable(plan: AlterPlan, oldTable: TableInfo, newTable: TableInf
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
constraintPairs
|
||||||
|
.filter(x => x[0] && x[1])
|
||||||
|
.forEach(x => {
|
||||||
|
if (!testEqualConstraints(x[0], x[1], opts)) {
|
||||||
|
// console.log('PLAN CHANGE COLUMN')
|
||||||
|
plan.changeConstraint(x[0], x[1]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
constraintPairs.filter(x => x[0] == null).forEach(x => plan.createConstraint(x[1]));
|
constraintPairs.filter(x => x[0] == null).forEach(x => plan.createConstraint(x[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user