mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
clickhouse + mysql: modify table option
This commit is contained in:
parent
7ad1950777
commit
fb39cd1302
@ -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(
|
||||
|
1
packages/types/alter-processor.d.ts
vendored
1
packages/types/alter-processor.d.ts
vendored
@ -15,6 +15,7 @@ export interface AlterProcessor {
|
||||
recreateTable(oldTable: TableInfo, newTable: TableInfo);
|
||||
createSqlObject(obj: SqlObjectInfo);
|
||||
dropSqlObject(obj: SqlObjectInfo);
|
||||
setTableOption(table: TableInfo, optionName: string, optionValue: string);
|
||||
fillPreloadedRows(
|
||||
table: NamedObjectInfo,
|
||||
oldRows: any[],
|
||||
|
1
packages/types/dialect.d.ts
vendored
1
packages/types/dialect.d.ts
vendored
@ -48,5 +48,6 @@ export interface SqlDialect {
|
||||
getTableFormOptions(intent: 'newTableForm' | 'editTableForm' | 'sqlCreateTable' | 'sqlAlterTable'): {
|
||||
name: string;
|
||||
sqlFormatString: string;
|
||||
disabled?: boolean;
|
||||
}[];
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
import FormArgumentList from '../forms/FormArgumentList.svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import FormProviderCore from '../forms/FormProviderCore.svelte';
|
||||
import createRef from '../utility/createRef';
|
||||
|
||||
export let title;
|
||||
export let fieldDefinitions;
|
||||
|
@ -89,6 +89,7 @@
|
||||
export let setTableInfo;
|
||||
export let dbInfo;
|
||||
export let driver;
|
||||
export let resetCounter;
|
||||
|
||||
$: isWritable = !!setTableInfo;
|
||||
|
||||
@ -161,6 +162,7 @@
|
||||
|
||||
<div class="wrapper">
|
||||
{#if tableFormOptions}
|
||||
{#key resetCounter}
|
||||
<ObjectFieldsEditor
|
||||
title="Table properties"
|
||||
fieldDefinitions={tableFormOptions}
|
||||
@ -174,6 +176,7 @@
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{/key}
|
||||
{/if}
|
||||
|
||||
<ObjectListControl
|
||||
|
@ -72,6 +72,7 @@
|
||||
let domEditor;
|
||||
|
||||
let savedName;
|
||||
let resetCounter = 0;
|
||||
|
||||
export const activator = createActivator('TableStructureTab', true);
|
||||
|
||||
@ -157,7 +158,8 @@
|
||||
|
||||
export async function reset() {
|
||||
await apiCall('database-connections/sync-model', { conid, database });
|
||||
clearEditorData();
|
||||
await clearEditorData();
|
||||
resetCounter++;
|
||||
}
|
||||
|
||||
// $: {
|
||||
@ -172,6 +174,7 @@
|
||||
tableInfo={showTable}
|
||||
dbInfo={$dbInfo}
|
||||
{driver}
|
||||
{resetCounter}
|
||||
setTableInfo={objectTypeField == 'tables' && !$connection?.isReadOnly && hasPermission(`dbops/model/edit`)
|
||||
? tableInfoUpdater =>
|
||||
setEditorData(tbl =>
|
||||
|
@ -1,6 +1,10 @@
|
||||
const { SqlDumper } = require('dbgate-tools');
|
||||
|
||||
class Dumper extends SqlDumper {
|
||||
setTableOptionCore(table, optionName, optionValue, formatString) {
|
||||
this.put('^alter ^table %f ^modify ', table);
|
||||
this.put(formatString, optionValue);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Dumper;
|
||||
|
@ -74,7 +74,7 @@ const dialect = {
|
||||
},
|
||||
|
||||
getTableFormOptions(intent) {
|
||||
const isNewTable = intent == 'newTableForm';
|
||||
const isNewTable = intent == 'newTableForm' || intent == 'sqlCreateTable';
|
||||
return [
|
||||
{
|
||||
type: isNewTable ? 'dropdowntext' : 'text',
|
||||
|
@ -105,21 +105,19 @@ const dialect = {
|
||||
},
|
||||
|
||||
getTableFormOptions(intent) {
|
||||
const isNewTable = intent == 'newTableForm';
|
||||
return [
|
||||
{
|
||||
type: isNewTable ? 'dropdowntext' : 'text',
|
||||
type: 'dropdowntext',
|
||||
options: this.getSupportedEngines(),
|
||||
label: 'Engine',
|
||||
name: 'tableEngine',
|
||||
sqlFormatString: '^engine = %s',
|
||||
disabled: !isNewTable,
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
label: 'Comment',
|
||||
name: 'objectComment',
|
||||
sqlFormatString: '^comment %v',
|
||||
sqlFormatString: '^comment = %v',
|
||||
},
|
||||
];
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user