mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-03 11:43:57 +00:00
db deploy - next tests
This commit is contained in:
@@ -1,30 +1,41 @@
|
|||||||
/// TODO
|
/// TODO
|
||||||
|
|
||||||
const { testWrapper } = require('../tools');
|
const { testWrapper } = require('../tools');
|
||||||
|
const _ = require('lodash');
|
||||||
const engines = require('../engines');
|
const engines = require('../engines');
|
||||||
const deployDb = require('dbgate-api/src/shell/deployDb');
|
const deployDb = require('dbgate-api/src/shell/deployDb');
|
||||||
|
const { databaseInfoFromYamlModel } = require('dbgate-tools');
|
||||||
|
|
||||||
async function testDatabaseDeploy(conn, driver, dbModelYaml, checkDb) {
|
function checkStructure(structure, model) {
|
||||||
|
const expected = databaseInfoFromYamlModel(model);
|
||||||
|
expect(structure.tables.length).toEqual(expected.tables.length);
|
||||||
|
|
||||||
|
for (const [realTable, expectedTable] of _.zip(structure.tables, expected.tables)) {
|
||||||
|
expect(realTable.columns.length).toEqual(expectedTable.columns.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testDatabaseDeploy(conn, driver, dbModelsYaml) {
|
||||||
|
for (const loadedDbModel of dbModelsYaml) {
|
||||||
await deployDb({
|
await deployDb({
|
||||||
systemConnection: conn,
|
systemConnection: conn,
|
||||||
driver,
|
driver,
|
||||||
loadedDbModel: dbModelYaml,
|
loadedDbModel,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const structure = await driver.analyseFull(conn);
|
const structure = await driver.analyseFull(conn);
|
||||||
checkDb(structure);
|
checkStructure(structure, dbModelsYaml[dbModelsYaml.length - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Deploy database', () => {
|
describe('Deploy database', () => {
|
||||||
test.each(engines.map(engine => [engine.label, engine]))(
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
'Drop referenced table - %s',
|
'Deploy database simple - %s',
|
||||||
testWrapper(async (conn, driver, engine) => {
|
testWrapper(async (conn, driver, engine) => {
|
||||||
await testDatabaseDeploy(
|
await testDatabaseDeploy(conn, driver, [
|
||||||
conn,
|
|
||||||
driver,
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
name: 'tables.yaml',
|
name: 't1.table.yaml',
|
||||||
json: {
|
json: {
|
||||||
name: 't1',
|
name: 't1',
|
||||||
columns: [{ name: 'id', type: 'int' }],
|
columns: [{ name: 'id', type: 'int' }],
|
||||||
@@ -32,10 +43,35 @@ describe('Deploy database', () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
db => {
|
]);
|
||||||
expect(db.tables.length).toEqual(1);
|
})
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
|
'Deploy database simple twice - %s',
|
||||||
|
testWrapper(async (conn, driver, engine) => {
|
||||||
|
await testDatabaseDeploy(conn, driver, [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
name: 't1.table.yaml',
|
||||||
|
json: {
|
||||||
|
name: 't1',
|
||||||
|
columns: [{ name: 'id', type: 'int' }],
|
||||||
|
primaryKey: ['id'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
name: 't1.table.yaml',
|
||||||
|
json: {
|
||||||
|
name: 't1',
|
||||||
|
columns: [{ name: 'id', type: 'int' }],
|
||||||
|
primaryKey: ['id'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ async function deployDb({ connection, systemConnection, driver, analysedStructur
|
|||||||
modelFolder,
|
modelFolder,
|
||||||
loadedDbModel,
|
loadedDbModel,
|
||||||
});
|
});
|
||||||
|
console.log('RUNNING DEPLOY SCRIPT:', sql);
|
||||||
await executeQuery({ connection, systemConnection, driver, sql });
|
await executeQuery({ connection, systemConnection, driver, sql });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ function columnInfoFromYaml(column: ColumnInfoYaml, table: TableInfoYaml): Colum
|
|||||||
columnName: column.name,
|
columnName: column.name,
|
||||||
dataType: column.type,
|
dataType: column.type,
|
||||||
autoIncrement: column.autoIncrement,
|
autoIncrement: column.autoIncrement,
|
||||||
notNull: column.notNull,
|
notNull: column.notNull || (table.primaryKey && table.primaryKey.includes(column.name)),
|
||||||
};
|
};
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -170,5 +170,8 @@ export function databaseInfoFromYamlModel(files: DatabaseModelFile[]): DatabaseI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model.tables = tablesYaml.map(table => tableInfoFromYaml(table, tablesYaml));
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user