mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
alter processor tests
This commit is contained in:
@@ -19,21 +19,35 @@ function checkTableStructure(t1, t2) {
|
||||
}
|
||||
|
||||
async function testTableDiff(conn, driver, mangle) {
|
||||
await driver.query(conn, 'create table t1 (col1 int not null)');
|
||||
await driver.query(conn, `create table t0 (id int not null primary key)`);
|
||||
|
||||
await driver.query(
|
||||
conn,
|
||||
`create table t1 (
|
||||
id int not null primary key,
|
||||
col_std int null,
|
||||
col_def int null default 12,
|
||||
col_fk int null references t0(id),
|
||||
col_idx int null
|
||||
)`
|
||||
);
|
||||
|
||||
await driver.query(conn, `create index idx1 on t1(col_idx)`);
|
||||
|
||||
const tget = x => x.tables.find(y => y.pureName == 't1');
|
||||
const structure1 = generateDbPairingId(extendDatabaseInfo(await driver.analyseFull(conn)));
|
||||
let structure2 = _.cloneDeep(structure1);
|
||||
mangle(structure2.tables[0]);
|
||||
mangle(tget(structure2));
|
||||
structure2 = extendDatabaseInfo(structure2);
|
||||
|
||||
const sql = getAlterTableScript(structure1.tables[0], structure2.tables[0], {}, structure2, driver);
|
||||
const sql = getAlterTableScript(tget(structure1), tget(structure2), {}, structure2, driver);
|
||||
console.log('RUNNING ALTER SQL:', sql);
|
||||
|
||||
await driver.query(conn, sql);
|
||||
|
||||
const structure2Real = extendDatabaseInfo(await driver.analyseFull(conn));
|
||||
|
||||
checkTableStructure(structure2Real.tables[0], structure2.tables[0]);
|
||||
checkTableStructure(tget(structure2Real), tget(structure2));
|
||||
// expect(stableStringify(structure2)).toEqual(stableStringify(structure2Real));
|
||||
}
|
||||
|
||||
@@ -50,14 +64,45 @@ describe('Alter processor', () => {
|
||||
autoIncrement: false,
|
||||
})
|
||||
);
|
||||
// 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);
|
||||
test.each(engines.map(engine => [engine.label, engine]))(
|
||||
'Drop column - %s',
|
||||
testWrapper(async (conn, driver, engine) => {
|
||||
await testTableDiff(conn, driver, tbl => (tbl.columns = tbl.columns.filter(x => x.columnName != 'col_std')));
|
||||
})
|
||||
);
|
||||
|
||||
// expect(structure[type].length).toEqual(1);
|
||||
// expect(structure[type][0]).toEqual(type.includes('views') ? view1Match : obj1Match);
|
||||
test.each(engines.map(engine => [engine.label, engine]))(
|
||||
'Drop column with default - %s',
|
||||
testWrapper(async (conn, driver, engine) => {
|
||||
await testTableDiff(conn, driver, tbl => (tbl.columns = tbl.columns.filter(x => x.columnName != 'col_def')));
|
||||
})
|
||||
);
|
||||
|
||||
test.each(engines.map(engine => [engine.label, engine]))(
|
||||
'Drop column with fk - %s',
|
||||
testWrapper(async (conn, driver, engine) => {
|
||||
await testTableDiff(conn, driver, tbl => (tbl.columns = tbl.columns.filter(x => x.columnName != 'col_fk')));
|
||||
})
|
||||
);
|
||||
|
||||
test.each(engines.map(engine => [engine.label, engine]))(
|
||||
'Drop column with index - %s',
|
||||
testWrapper(async (conn, driver, engine) => {
|
||||
await testTableDiff(conn, driver, tbl => (tbl.columns = tbl.columns.filter(x => x.columnName != 'col_idx')));
|
||||
})
|
||||
);
|
||||
|
||||
test.each(engines.map(engine => [engine.label, engine]))(
|
||||
'Change nullability - %s',
|
||||
testWrapper(async (conn, driver, engine) => {
|
||||
await testTableDiff(
|
||||
conn,
|
||||
driver,
|
||||
tbl => (tbl.columns = tbl.columns.map(x => (x.columnName == 'col_std' ? { ...x, notNull: true } : x)))
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user