mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 16:43:59 +00:00
alter table analyser test
This commit is contained in:
@@ -1,29 +1,45 @@
|
|||||||
const engines = require('../engines');
|
const engines = require('../engines');
|
||||||
const { testWrapper } = require('../tools');
|
const { testWrapper } = require('../tools');
|
||||||
|
|
||||||
const t1Sql = 'CREATE TABLE t1 (id int not null primary key, val varchar(50) null)';
|
const t1Sql = 'CREATE TABLE t1 (id int not null primary key, val1 varchar(50) null)';
|
||||||
const t1Match = expect.objectContaining({
|
const t2Sql = 'CREATE TABLE t2 (id int not null primary key, val2 varchar(50) null)';
|
||||||
pureName: 't1',
|
|
||||||
columns: [
|
const txMatch = (tname, vcolname, nextcol) =>
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
columnName: 'id',
|
pureName: tname,
|
||||||
notNull: true,
|
|
||||||
dataType: expect.stringContaining('int'),
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
columnName: 'val',
|
|
||||||
notNull: false,
|
|
||||||
dataType: expect.stringMatching(/.*char.*\(50\)/),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
primaryKey: expect.objectContaining({
|
|
||||||
columns: [
|
columns: [
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
columnName: 'id',
|
columnName: 'id',
|
||||||
|
notNull: true,
|
||||||
|
dataType: expect.stringContaining('int'),
|
||||||
}),
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
columnName: vcolname,
|
||||||
|
notNull: false,
|
||||||
|
dataType: expect.stringMatching(/.*char.*\(50\)/),
|
||||||
|
}),
|
||||||
|
...(nextcol
|
||||||
|
? [
|
||||||
|
expect.objectContaining({
|
||||||
|
columnName: 'nextcol',
|
||||||
|
notNull: false,
|
||||||
|
dataType: expect.stringMatching(/.*char.*\(50\)/),
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
: []),
|
||||||
],
|
],
|
||||||
}),
|
primaryKey: expect.objectContaining({
|
||||||
});
|
columns: [
|
||||||
|
expect.objectContaining({
|
||||||
|
columnName: 'id',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const t1Match = txMatch('t1', 'val1');
|
||||||
|
const t2Match = txMatch('t2', 'val2');
|
||||||
|
const t2NextColMatch = txMatch('t2', 'val2', true);
|
||||||
|
|
||||||
describe('Table analyse', () => {
|
describe('Table analyse', () => {
|
||||||
test.each(engines.map(engine => [engine.label, engine]))(
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
@@ -41,13 +57,18 @@ 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, 'CREATE TABLE t0 (id0 int)');
|
await driver.query(conn, t2Sql);
|
||||||
|
|
||||||
const structure1 = await driver.analyseFull(conn);
|
const structure1 = await driver.analyseFull(conn);
|
||||||
|
expect(structure1.tables.length).toEqual(1);
|
||||||
|
expect(structure1.tables[0]).toEqual(t2Match);
|
||||||
|
|
||||||
await driver.query(conn, t1Sql);
|
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 == 't1')).toEqual(t1Match);
|
expect(structure2.tables.find(x => x.pureName == 't1')).toEqual(t1Match);
|
||||||
|
expect(structure2.tables.find(x => x.pureName == 't2')).toEqual(t2Match);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -55,8 +76,12 @@ describe('Table analyse', () => {
|
|||||||
'Table remove - incremental analysis - %s',
|
'Table remove - incremental analysis - %s',
|
||||||
testWrapper(async (conn, driver, engine) => {
|
testWrapper(async (conn, driver, engine) => {
|
||||||
await driver.query(conn, t1Sql);
|
await driver.query(conn, t1Sql);
|
||||||
await driver.query(conn, 'CREATE TABLE t2 (id2 int)');
|
await driver.query(conn, t2Sql);
|
||||||
const structure1 = await driver.analyseFull(conn);
|
const structure1 = await driver.analyseFull(conn);
|
||||||
|
expect(structure1.tables.length).toEqual(2);
|
||||||
|
expect(structure1.tables.find(x => x.pureName == 't1')).toEqual(t1Match);
|
||||||
|
expect(structure1.tables.find(x => x.pureName == 't2')).toEqual(t2Match);
|
||||||
|
|
||||||
await driver.query(conn, 'DROP TABLE t2');
|
await driver.query(conn, 'DROP TABLE t2');
|
||||||
const structure2 = await driver.analyseIncremental(conn, structure1);
|
const structure2 = await driver.analyseIncremental(conn, structure1);
|
||||||
|
|
||||||
@@ -64,4 +89,24 @@ describe('Table analyse', () => {
|
|||||||
expect(structure2.tables[0]).toEqual(t1Match);
|
expect(structure2.tables[0]).toEqual(t1Match);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
|
'Table change - incremental analysis - %s',
|
||||||
|
testWrapper(async (conn, driver, engine) => {
|
||||||
|
await driver.query(conn, t1Sql);
|
||||||
|
await driver.query(conn, t2Sql);
|
||||||
|
const structure1 = await driver.analyseFull(conn);
|
||||||
|
|
||||||
|
if (engine.dbSnapshotBySeconds) await new Promise(resolve => setTimeout(resolve, 1100));
|
||||||
|
|
||||||
|
await driver.query(conn, 'ALTER TABLE t2 ADD nextcol varchar(50)');
|
||||||
|
const structure2 = await driver.analyseIncremental(conn, structure1);
|
||||||
|
|
||||||
|
expect(structure2).toBeTruthy(); // if falsy, no modification is detected
|
||||||
|
|
||||||
|
expect(structure2.tables.length).toEqual(2);
|
||||||
|
expect(structure2.tables.find(x => x.pureName == 't1')).toEqual(t1Match);
|
||||||
|
expect(structure2.tables.find(x => x.pureName == 't2')).toEqual(t2NextColMatch);
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const engines = [
|
|||||||
},
|
},
|
||||||
// skipOnCI: true,
|
// skipOnCI: true,
|
||||||
objects: [views],
|
objects: [views],
|
||||||
|
dbSnapshotBySeconds: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'PostgreSQL',
|
label: 'PostgreSQL',
|
||||||
|
|||||||
Reference in New Issue
Block a user