mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 21:56:00 +00:00
fixed incremental analysis when changed schema+test
This commit is contained in:
@@ -5,28 +5,49 @@ const { testWrapper } = require('../tools');
|
|||||||
const engines = require('../engines');
|
const engines = require('../engines');
|
||||||
const { runCommandOnDriver } = require('dbgate-tools');
|
const { runCommandOnDriver } = require('dbgate-tools');
|
||||||
|
|
||||||
|
async function baseStructure(conn, driver) {
|
||||||
|
await driver.query(conn, `create table t1 (id int not null primary key)`);
|
||||||
|
|
||||||
|
await driver.query(
|
||||||
|
conn,
|
||||||
|
`create table t2 (
|
||||||
|
id int not null primary key,
|
||||||
|
t1_id int
|
||||||
|
)`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
describe('Schema tests', () => {
|
describe('Schema tests', () => {
|
||||||
test.each(engines.filter(x => x.supportSchemas).map(engine => [engine.label, engine]))(
|
test.each(engines.filter(x => x.supportSchemas).map(engine => [engine.label, engine]))(
|
||||||
'Create schema - %s',
|
'Create schema - %s',
|
||||||
testWrapper(async (conn, driver, engine) => {
|
testWrapper(async (conn, driver, engine) => {
|
||||||
|
await baseStructure(conn, driver);
|
||||||
const structure1 = await driver.analyseFull(conn);
|
const structure1 = await driver.analyseFull(conn);
|
||||||
expect(structure1.schemas.find(x => x.schemaName == 'myschema')).toBeFalsy();
|
expect(structure1.schemas.find(x => x.schemaName == 'myschema')).toBeFalsy();
|
||||||
|
expect(structure1.tables.length).toEqual(2);
|
||||||
await runCommandOnDriver(conn, driver, dmp => dmp.createSchema('myschema'));
|
await runCommandOnDriver(conn, driver, dmp => dmp.createSchema('myschema'));
|
||||||
const structure2 = await driver.analyseIncremental(conn, structure1);
|
const structure2 = await driver.analyseIncremental(conn, structure1);
|
||||||
expect(structure2.schemas.find(x => x.schemaName == 'myschema')).toBeTruthy();
|
expect(structure2.schemas.find(x => x.schemaName == 'myschema')).toBeTruthy();
|
||||||
|
expect(structure2.tables.length).toEqual(2);
|
||||||
|
|
||||||
|
const structure3 = await driver.analyseIncremental(conn, structure2);
|
||||||
|
expect(structure3).toBeNull();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
test.each(engines.filter(x => x.supportSchemas).map(engine => [engine.label, engine]))(
|
test.each(engines.filter(x => x.supportSchemas).map(engine => [engine.label, engine]))(
|
||||||
'Drop schema - %s',
|
'Drop schema - %s',
|
||||||
testWrapper(async (conn, driver, engine) => {
|
testWrapper(async (conn, driver, engine) => {
|
||||||
|
await baseStructure(conn, driver);
|
||||||
await runCommandOnDriver(conn, driver, dmp => dmp.createSchema('myschema'));
|
await runCommandOnDriver(conn, driver, dmp => dmp.createSchema('myschema'));
|
||||||
|
|
||||||
const structure1 = await driver.analyseFull(conn);
|
const structure1 = await driver.analyseFull(conn);
|
||||||
expect(structure1.schemas.find(x => x.schemaName == 'myschema')).toBeTruthy();
|
expect(structure1.schemas.find(x => x.schemaName == 'myschema')).toBeTruthy();
|
||||||
|
expect(structure1.tables.length).toEqual(2);
|
||||||
await runCommandOnDriver(conn, driver, dmp => dmp.dropSchema('myschema'));
|
await runCommandOnDriver(conn, driver, dmp => dmp.dropSchema('myschema'));
|
||||||
const structure2 = await driver.analyseIncremental(conn, structure1);
|
const structure2 = await driver.analyseIncremental(conn, structure1);
|
||||||
expect(structure2.schemas.find(x => x.schemaName == 'myschema')).toBeFalsy();
|
expect(structure2.schemas.find(x => x.schemaName == 'myschema')).toBeFalsy();
|
||||||
|
expect(structure2.tables.length).toEqual(2);
|
||||||
|
|
||||||
const structure3 = await driver.analyseIncremental(conn, structure2);
|
const structure3 = await driver.analyseIncremental(conn, structure2);
|
||||||
expect(structure3).toBeNull();
|
expect(structure3).toBeNull();
|
||||||
@@ -38,17 +59,10 @@ describe('Base analyser test', () => {
|
|||||||
test.each(engines.map(engine => [engine.label, engine]))(
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
'Structure without change - %s',
|
'Structure without change - %s',
|
||||||
testWrapper(async (conn, driver, engine) => {
|
testWrapper(async (conn, driver, engine) => {
|
||||||
await driver.query(conn, `create table t1 (id int not null primary key)`);
|
await baseStructure(conn, driver);
|
||||||
|
|
||||||
await driver.query(
|
|
||||||
conn,
|
|
||||||
`create table t2 (
|
|
||||||
id int not null primary key,
|
|
||||||
t1_id int
|
|
||||||
)`
|
|
||||||
);
|
|
||||||
|
|
||||||
const structure1 = await driver.analyseFull(conn);
|
const structure1 = await driver.analyseFull(conn);
|
||||||
|
expect(structure1.tables.length).toEqual(2);
|
||||||
const structure2 = await driver.analyseIncremental(conn, structure1);
|
const structure2 = await driver.analyseIncremental(conn, structure1);
|
||||||
expect(structure2).toBeNull();
|
expect(structure2).toBeNull();
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ export class DatabaseAnalyser {
|
|||||||
const areSchemasDifferent = stableStringify(schemas) != stableStringify(this.structure.schemas);
|
const areSchemasDifferent = stableStringify(schemas) != stableStringify(this.structure.schemas);
|
||||||
if (areSchemasDifferent) {
|
if (areSchemasDifferent) {
|
||||||
structureUpdated = {
|
structureUpdated = {
|
||||||
|
...structure,
|
||||||
...structureUpdated,
|
...structureUpdated,
|
||||||
schemas,
|
schemas,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user