mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 17:36:01 +00:00
incremental analysis in alter table tests
This commit is contained in:
@@ -25,6 +25,13 @@ function pickImportantTableInfo(engine, table) {
|
|||||||
.map(props =>
|
.map(props =>
|
||||||
_.omitBy(props, (v, k) => k == 'defaultValue' && v == 'NULL' && engine.setNullDefaultInsteadOfDrop)
|
_.omitBy(props, (v, k) => k == 'defaultValue' && v == 'NULL' && engine.setNullDefaultInsteadOfDrop)
|
||||||
),
|
),
|
||||||
|
foreignKeys: table.foreignKeys
|
||||||
|
.sort((a, b) => a.refTableName.localeCompare(b.refTableName))
|
||||||
|
.map(fk => ({
|
||||||
|
constraintType: fk.constraintType,
|
||||||
|
refTableName: fk.refTableName,
|
||||||
|
columns: fk.columns.map(col => ({ columnName: col.columnName, refColumnName: col.refColumnName })),
|
||||||
|
})),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +40,7 @@ function checkTableStructure(engine, t1, t2) {
|
|||||||
expect(pickImportantTableInfo(engine, t1)).toEqual(pickImportantTableInfo(engine, t2));
|
expect(pickImportantTableInfo(engine, t1)).toEqual(pickImportantTableInfo(engine, t2));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testTableDiff(engine, conn, driver, mangle) {
|
async function testTableDiff(engine, conn, driver, mangle, changedTable = 't1') {
|
||||||
const initQuery = formatQueryWithoutParams(driver, `create table ~t0 (~id int not null primary key)`);
|
const initQuery = formatQueryWithoutParams(driver, `create table ~t0 (~id int not null primary key)`);
|
||||||
await driver.query(conn, transformSqlForEngine(engine, initQuery));
|
await driver.query(conn, transformSqlForEngine(engine, initQuery));
|
||||||
|
|
||||||
@@ -68,8 +75,20 @@ async function testTableDiff(engine, conn, driver, mangle) {
|
|||||||
await driver.query(conn, transformSqlForEngine(engine, query));
|
await driver.query(conn, transformSqlForEngine(engine, query));
|
||||||
}
|
}
|
||||||
|
|
||||||
const tget = x => x.tables.find(y => y.pureName == 't1');
|
if (!engine.skipReferences) {
|
||||||
const structure1 = generateDbPairingId(extendDatabaseInfo(await driver.analyseFull(conn)));
|
const query = formatQueryWithoutParams(
|
||||||
|
driver,
|
||||||
|
`create table ~t3 (~id int not null primary key, ~fkval int ${
|
||||||
|
driver.dialect.implicitNullDeclaration ? '' : 'null'
|
||||||
|
})`
|
||||||
|
);
|
||||||
|
|
||||||
|
await driver.query(conn, transformSqlForEngine(engine, query));
|
||||||
|
}
|
||||||
|
|
||||||
|
const tget = x => x.tables.find(y => y.pureName == changedTable);
|
||||||
|
const structure1Source = await driver.analyseFull(conn);
|
||||||
|
const structure1 = generateDbPairingId(extendDatabaseInfo(structure1Source));
|
||||||
let structure2 = _.cloneDeep(structure1);
|
let structure2 = _.cloneDeep(structure1);
|
||||||
mangle(tget(structure2));
|
mangle(tget(structure2));
|
||||||
structure2 = extendDatabaseInfo(structure2);
|
structure2 = extendDatabaseInfo(structure2);
|
||||||
@@ -79,6 +98,11 @@ async function testTableDiff(engine, conn, driver, mangle) {
|
|||||||
|
|
||||||
await driver.script(conn, sql);
|
await driver.script(conn, sql);
|
||||||
|
|
||||||
|
if (!engine.skipIncrementalAnalysis) {
|
||||||
|
const structure2RealIncremental = await driver.analyseIncremental(conn, structure1Source);
|
||||||
|
checkTableStructure(engine, tget(structure2RealIncremental), tget(structure2));
|
||||||
|
}
|
||||||
|
|
||||||
const structure2Real = extendDatabaseInfo(await driver.analyseFull(conn));
|
const structure2Real = extendDatabaseInfo(await driver.analyseFull(conn));
|
||||||
|
|
||||||
checkTableStructure(engine, tget(structure2Real), tget(structure2));
|
checkTableStructure(engine, tget(structure2Real), tget(structure2));
|
||||||
@@ -214,6 +238,48 @@ describe('Alter table', () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test.each(engines.filter(x => !x.skipReferences).map(engine => [engine.label, engine]))(
|
||||||
|
'Drop FK - %s',
|
||||||
|
testWrapper(async (conn, driver, engine) => {
|
||||||
|
await testTableDiff(
|
||||||
|
engine,
|
||||||
|
conn,
|
||||||
|
driver,
|
||||||
|
tbl => {
|
||||||
|
tbl.foreignKeys = [];
|
||||||
|
},
|
||||||
|
't2'
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
test.each(engines.filter(x => !x.skipReferences).map(engine => [engine.label, engine]))(
|
||||||
|
'Create FK - %s',
|
||||||
|
testWrapper(async (conn, driver, engine) => {
|
||||||
|
await testTableDiff(
|
||||||
|
engine,
|
||||||
|
conn,
|
||||||
|
driver,
|
||||||
|
tbl => {
|
||||||
|
tbl.foreignKeys = [
|
||||||
|
{
|
||||||
|
constraintType: 'foreignKey',
|
||||||
|
pureName: 't2',
|
||||||
|
refTableName: 't1',
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
columnName: 'fkval',
|
||||||
|
refColumnName: 'col_ref',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
},
|
||||||
|
't3'
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
// test.each(engines.map(engine => [engine.label, engine]))(
|
// test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
// 'Change autoincrement - %s',
|
// 'Change autoincrement - %s',
|
||||||
// testWrapper(async (conn, driver, engine) => {
|
// testWrapper(async (conn, driver, engine) => {
|
||||||
|
|||||||
@@ -759,9 +759,9 @@ const enginesOnLocal = [
|
|||||||
// cassandraEngine,
|
// cassandraEngine,
|
||||||
//mysqlEngine,
|
//mysqlEngine,
|
||||||
// mariaDbEngine,
|
// mariaDbEngine,
|
||||||
//postgreSqlEngine,
|
postgreSqlEngine,
|
||||||
//sqlServerEngine,
|
//sqlServerEngine,
|
||||||
sqliteEngine,
|
// sqliteEngine,
|
||||||
// cockroachDbEngine,
|
// cockroachDbEngine,
|
||||||
// clickhouseEngine,
|
// clickhouseEngine,
|
||||||
// libsqlFileEngine,
|
// libsqlFileEngine,
|
||||||
|
|||||||
Reference in New Issue
Block a user