mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 12:46:00 +00:00
clickhouse + mysql: modify table option
This commit is contained in:
@@ -304,7 +304,7 @@ export class SqlDumper implements AlterProcessor {
|
||||
}
|
||||
|
||||
tableOptions(table: TableInfo) {
|
||||
const options = this.driver.getTableFormOptions('sqlCreateTable');
|
||||
const options = this.driver?.dialect?.getTableFormOptions?.('sqlCreateTable') || [];
|
||||
for (const option of options) {
|
||||
if (table[option.name]) {
|
||||
this.put('&n');
|
||||
@@ -686,6 +686,23 @@ export class SqlDumper implements AlterProcessor {
|
||||
this.putCmd('^drop %s %f', this.getSqlObjectSqlName(obj.objectTypeField), obj);
|
||||
}
|
||||
|
||||
setTableOption(table: TableInfo, optionName: string, optionValue: string) {
|
||||
const options = this?.dialect?.getTableFormOptions?.('sqlAlterTable');
|
||||
const option = options?.find(x => x.name == optionName && !x.disabled);
|
||||
if (!option) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setTableOptionCore(table, optionName, optionValue, option.sqlFormatString);
|
||||
|
||||
this.endCommand();
|
||||
}
|
||||
|
||||
setTableOptionCore(table: TableInfo, optionName: string, optionValue: string, formatString: string) {
|
||||
this.put('^alter ^table %f ', table);
|
||||
this.put(formatString, optionValue);
|
||||
}
|
||||
|
||||
fillPreloadedRows(
|
||||
table: NamedObjectInfo,
|
||||
oldRows: any[],
|
||||
|
||||
@@ -97,6 +97,13 @@ interface AlterOperation_FillPreloadedRows {
|
||||
autoIncrementColumn: string;
|
||||
}
|
||||
|
||||
interface AlterOperation_SetTableOption {
|
||||
operationType: 'setTableOption';
|
||||
table: TableInfo;
|
||||
optionName: string;
|
||||
optionValue: string;
|
||||
}
|
||||
|
||||
type AlterOperation =
|
||||
| AlterOperation_CreateColumn
|
||||
| AlterOperation_ChangeColumn
|
||||
@@ -112,7 +119,8 @@ type AlterOperation =
|
||||
| AlterOperation_CreateSqlObject
|
||||
| AlterOperation_DropSqlObject
|
||||
| AlterOperation_RecreateTable
|
||||
| AlterOperation_FillPreloadedRows;
|
||||
| AlterOperation_FillPreloadedRows
|
||||
| AlterOperation_SetTableOption;
|
||||
|
||||
export class AlterPlan {
|
||||
recreates = {
|
||||
@@ -253,6 +261,15 @@ export class AlterPlan {
|
||||
});
|
||||
}
|
||||
|
||||
setTableOption(table: TableInfo, optionName: string, optionValue: string) {
|
||||
this.operations.push({
|
||||
operationType: 'setTableOption',
|
||||
table,
|
||||
optionName,
|
||||
optionValue,
|
||||
});
|
||||
}
|
||||
|
||||
run(processor: AlterProcessor) {
|
||||
for (const op of this.operations) {
|
||||
runAlterOperation(op, processor);
|
||||
@@ -575,6 +592,9 @@ export function runAlterOperation(op: AlterOperation, processor: AlterProcessor)
|
||||
case 'dropSqlObject':
|
||||
processor.dropSqlObject(op.oldObject);
|
||||
break;
|
||||
case 'setTableOption':
|
||||
processor.setTableOption(op.table, op.optionName, op.optionValue);
|
||||
break;
|
||||
case 'fillPreloadedRows':
|
||||
processor.fillPreloadedRows(op.table, op.oldRows, op.newRows, op.key, op.insertOnly, op.autoIncrementColumn);
|
||||
break;
|
||||
|
||||
@@ -129,4 +129,9 @@ export class DatabaseInfoAlterProcessor {
|
||||
tableInfo.preloadedRowsKey = key;
|
||||
tableInfo.preloadedRowsInsertOnly = insertOnly;
|
||||
}
|
||||
|
||||
setTableOption(table: TableInfo, optionName: string, optionValue: string) {
|
||||
const tableInfo = this.db.tables.find(x => x.pureName == table.pureName && x.schemaName == table.schemaName);
|
||||
tableInfo[optionName] = optionValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,6 +425,20 @@ function planAlterTable(plan: AlterPlan, oldTable: TableInfo, newTable: TableInf
|
||||
constraintPairs.filter(x => x[0] == null).forEach(x => plan.createConstraint(x[1]));
|
||||
|
||||
planTablePreload(plan, oldTable, newTable);
|
||||
|
||||
planChangeTableOptions(plan, oldTable, newTable, opts);
|
||||
}
|
||||
|
||||
function planChangeTableOptions(plan: AlterPlan, oldTable: TableInfo, newTable: TableInfo, opts: DbDiffOptions) {
|
||||
for(const option of plan.dialect?.getTableFormOptions?.('sqlAlterTable') || []) {
|
||||
if (option.disabled) {
|
||||
continue;
|
||||
}
|
||||
const name = option.name;
|
||||
if (oldTable[name] != newTable[name] && (oldTable[name]||newTable[name])) {
|
||||
plan.setTableOption(newTable, name, newTable[name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function testEqualTables(
|
||||
|
||||
Reference in New Issue
Block a user