mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 20:46:00 +00:00
clickhouse: rename & change column
This commit is contained in:
@@ -407,7 +407,7 @@ function planAlterTable(plan: AlterPlan, oldTable: TableInfo, newTable: TableInf
|
|||||||
// console.log('PLAN RENAME COLUMN')
|
// console.log('PLAN RENAME COLUMN')
|
||||||
plan.renameColumn(x[0], x[1].columnName);
|
plan.renameColumn(x[0], x[1].columnName);
|
||||||
} else {
|
} else {
|
||||||
// console.log('PLAN CHANGE COLUMN')
|
// console.log('PLAN CHANGE COLUMN', x[0], x[1]);
|
||||||
plan.changeColumn(x[0], x[1]);
|
plan.changeColumn(x[0], x[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -430,12 +430,12 @@ function planAlterTable(plan: AlterPlan, oldTable: TableInfo, newTable: TableInf
|
|||||||
}
|
}
|
||||||
|
|
||||||
function planChangeTableOptions(plan: AlterPlan, oldTable: TableInfo, newTable: TableInfo, opts: DbDiffOptions) {
|
function planChangeTableOptions(plan: AlterPlan, oldTable: TableInfo, newTable: TableInfo, opts: DbDiffOptions) {
|
||||||
for(const option of plan.dialect?.getTableFormOptions?.('sqlAlterTable') || []) {
|
for (const option of plan.dialect?.getTableFormOptions?.('sqlAlterTable') || []) {
|
||||||
if (option.disabled) {
|
if (option.disabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const name = option.name;
|
const name = option.name;
|
||||||
if (oldTable[name] != newTable[name] && (oldTable[name]||newTable[name])) {
|
if (oldTable[name] != newTable[name] && (oldTable[name] || newTable[name])) {
|
||||||
plan.setTableOption(newTable, name, newTable[name]);
|
plan.setTableOption(newTable, name, newTable[name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,24 @@ class Dumper extends SqlDumper {
|
|||||||
this.put('^alter ^table %f ^modify ', table);
|
this.put('^alter ^table %f ^modify ', table);
|
||||||
this.put(formatString, optionValue);
|
this.put(formatString, optionValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changeColumn(oldcol, newcol, constraints) {
|
||||||
|
if (oldcol.columnName != newcol.columnName) {
|
||||||
|
this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', oldcol, oldcol.columnName, newcol.columnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.put('^alter ^table %f ^modify ^column %i ', newcol, newcol.columnName);
|
||||||
|
this.columnDefinition(newcol);
|
||||||
|
this.endCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
columnType(dataType) {
|
||||||
|
this.putRaw(dataType);
|
||||||
|
}
|
||||||
|
|
||||||
|
renameColumn(column, newcol) {
|
||||||
|
this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', column, column.columnName, newcol);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Dumper;
|
module.exports = Dumper;
|
||||||
|
|||||||
@@ -50,6 +50,41 @@ const clickhouseEngines = [
|
|||||||
'DeltaLake',
|
'DeltaLake',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const clickhouseDataTypes = [
|
||||||
|
'Int8',
|
||||||
|
'Int16',
|
||||||
|
'Int32',
|
||||||
|
'Int64',
|
||||||
|
'UInt8',
|
||||||
|
'UInt16',
|
||||||
|
'UInt32',
|
||||||
|
'UInt64',
|
||||||
|
'Float32',
|
||||||
|
'Float64',
|
||||||
|
'Decimal',
|
||||||
|
'String',
|
||||||
|
'FixedString',
|
||||||
|
'UUID',
|
||||||
|
'Date',
|
||||||
|
'DateTime',
|
||||||
|
'DateTime64',
|
||||||
|
"DateTime('UTC')",
|
||||||
|
'Date32',
|
||||||
|
'Enum8',
|
||||||
|
'Enum16',
|
||||||
|
'Array',
|
||||||
|
'Tuple',
|
||||||
|
'Nullable',
|
||||||
|
'LowCardinality',
|
||||||
|
'Map',
|
||||||
|
'JSON',
|
||||||
|
'IPv4',
|
||||||
|
'IPv6',
|
||||||
|
'Nested',
|
||||||
|
'AggregateFunction',
|
||||||
|
'SimpleAggregateFunction',
|
||||||
|
];
|
||||||
|
|
||||||
/** @type {import('dbgate-types').SqlDialect} */
|
/** @type {import('dbgate-types').SqlDialect} */
|
||||||
const dialect = {
|
const dialect = {
|
||||||
limitSelect: true,
|
limitSelect: true,
|
||||||
@@ -93,6 +128,8 @@ const dialect = {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
predefinedDataTypes: clickhouseDataTypes,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @type {import('dbgate-types').EngineDriver} */
|
/** @type {import('dbgate-types').EngineDriver} */
|
||||||
|
|||||||
Reference in New Issue
Block a user