schema analyser test

This commit is contained in:
Jan Prochazka 2024-09-18 16:01:02 +02:00
parent 5ab686b721
commit fc0db925c5
4 changed files with 72 additions and 16 deletions

View File

@ -67,3 +67,4 @@ describe('Alter database', () => {
})
);
});

View File

@ -0,0 +1,53 @@
const stableStringify = require('json-stable-stringify');
const _ = require('lodash');
const fp = require('lodash/fp');
const { testWrapper } = require('../tools');
const engines = require('../engines');
const { runCommandOnDriver } = require('dbgate-tools');
describe('Schema tests', () => {
test.each(engines.filter(x => x.supportSchemas).map(engine => [engine.label, engine]))(
'Create schema - %s',
testWrapper(async (conn, driver, engine) => {
const structure1 = await driver.analyseFull(conn);
expect(structure1.schemas.find(x => x.schemaName == 'myschema')).toBeFalsy();
await runCommandOnDriver(conn, driver, dmp => dmp.createSchema('myschema'));
const structure2 = await driver.analyseIncremental(conn, structure1);
expect(structure2.schemas.find(x => x.schemaName == 'myschema')).toBeTruthy();
})
);
test.each(engines.filter(x => x.supportSchemas).map(engine => [engine.label, engine]))(
'Drop schema - %s',
testWrapper(async (conn, driver, engine) => {
await runCommandOnDriver(conn, driver, dmp => dmp.createSchema('myschema'));
const structure1 = await driver.analyseFull(conn);
expect(structure1.schemas.find(x => x.schemaName == 'myschema')).toBeTruthy();
await runCommandOnDriver(conn, driver, dmp => dmp.dropSchema('myschema'));
const structure2 = await driver.analyseIncremental(conn, structure1);
expect(structure2.schemas.find(x => x.schemaName == 'myschema')).toBeFalsy();
})
);
});
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 null references t1(id)
)`
);
const structure1 = await driver.analyseFull(conn);
const structure2 = await driver.analyseIncremental(conn, structure1);
expect(structure2).toBeNull();
})
);
});

View File

@ -1,12 +1,12 @@
version: '3'
services:
# postgres:
# image: postgres
# restart: always
# environment:
# POSTGRES_PASSWORD: Pwd2020Db
# ports:
# - 15000:5432
postgres:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: Pwd2020Db
ports:
- 15000:5432
# mariadb:
# image: mariadb
@ -26,13 +26,13 @@ services:
# environment:
# - MYSQL_ROOT_PASSWORD=Pwd2020Db
clickhouse:
image: bitnami/clickhouse:24.8.4
restart: always
ports:
- 15005:8123
environment:
- CLICKHOUSE_ADMIN_PASSWORD=Pwd2020Db
# clickhouse:
# image: bitnami/clickhouse:24.8.4
# restart: always
# ports:
# - 15005:8123
# environment:
# - CLICKHOUSE_ADMIN_PASSWORD=Pwd2020Db
# mssql:
# image: mcr.microsoft.com/mssql/server

View File

@ -81,6 +81,7 @@ const engines = [
drop2: 'DROP FUNCTION obj2',
},
],
supportSchemas: true,
},
{
label: 'SQL Server',
@ -105,6 +106,7 @@ const engines = [
drop2: 'DROP PROCEDURE obj2',
},
],
supportSchemas: true,
},
{
label: 'SQLite',
@ -159,11 +161,11 @@ const filterLocal = [
// filter local testing
'-MySQL',
'-MariaDB',
'-PostgreSQL',
'PostgreSQL',
'-SQL Server',
'-SQLite',
'-CockroachDB',
'ClickHouse',
'-ClickHouse',
];
const enginesPostgre = engines.filter(x => x.label == 'PostgreSQL');