mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
table remove - incremental analysis
This commit is contained in:
parent
a5ad8dc5f6
commit
e74521fdab
@ -10,6 +10,30 @@ function randomDbName() {
|
|||||||
return `db${newKey}`;
|
return `db${newKey}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const t1Match = expect.objectContaining({
|
||||||
|
pureName: 't1',
|
||||||
|
columns: [
|
||||||
|
expect.objectContaining({
|
||||||
|
columnName: 'id',
|
||||||
|
notNull: true,
|
||||||
|
dataType: expect.stringContaining('int'),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
columnName: 'val',
|
||||||
|
notNull: false,
|
||||||
|
dataType: expect.stringMatching(/.*char.*\(50\)/),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
primaryKey: expect.objectContaining({
|
||||||
|
columns: [
|
||||||
|
expect.objectContaining({
|
||||||
|
columnName: 'id',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
const t1Sql = 'CREATE TABLE t1 (id int not null primary key, val varchar(50) null)';
|
||||||
|
|
||||||
async function connect(engine, database) {
|
async function connect(engine, database) {
|
||||||
const { connection } = engine;
|
const { connection } = engine;
|
||||||
const driver = requireEngineDriver(connection);
|
const driver = requireEngineDriver(connection);
|
||||||
@ -40,21 +64,12 @@ describe('Analyse tests', () => {
|
|||||||
const conn = await connect(engine, randomDbName());
|
const conn = await connect(engine, randomDbName());
|
||||||
const driver = requireEngineDriver(engine.connection);
|
const driver = requireEngineDriver(engine.connection);
|
||||||
|
|
||||||
await driver.query(conn, 'CREATE TABLE t1 (id int not null primary key)');
|
await driver.query(conn, t1Sql);
|
||||||
|
|
||||||
const structure = await driver.analyseFull(conn);
|
const structure = await driver.analyseFull(conn);
|
||||||
|
|
||||||
expect(structure.tables.length).toEqual(1);
|
expect(structure.tables.length).toEqual(1);
|
||||||
expect(structure.tables[0]).toEqual(
|
expect(structure.tables[0]).toEqual(t1Match);
|
||||||
expect.objectContaining({
|
|
||||||
pureName: 't1',
|
|
||||||
columns: [
|
|
||||||
expect.objectContaining({
|
|
||||||
columnName: 'id',
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
);
|
|
||||||
await driver.close(conn);
|
await driver.close(conn);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -65,23 +80,33 @@ describe('Analyse tests', () => {
|
|||||||
const conn = await connect(engine, randomDbName());
|
const conn = await connect(engine, randomDbName());
|
||||||
const driver = requireEngineDriver(engine.connection);
|
const driver = requireEngineDriver(engine.connection);
|
||||||
|
|
||||||
await driver.query(conn, 'CREATE TABLE t1 (id int)');
|
await driver.query(conn, 'CREATE TABLE t0 (id0 int)');
|
||||||
const structure1 = await driver.analyseFull(conn);
|
const structure1 = await driver.analyseFull(conn);
|
||||||
await driver.query(conn, 'CREATE TABLE t2 (id2 int not null primary key)');
|
await driver.query(conn, t1Sql);
|
||||||
const structure2 = await driver.analyseIncremental(conn, structure1);
|
const structure2 = await driver.analyseIncremental(conn, structure1);
|
||||||
|
|
||||||
expect(structure2.tables.length).toEqual(2);
|
expect(structure2.tables.length).toEqual(2);
|
||||||
expect(structure2.tables.find(x => x.pureName == 't2')).toEqual(
|
expect(structure2.tables.find(x => x.pureName == 't1')).toEqual(t1Match);
|
||||||
expect.objectContaining({
|
|
||||||
pureName: 't2',
|
|
||||||
columns: [
|
|
||||||
expect.objectContaining({
|
|
||||||
columnName: 'id2',
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
);
|
|
||||||
await driver.close(conn);
|
await driver.close(conn);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
|
'Table remove - incremental analysis (%s)',
|
||||||
|
async (label, engine) => {
|
||||||
|
const conn = await connect(engine, randomDbName());
|
||||||
|
const driver = requireEngineDriver(engine.connection);
|
||||||
|
|
||||||
|
await driver.query(conn, t1Sql);
|
||||||
|
await driver.query(conn, 'CREATE TABLE t2 (id2 int)');
|
||||||
|
const structure1 = await driver.analyseFull(conn);
|
||||||
|
await driver.query(conn, 'DROP TABLE t2');
|
||||||
|
const structure2 = await driver.analyseIncremental(conn, structure1);
|
||||||
|
|
||||||
|
expect(structure2.tables.length).toEqual(1);
|
||||||
|
expect(structure2.tables[0]).toEqual(t1Match);
|
||||||
|
await driver.close(conn);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user