2021-06-28 06:00:28 +00:00
|
|
|
const stableStringify = require('json-stable-stringify');
|
|
|
|
const _ = require('lodash');
|
2021-06-27 18:44:02 +00:00
|
|
|
const uuidv1 = require('uuid/v1');
|
|
|
|
const { testWrapper } = require('../tools');
|
2021-06-28 06:00:28 +00:00
|
|
|
const engines = require('../engines');
|
|
|
|
const { getAlterTableScript, extendDatabaseInfo } = require('dbgate-tools');
|
2021-06-27 18:44:02 +00:00
|
|
|
|
|
|
|
async function testTableDiff(conn, driver, mangle) {
|
|
|
|
await driver.query(conn, 'create table t1 (col1 int not null)');
|
|
|
|
|
2021-06-28 06:00:28 +00:00
|
|
|
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));
|
2021-06-27 18:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('Alter processor', () => {
|
|
|
|
test.each(engines.map(engine => [engine.label, engine]))(
|
|
|
|
'Add column - %s',
|
|
|
|
testWrapper(async (conn, driver, engine) => {
|
2021-06-28 06:00:28 +00:00
|
|
|
await testTableDiff(conn, driver, tbl =>
|
2021-06-27 18:44:02 +00:00
|
|
|
tbl.columns.push({
|
|
|
|
columnName: 'added',
|
|
|
|
dataType: 'int',
|
|
|
|
pairingId: uuidv1(),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
// console.log('ENGINE', engine);
|
|
|
|
// for (const sql of initSql) await driver.query(conn, sql);
|
|
|
|
|
|
|
|
// await driver.query(conn, object.create1);
|
|
|
|
// const structure = await driver.analyseFull(conn);
|
|
|
|
|
|
|
|
// expect(structure[type].length).toEqual(1);
|
|
|
|
// expect(structure[type][0]).toEqual(type.includes('views') ? view1Match : obj1Match);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|