mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 15:16:01 +00:00
support for rename SQL object (mssql, postgres)
This commit is contained in:
@@ -588,6 +588,8 @@ export class SqlDumper implements AlterProcessor {
|
||||
|
||||
renameTable(obj: TableInfo, newname: string) {}
|
||||
|
||||
renameSqlObject(obj: SqlObjectInfo, newname: string) {}
|
||||
|
||||
beginTransaction() {
|
||||
this.putCmd('^begin ^transaction');
|
||||
}
|
||||
|
||||
@@ -39,6 +39,12 @@ interface AlterOperation_RenameTable {
|
||||
newName: string;
|
||||
}
|
||||
|
||||
interface AlterOperation_RenameSqlObject {
|
||||
operationType: 'renameSqlObject';
|
||||
object: SqlObjectInfo;
|
||||
newName: string;
|
||||
}
|
||||
|
||||
interface AlterOperation_CreateColumn {
|
||||
operationType: 'createColumn';
|
||||
newObject: ColumnInfo;
|
||||
@@ -120,7 +126,8 @@ type AlterOperation =
|
||||
| AlterOperation_DropSqlObject
|
||||
| AlterOperation_RecreateTable
|
||||
| AlterOperation_FillPreloadedRows
|
||||
| AlterOperation_SetTableOption;
|
||||
| AlterOperation_SetTableOption
|
||||
| AlterOperation_RenameSqlObject;
|
||||
|
||||
export class AlterPlan {
|
||||
recreates = {
|
||||
@@ -217,6 +224,14 @@ export class AlterPlan {
|
||||
});
|
||||
}
|
||||
|
||||
renameSqlObject(table: TableInfo, newName: string) {
|
||||
this.operations.push({
|
||||
operationType: 'renameSqlObject',
|
||||
object: table,
|
||||
newName,
|
||||
});
|
||||
}
|
||||
|
||||
renameColumn(column: ColumnInfo, newName: string) {
|
||||
this.operations.push({
|
||||
operationType: 'renameColumn',
|
||||
@@ -595,6 +610,9 @@ export function runAlterOperation(op: AlterOperation, processor: AlterProcessor)
|
||||
case 'renameTable':
|
||||
processor.renameTable(op.object, op.newName);
|
||||
break;
|
||||
case 'renameSqlObject':
|
||||
processor.renameSqlObject(op.object, op.newName);
|
||||
break;
|
||||
case 'renameConstraint':
|
||||
processor.renameConstraint(op.object, op.newName);
|
||||
break;
|
||||
|
||||
@@ -112,6 +112,11 @@ export class DatabaseInfoAlterProcessor {
|
||||
this.db.tables.find(x => x.pureName == table.pureName && x.schemaName == table.schemaName).pureName = newName;
|
||||
}
|
||||
|
||||
renameSqlObject(obj: SqlObjectInfo, newName: string) {
|
||||
this.db[obj.objectTypeField].find(x => x.pureName == obj.pureName && x.schemaName == obj.schemaName).pureName =
|
||||
newName;
|
||||
}
|
||||
|
||||
renameColumn(column: ColumnInfo, newName: string) {
|
||||
const table = this.db.tables.find(x => x.pureName == column.pureName && x.schemaName == column.schemaName);
|
||||
table.columns.find(x => x.columnName == column.columnName).columnName = newName;
|
||||
|
||||
@@ -583,7 +583,9 @@ export function createAlterDatabasePlan(
|
||||
}
|
||||
} else {
|
||||
if (newobj == null) {
|
||||
if (!opts.noDropSqlObject) {
|
||||
if (opts.allowSqlObjectMarkDropped) {
|
||||
plan.renameSqlObject(oldobj, '_deleted_' + oldobj.pureName);
|
||||
} else if (!opts.noDropSqlObject) {
|
||||
plan.dropSqlObject(oldobj);
|
||||
}
|
||||
} else if (!testEqualSqlObjects(oldobj.createSql, newobj.createSql, opts)) {
|
||||
|
||||
Reference in New Issue
Block a user