editing table works

This commit is contained in:
Jan Prochazka
2024-09-11 09:16:08 +02:00
parent 15c400747e
commit ae9ffe1aef
6 changed files with 64 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
const { driverBase } = require('dbgate-tools');
const Dumper = require('./Dumper');
const { mysqlSplitterOptions } = require('dbgate-query-splitter/lib/options');
const _cloneDeepWith = require('lodash/cloneDeepWith');
/** @type {import('dbgate-types').SqlDialect} */
const dialect = {
@@ -40,6 +41,35 @@ const driver = {
usage == 'editor'
? { ...mysqlSplitterOptions, ignoreComments: true, preventSingleLineSplit: true }
: mysqlSplitterOptions,
createSaveChangeSetScript(changeSet, dbinfo, defaultCreator) {
function removeConditionSource(cmd) {
cmd.where = _cloneDeepWith(cmd.where, (expr) => {
if (expr.exprType == 'column') {
return {
...expr,
source: undefined,
};
}
});
}
const res = defaultCreator(changeSet, dbinfo);
for (const cmd of res) {
if (cmd.commandType == 'update') {
cmd.alterTableUpdateSyntax = true;
removeConditionSource(cmd);
}
if (cmd.commandType == 'delete') {
const table = dbinfo?.tables?.find((x) => x.pureName == cmd?.from?.name?.pureName);
if (table?.tableEngine != 'MergeTree') {
cmd.alterTableDeleteSyntax = true;
}
removeConditionSource(cmd);
}
}
return res;
},
};
module.exports = driver;