mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 21:56:00 +00:00
rename column works
This commit is contained in:
@@ -41,7 +41,7 @@ async function testTableDiff(conn, driver, mangle) {
|
||||
structure2 = extendDatabaseInfo(structure2);
|
||||
|
||||
const sql = getAlterTableScript(tget(structure1), tget(structure2), {}, structure2, driver);
|
||||
console.log('RUNNING ALTER SQL:', sql);
|
||||
console.log('RUNNING ALTER SQL', driver.engine, ':', sql);
|
||||
|
||||
await driver.query(conn, sql);
|
||||
|
||||
@@ -51,10 +51,11 @@ async function testTableDiff(conn, driver, mangle) {
|
||||
// expect(stableStringify(structure2)).toEqual(stableStringify(structure2Real));
|
||||
}
|
||||
|
||||
// const TESTED_COLUMNS = ['col_std', 'col_def', 'col_fk', 'col_idx'];
|
||||
const TESTED_COLUMNS = ['col_std'];
|
||||
|
||||
function engines_columns_source() {
|
||||
return _.flatten(
|
||||
engines.map(engine => ['col_std', 'col_def', 'col_fk', 'col_idx'].map(column => [engine.label, column, engine]))
|
||||
);
|
||||
return _.flatten(engines.map(engine => TESTED_COLUMNS.map(column => [engine.label, column, engine])));
|
||||
}
|
||||
|
||||
describe('Alter processor', () => {
|
||||
@@ -92,7 +93,7 @@ describe('Alter processor', () => {
|
||||
);
|
||||
|
||||
test.each(engines_columns_source())(
|
||||
'Rename column - %s',
|
||||
'Rename column - %s - %s',
|
||||
testWrapper(async (conn, driver, column, engine) => {
|
||||
await testTableDiff(
|
||||
conn,
|
||||
|
||||
@@ -189,5 +189,14 @@ export function runAlterOperation(op: AlterOperation, processor: AlterProcessor)
|
||||
case 'dropConstraint':
|
||||
processor.dropConstraint(op.oldObject);
|
||||
break;
|
||||
case 'renameColumn':
|
||||
processor.renameColumn(op.object, op.newName);
|
||||
break;
|
||||
case 'renameTable':
|
||||
processor.renameTable(op.object, op.newName);
|
||||
break;
|
||||
case 'renameConstraint':
|
||||
processor.renameConstraint(op.object, op.newName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,9 +255,11 @@ function planAlterTable(plan: AlterPlan, oldTable: TableInfo, newTable: TableInf
|
||||
.filter(x => x[0] && x[1])
|
||||
.forEach(x => {
|
||||
if (!testEqualsColumns(x[0], x[1], true, true, opts)) {
|
||||
if (!testEqualsColumns(x[0], x[1], false, true, opts)) {
|
||||
if (testEqualsColumns(x[0], x[1], false, true, opts)) {
|
||||
// console.log('PLAN RENAME COLUMN')
|
||||
plan.renameColumn(x[0], x[1].columnName);
|
||||
} else {
|
||||
// console.log('PLAN CHANGE COLUMN')
|
||||
plan.changeColumn(x[0], x[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
const { SqlDumper } = global.DBGATE_TOOLS;
|
||||
|
||||
class Dumper extends SqlDumper {}
|
||||
class Dumper extends SqlDumper {
|
||||
renameColumn(column, newcol) {
|
||||
this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', column, column.columnName, newcol);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Dumper;
|
||||
|
||||
Reference in New Issue
Block a user