mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 01:03:58 +00:00
table analyse refactor (works on oracle)
This commit is contained in:
8
.github/workflows/run-tests.yaml
vendored
8
.github/workflows/run-tests.yaml
vendored
@@ -84,10 +84,10 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
CLICKHOUSE_ADMIN_PASSWORD: Pwd2020Db
|
CLICKHOUSE_ADMIN_PASSWORD: Pwd2020Db
|
||||||
|
|
||||||
oracle:
|
# oracle:
|
||||||
image: gvenzl/oracle-xe:21-slim
|
# image: gvenzl/oracle-xe:21-slim
|
||||||
env:
|
# env:
|
||||||
ORACLE_PWD: Pwd2020Db
|
# ORACLE_PASSWORD: Pwd2020Db
|
||||||
|
|
||||||
# cockroachdb:
|
# cockroachdb:
|
||||||
# image: cockroachdb/cockroach
|
# image: cockroachdb/cockroach
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ const engines = require('../engines');
|
|||||||
const { testWrapper } = require('../tools');
|
const { testWrapper } = require('../tools');
|
||||||
|
|
||||||
const t1Sql = 'CREATE TABLE ~t1 (~id int not null primary key, ~val1 varchar(50))';
|
const t1Sql = 'CREATE TABLE ~t1 (~id int not null primary key, ~val1 varchar(50))';
|
||||||
const ix1Sql = 'CREATE index ix1 ON t1(val1, id)';
|
const ix1Sql = 'CREATE index ~ix1 ON ~t1(~val1, ~id)';
|
||||||
const t2Sql = engine =>
|
const t2Sql = engine =>
|
||||||
`CREATE TABLE t2 (id int not null primary key, val2 varchar(50) ${engine.skipUnique ? '' : 'unique'})`;
|
`CREATE TABLE ~t2 (~id int not null primary key, ~val2 varchar(50) ${engine.skipUnique ? '' : 'unique'})`;
|
||||||
const t3Sql = 'CREATE TABLE t3 (id int not null primary key, valfk int, foreign key (valfk) references t2(id))';
|
const t3Sql = 'CREATE TABLE ~t3 (~id int not null primary key, ~valfk int, foreign key (~valfk) references ~t2(~id))';
|
||||||
const t4Sql = 'CREATE TABLE t4 (id int not null primary key, valdef int not null default 12)';
|
const t4Sql = 'CREATE TABLE ~t4 (~id int not null primary key, ~valdef int not null default 12)';
|
||||||
// const fkSql = 'ALTER TABLE t3 ADD FOREIGN KEY (valfk) REFERENCES t2(id)'
|
// const fkSql = 'ALTER TABLE t3 ADD FOREIGN KEY (valfk) REFERENCES t2(id)'
|
||||||
|
|
||||||
const txMatch = (engine, tname, vcolname, nextcol, defaultValue) =>
|
const txMatch = (engine, tname, vcolname, nextcol, defaultValue) =>
|
||||||
@@ -73,7 +73,7 @@ describe('Table analyse', () => {
|
|||||||
test.each(engines.map(engine => [engine.label, engine]))(
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
'Table add - incremental analysis - %s',
|
'Table add - incremental analysis - %s',
|
||||||
testWrapper(async (conn, driver, engine) => {
|
testWrapper(async (conn, driver, engine) => {
|
||||||
await driver.query(conn, t2Sql(engine));
|
await runCommandOnDriver(conn, driver, dmp => dmp.put(t2Sql(engine)));
|
||||||
|
|
||||||
const structure1 = await driver.analyseFull(conn);
|
const structure1 = await driver.analyseFull(conn);
|
||||||
expect(structure1.tables.length).toEqual(1);
|
expect(structure1.tables.length).toEqual(1);
|
||||||
@@ -92,13 +92,13 @@ describe('Table analyse', () => {
|
|||||||
'Table remove - incremental analysis - %s',
|
'Table remove - incremental analysis - %s',
|
||||||
testWrapper(async (conn, driver, engine) => {
|
testWrapper(async (conn, driver, engine) => {
|
||||||
await runCommandOnDriver(conn, driver, dmp => dmp.put(t1Sql));
|
await runCommandOnDriver(conn, driver, dmp => dmp.put(t1Sql));
|
||||||
await driver.query(conn, t2Sql(engine));
|
await runCommandOnDriver(conn, driver, dmp => dmp.put(t2Sql(engine)));
|
||||||
const structure1 = await driver.analyseFull(conn);
|
const structure1 = await driver.analyseFull(conn);
|
||||||
expect(structure1.tables.length).toEqual(2);
|
expect(structure1.tables.length).toEqual(2);
|
||||||
expect(structure1.tables.find(x => x.pureName == 't1')).toEqual(t1Match(engine));
|
expect(structure1.tables.find(x => x.pureName == 't1')).toEqual(t1Match(engine));
|
||||||
expect(structure1.tables.find(x => x.pureName == 't2')).toEqual(t2Match(engine));
|
expect(structure1.tables.find(x => x.pureName == 't2')).toEqual(t2Match(engine));
|
||||||
|
|
||||||
await driver.query(conn, 'DROP TABLE t2');
|
await runCommandOnDriver(conn, driver, dmp => dmp.put('DROP TABLE ~t2'));
|
||||||
const structure2 = await driver.analyseIncremental(conn, structure1);
|
const structure2 = await driver.analyseIncremental(conn, structure1);
|
||||||
|
|
||||||
expect(structure2.tables.length).toEqual(1);
|
expect(structure2.tables.length).toEqual(1);
|
||||||
@@ -110,14 +110,13 @@ describe('Table analyse', () => {
|
|||||||
'Table change - incremental analysis - %s',
|
'Table change - incremental analysis - %s',
|
||||||
testWrapper(async (conn, driver, engine) => {
|
testWrapper(async (conn, driver, engine) => {
|
||||||
await runCommandOnDriver(conn, driver, dmp => dmp.put(t1Sql));
|
await runCommandOnDriver(conn, driver, dmp => dmp.put(t1Sql));
|
||||||
await driver.query(conn, t2Sql(engine));
|
await runCommandOnDriver(conn, driver, dmp => dmp.put(t2Sql(engine)));
|
||||||
const structure1 = await driver.analyseFull(conn);
|
const structure1 = await driver.analyseFull(conn);
|
||||||
|
|
||||||
if (engine.dbSnapshotBySeconds) await new Promise(resolve => setTimeout(resolve, 1100));
|
if (engine.dbSnapshotBySeconds) await new Promise(resolve => setTimeout(resolve, 1100));
|
||||||
|
|
||||||
await driver.query(
|
await runCommandOnDriver(conn, driver, dmp =>
|
||||||
conn,
|
dmp.put(`ALTER TABLE ~t2 ADD ${engine.alterTableAddColumnSyntax ? 'COLUMN' : ''} ~nextcol varchar(50)`)
|
||||||
`ALTER TABLE t2 ADD ${engine.alterTableAddColumnSyntax ? 'COLUMN' : ''} nextcol varchar(50)`
|
|
||||||
);
|
);
|
||||||
const structure2 = await driver.analyseIncremental(conn, structure1);
|
const structure2 = await driver.analyseIncremental(conn, structure1);
|
||||||
|
|
||||||
@@ -133,7 +132,7 @@ describe('Table analyse', () => {
|
|||||||
'Index - full analysis - %s',
|
'Index - full analysis - %s',
|
||||||
testWrapper(async (conn, driver, engine) => {
|
testWrapper(async (conn, driver, engine) => {
|
||||||
await runCommandOnDriver(conn, driver, dmp => dmp.put(t1Sql));
|
await runCommandOnDriver(conn, driver, dmp => dmp.put(t1Sql));
|
||||||
await driver.query(conn, ix1Sql);
|
await runCommandOnDriver(conn, driver, dmp => dmp.put(ix1Sql));
|
||||||
const structure = await driver.analyseFull(conn);
|
const structure = await driver.analyseFull(conn);
|
||||||
|
|
||||||
const t1 = structure.tables.find(x => x.pureName == 't1');
|
const t1 = structure.tables.find(x => x.pureName == 't1');
|
||||||
@@ -147,7 +146,7 @@ describe('Table analyse', () => {
|
|||||||
test.each(engines.filter(x => !x.skipUnique).map(engine => [engine.label, engine]))(
|
test.each(engines.filter(x => !x.skipUnique).map(engine => [engine.label, engine]))(
|
||||||
'Unique - full analysis - %s',
|
'Unique - full analysis - %s',
|
||||||
testWrapper(async (conn, driver, engine) => {
|
testWrapper(async (conn, driver, engine) => {
|
||||||
await driver.query(conn, t2Sql(engine));
|
await runCommandOnDriver(conn, driver, dmp => dmp.put(t2Sql(engine)));
|
||||||
const structure = await driver.analyseFull(conn);
|
const structure = await driver.analyseFull(conn);
|
||||||
|
|
||||||
const t2 = structure.tables.find(x => x.pureName == 't2');
|
const t2 = structure.tables.find(x => x.pureName == 't2');
|
||||||
@@ -161,8 +160,8 @@ describe('Table analyse', () => {
|
|||||||
test.each(engines.filter(x => !x.skipReferences).map(engine => [engine.label, engine]))(
|
test.each(engines.filter(x => !x.skipReferences).map(engine => [engine.label, engine]))(
|
||||||
'Foreign key - full analysis - %s',
|
'Foreign key - full analysis - %s',
|
||||||
testWrapper(async (conn, driver, engine) => {
|
testWrapper(async (conn, driver, engine) => {
|
||||||
await driver.query(conn, t2Sql(engine));
|
await runCommandOnDriver(conn, driver, dmp => dmp.put(t2Sql(engine)));
|
||||||
await driver.query(conn, t3Sql);
|
await runCommandOnDriver(conn, driver, dmp => dmp.put(t3Sql));
|
||||||
// await driver.query(conn, fkSql);
|
// await driver.query(conn, fkSql);
|
||||||
|
|
||||||
const structure = await driver.analyseFull(conn);
|
const structure = await driver.analyseFull(conn);
|
||||||
@@ -181,7 +180,7 @@ describe('Table analyse', () => {
|
|||||||
test.each(engines.map(engine => [engine.label, engine]))(
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
'Table structure - default value - %s',
|
'Table structure - default value - %s',
|
||||||
testWrapper(async (conn, driver, engine) => {
|
testWrapper(async (conn, driver, engine) => {
|
||||||
await driver.query(conn, t4Sql);
|
await runCommandOnDriver(conn, driver, dmp => dmp.put(t4Sql));
|
||||||
|
|
||||||
const structure = await driver.analyseFull(conn);
|
const structure = await driver.analyseFull(conn);
|
||||||
|
|
||||||
|
|||||||
@@ -71,8 +71,8 @@ services:
|
|||||||
# restart: on-failure
|
# restart: on-failure
|
||||||
|
|
||||||
oracle:
|
oracle:
|
||||||
image: container-registry.oracle.com/database/express:21.3.0-xe
|
image: gvenzl/oracle-xe:21-slim
|
||||||
environment:
|
environment:
|
||||||
ORACLE_PWD: Pwd2020Db
|
ORACLE_PASSWORD: Pwd2020Db
|
||||||
ports:
|
ports:
|
||||||
- 15006:1521
|
- 15006:1521
|
||||||
|
|||||||
@@ -414,7 +414,7 @@ end;$$`,
|
|||||||
server: 'localhost',
|
server: 'localhost',
|
||||||
port: 15006,
|
port: 15006,
|
||||||
},
|
},
|
||||||
skipOnCI: false,
|
skipOnCI: true,
|
||||||
dbSnapshotBySeconds: true,
|
dbSnapshotBySeconds: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user