mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 12:13:57 +00:00
create column test
This commit is contained in:
parent
67a793038b
commit
4c1ac0757c
@ -1,19 +1,33 @@
|
||||
const engines = require('../engines');
|
||||
const stableStringify = require('json-stable-stringify');
|
||||
const _ = require('lodash');
|
||||
const uuidv1 = require('uuid/v1');
|
||||
const { testWrapper } = require('../tools');
|
||||
const engines = require('../engines');
|
||||
const { getAlterTableScript, extendDatabaseInfo } = require('dbgate-tools');
|
||||
|
||||
async function testTableDiff(conn, driver, mangle) {
|
||||
await driver.query(conn, 'create table t1 (col1 int not null)');
|
||||
|
||||
const structure1 = await driver.analyseFull(conn);
|
||||
mangle(structure1.tables[0]);
|
||||
const structure1 = extendDatabaseInfo(await driver.analyseFull(conn));
|
||||
let structure2 = _.cloneDeep(structure1);
|
||||
mangle(structure2.tables[0]);
|
||||
structure2 = extendDatabaseInfo(structure2);
|
||||
|
||||
const sql = getAlterTableScript(structure1.tables[0], structure2.tables[0], {}, structure2, driver);
|
||||
console.log('RUNNING ALTER SQL:', sql);
|
||||
|
||||
await driver.query(conn, sql);
|
||||
|
||||
const structure2Real = extendDatabaseInfo(await driver.analyseFull(conn));
|
||||
|
||||
expect(stableStringify(structure2)).toEqual(stableStringify(structure2Real));
|
||||
}
|
||||
|
||||
describe('Alter processor', () => {
|
||||
test.each(engines.map(engine => [engine.label, engine]))(
|
||||
'Add column - %s',
|
||||
testWrapper(async (conn, driver, engine) => {
|
||||
testTableDiff(conn, driver, tbl =>
|
||||
await testTableDiff(conn, driver, tbl =>
|
||||
tbl.columns.push({
|
||||
columnName: 'added',
|
||||
dataType: 'int',
|
||||
|
@ -158,6 +158,12 @@ export class AlterPlan {
|
||||
newName,
|
||||
});
|
||||
}
|
||||
|
||||
run(processor: AlterProcessor) {
|
||||
for (const op of this.operations) {
|
||||
runAlterOperation(op, processor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function runAlterOperation(op: AlterOperation, processor: AlterProcessor) {
|
||||
|
@ -281,4 +281,7 @@ export function getAlterTableScript(
|
||||
driver: EngineDriver
|
||||
): string {
|
||||
const plan = createAlterTablePlan(oldTable, newTable, opts, db);
|
||||
const dmp = driver.createDumper();
|
||||
plan.run(dmp);
|
||||
return dmp.s;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user