mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 17:55:59 +00:00
feat: safeCommentChanges flag to dialect
This commit is contained in:
@@ -292,6 +292,16 @@ export class AlterPlan {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_hasOnlyCommentChange(op: AlterOperation): boolean {
|
||||||
|
if (op.operationType === 'changeColumn') {
|
||||||
|
return _.isEqual(
|
||||||
|
_.omit(op.oldObject, ['columnComment', 'ordinal']),
|
||||||
|
_.omit(op.newObject, ['columnComment', 'ordinal'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
_getDependendColumnConstraints(column: ColumnInfo, dependencyDefinition) {
|
_getDependendColumnConstraints(column: ColumnInfo, dependencyDefinition) {
|
||||||
const table = this.wholeOldDb.tables.find(x => x.pureName == column.pureName && x.schemaName == column.schemaName);
|
const table = this.wholeOldDb.tables.find(x => x.pureName == column.pureName && x.schemaName == column.schemaName);
|
||||||
if (!table) return [];
|
if (!table) return [];
|
||||||
@@ -337,31 +347,42 @@ export class AlterPlan {
|
|||||||
]) {
|
]) {
|
||||||
if (op.operationType == testedOperationType) {
|
if (op.operationType == testedOperationType) {
|
||||||
const constraints = this._getDependendColumnConstraints(testedObject as ColumnInfo, testedDependencies);
|
const constraints = this._getDependendColumnConstraints(testedObject as ColumnInfo, testedDependencies);
|
||||||
|
const ignoreContraints = this.dialect.safeCommentChanges && this._hasOnlyCommentChange(op);
|
||||||
|
|
||||||
// if (constraints.length > 0 && this.opts.noDropConstraint) {
|
// if (constraints.length > 0 && this.opts.noDropConstraint) {
|
||||||
// return [];
|
// return [];
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const res: AlterOperation[] = [
|
const res: AlterOperation[] = [];
|
||||||
...constraints.map(oldObject => {
|
|
||||||
const opRes: AlterOperation = {
|
|
||||||
operationType: 'dropConstraint',
|
|
||||||
oldObject,
|
|
||||||
isRecreate: true,
|
|
||||||
};
|
|
||||||
return opRes;
|
|
||||||
}),
|
|
||||||
op,
|
|
||||||
..._.reverse([...constraints]).map(newObject => {
|
|
||||||
const opRes: AlterOperation = {
|
|
||||||
operationType: 'createConstraint',
|
|
||||||
newObject,
|
|
||||||
};
|
|
||||||
return opRes;
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
|
|
||||||
if (constraints.length > 0) {
|
if (!ignoreContraints) {
|
||||||
|
res.push(
|
||||||
|
...constraints.map(oldObject => {
|
||||||
|
const opRes: AlterOperation = {
|
||||||
|
operationType: 'dropConstraint',
|
||||||
|
oldObject,
|
||||||
|
isRecreate: true,
|
||||||
|
};
|
||||||
|
return opRes;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.push(op);
|
||||||
|
|
||||||
|
if (!ignoreContraints) {
|
||||||
|
res.push(
|
||||||
|
..._.reverse([...constraints]).map(newObject => {
|
||||||
|
const opRes: AlterOperation = {
|
||||||
|
operationType: 'createConstraint',
|
||||||
|
newObject,
|
||||||
|
};
|
||||||
|
return opRes;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ignoreContraints && constraints.length > 0) {
|
||||||
this.recreates.constraints += 1;
|
this.recreates.constraints += 1;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
2
packages/types/dialect.d.ts
vendored
2
packages/types/dialect.d.ts
vendored
@@ -80,6 +80,8 @@ export interface SqlDialect {
|
|||||||
isPersisted?: true;
|
isPersisted?: true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
safeCommentChanges?: boolean;
|
||||||
|
|
||||||
// create sql-tree expression
|
// create sql-tree expression
|
||||||
createColumnViewExpression(
|
createColumnViewExpression(
|
||||||
columnName: string,
|
columnName: string,
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ const dialect = {
|
|||||||
isPersisted: true,
|
isPersisted: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
safeCommentChanges: true,
|
||||||
|
|
||||||
predefinedDataTypes: [
|
predefinedDataTypes: [
|
||||||
'bigint',
|
'bigint',
|
||||||
'bit',
|
'bit',
|
||||||
|
|||||||
Reference in New Issue
Block a user