diff --git a/integration-tests/__tests__/schema-tests.spec.js b/integration-tests/__tests__/schema-tests.spec.js index ce5e72dc7..4edeb3c5e 100644 --- a/integration-tests/__tests__/schema-tests.spec.js +++ b/integration-tests/__tests__/schema-tests.spec.js @@ -5,28 +5,49 @@ const { testWrapper } = require('../tools'); const engines = require('../engines'); 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', () => { test.each(engines.filter(x => x.supportSchemas).map(engine => [engine.label, engine]))( 'Create schema - %s', testWrapper(async (conn, driver, engine) => { + await baseStructure(conn, driver); const structure1 = await driver.analyseFull(conn); expect(structure1.schemas.find(x => x.schemaName == 'myschema')).toBeFalsy(); + expect(structure1.tables.length).toEqual(2); await runCommandOnDriver(conn, driver, dmp => dmp.createSchema('myschema')); const structure2 = await driver.analyseIncremental(conn, structure1); 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]))( 'Drop schema - %s', testWrapper(async (conn, driver, engine) => { + await baseStructure(conn, driver); await runCommandOnDriver(conn, driver, dmp => dmp.createSchema('myschema')); const structure1 = await driver.analyseFull(conn); expect(structure1.schemas.find(x => x.schemaName == 'myschema')).toBeTruthy(); + expect(structure1.tables.length).toEqual(2); await runCommandOnDriver(conn, driver, dmp => dmp.dropSchema('myschema')); const structure2 = await driver.analyseIncremental(conn, structure1); expect(structure2.schemas.find(x => x.schemaName == 'myschema')).toBeFalsy(); + expect(structure2.tables.length).toEqual(2); const structure3 = await driver.analyseIncremental(conn, structure2); expect(structure3).toBeNull(); @@ -38,17 +59,10 @@ describe('Base analyser test', () => { test.each(engines.map(engine => [engine.label, engine]))( 'Structure without change - %s', testWrapper(async (conn, driver, engine) => { - 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 - )` - ); + await baseStructure(conn, driver); const structure1 = await driver.analyseFull(conn); + expect(structure1.tables.length).toEqual(2); const structure2 = await driver.analyseIncremental(conn, structure1); expect(structure2).toBeNull(); }) diff --git a/packages/tools/src/DatabaseAnalyser.ts b/packages/tools/src/DatabaseAnalyser.ts index b189a3900..ab5a8dc12 100644 --- a/packages/tools/src/DatabaseAnalyser.ts +++ b/packages/tools/src/DatabaseAnalyser.ts @@ -119,6 +119,7 @@ export class DatabaseAnalyser { const areSchemasDifferent = stableStringify(schemas) != stableStringify(this.structure.schemas); if (areSchemasDifferent) { structureUpdated = { + ...structure, ...structureUpdated, schemas, };