mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 19:43:58 +00:00
alter processor tests
This commit is contained in:
@@ -19,21 +19,35 @@ function checkTableStructure(t1, t2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function testTableDiff(conn, driver, mangle) {
|
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)));
|
const structure1 = generateDbPairingId(extendDatabaseInfo(await driver.analyseFull(conn)));
|
||||||
let structure2 = _.cloneDeep(structure1);
|
let structure2 = _.cloneDeep(structure1);
|
||||||
mangle(structure2.tables[0]);
|
mangle(tget(structure2));
|
||||||
structure2 = extendDatabaseInfo(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);
|
console.log('RUNNING ALTER SQL:', sql);
|
||||||
|
|
||||||
await driver.query(conn, sql);
|
await driver.query(conn, sql);
|
||||||
|
|
||||||
const structure2Real = extendDatabaseInfo(await driver.analyseFull(conn));
|
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));
|
// expect(stableStringify(structure2)).toEqual(stableStringify(structure2Real));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,14 +64,45 @@ describe('Alter processor', () => {
|
|||||||
autoIncrement: false,
|
autoIncrement: false,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
// console.log('ENGINE', engine);
|
})
|
||||||
// for (const sql of initSql) await driver.query(conn, sql);
|
);
|
||||||
|
|
||||||
// await driver.query(conn, object.create1);
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
// const structure = await driver.analyseFull(conn);
|
'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);
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
// expect(structure[type][0]).toEqual(type.includes('views') ? view1Match : obj1Match);
|
'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)))
|
||||||
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ function getTableConstraints(table: TableInfo) {
|
|||||||
function createPairs(oldList, newList, additionalCondition = null) {
|
function createPairs(oldList, newList, additionalCondition = null) {
|
||||||
const res = [];
|
const res = [];
|
||||||
for (const a of oldList) {
|
for (const a of oldList) {
|
||||||
const b = newList.find(x => x.pairingId == a.pairingId || (additionalCondition && additionalCondition(a, b)));
|
const b = newList.find(x => x.pairingId == a.pairingId || (additionalCondition && additionalCondition(a, x)));
|
||||||
if (b) {
|
if (b) {
|
||||||
res.push([a, b]);
|
res.push([a, b]);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user