mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
create table test
This commit is contained in:
parent
f4c39bbf3c
commit
5b58ed9c26
@ -1,23 +1,10 @@
|
|||||||
const stableStringify = require('json-stable-stringify');
|
const stableStringify = require('json-stable-stringify');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const fp = require('lodash/fp');
|
|
||||||
const uuidv1 = require('uuid/v1');
|
const uuidv1 = require('uuid/v1');
|
||||||
const { testWrapper } = require('../tools');
|
const { testWrapper, checkTableStructure } = require('../tools');
|
||||||
const engines = require('../engines');
|
const engines = require('../engines');
|
||||||
const { getAlterTableScript, extendDatabaseInfo, generateDbPairingId } = require('dbgate-tools');
|
const { getAlterTableScript, extendDatabaseInfo, generateDbPairingId } = require('dbgate-tools');
|
||||||
|
|
||||||
function pickImportantTableInfo(table) {
|
|
||||||
return {
|
|
||||||
pureName: table.pureName,
|
|
||||||
columns: table.columns.map(fp.pick(['columnName', 'notNull', 'autoIncrement'])),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkTableStructure(t1, t2) {
|
|
||||||
// expect(t1.pureName).toEqual(t2.pureName)
|
|
||||||
expect(pickImportantTableInfo(t1)).toEqual(pickImportantTableInfo(t2));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function testTableDiff(conn, driver, mangle) {
|
async function testTableDiff(conn, driver, mangle) {
|
||||||
await driver.query(conn, `create table t0 (id int not null primary key)`);
|
await driver.query(conn, `create table t0 (id int not null primary key)`);
|
||||||
|
|
||||||
|
41
integration-tests/__tests__/table-create.spec.js
Normal file
41
integration-tests/__tests__/table-create.spec.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
const engines = require('../engines');
|
||||||
|
const { testWrapper, checkTableStructure } = require('../tools');
|
||||||
|
const { extendDatabaseInfo } = require('dbgate-tools');
|
||||||
|
|
||||||
|
async function testTableCreate(conn, driver, table) {
|
||||||
|
const dmp = driver.createDumper();
|
||||||
|
const table1 = {
|
||||||
|
...table,
|
||||||
|
pureName: 'tested',
|
||||||
|
};
|
||||||
|
dmp.createTable(table1);
|
||||||
|
|
||||||
|
console.log('RUNNING CREATE SQL', driver.engine, ':', dmp.s);
|
||||||
|
await driver.query(conn, dmp.s);
|
||||||
|
|
||||||
|
const db = extendDatabaseInfo(await driver.analyseFull(conn));
|
||||||
|
const table2 = db.tables.find(x => x.pureName == 'tested');
|
||||||
|
|
||||||
|
checkTableStructure(table1, table2);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Table create', () => {
|
||||||
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
|
'Table structure - full analysis - %s',
|
||||||
|
testWrapper(async (conn, driver, engine) => {
|
||||||
|
await testTableCreate(conn, driver, {
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
columnName: 'col1',
|
||||||
|
dataType: 'int',
|
||||||
|
notNull: true,
|
||||||
|
autoIncrement: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
primaryKey: {
|
||||||
|
columns: [{ columnName: 'col1' }],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
@ -16,7 +16,7 @@ const matviews = {
|
|||||||
const engines = [
|
const engines = [
|
||||||
{
|
{
|
||||||
label: 'MySQL',
|
label: 'MySQL',
|
||||||
skipLocal: true,
|
// skipLocal: true,
|
||||||
connection: {
|
connection: {
|
||||||
engine: 'mysql@dbgate-plugin-mysql',
|
engine: 'mysql@dbgate-plugin-mysql',
|
||||||
password: 'Pwd2020Db',
|
password: 'Pwd2020Db',
|
||||||
@ -94,7 +94,7 @@ const engines = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'SQLite',
|
label: 'SQLite',
|
||||||
skipLocal: true,
|
// skipLocal: true,
|
||||||
generateDbFile: true,
|
generateDbFile: true,
|
||||||
connection: {
|
connection: {
|
||||||
engine: 'sqlite@dbgate-plugin-sqlite',
|
engine: 'sqlite@dbgate-plugin-sqlite',
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
global.DBGATE_TOOLS = require('dbgate-tools');
|
global.DBGATE_TOOLS = require('dbgate-tools');
|
||||||
const requireEngineDriver = require('dbgate-api/src/utility/requireEngineDriver');
|
const requireEngineDriver = require('dbgate-api/src/utility/requireEngineDriver');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
const fp = require('lodash/fp');
|
||||||
|
|
||||||
function randomDbName() {
|
function randomDbName() {
|
||||||
const generatedKey = crypto.randomBytes(6);
|
const generatedKey = crypto.randomBytes(6);
|
||||||
@ -55,9 +56,22 @@ const testWrapper = body => async (label, ...other) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function pickImportantTableInfo(table) {
|
||||||
|
return {
|
||||||
|
pureName: table.pureName,
|
||||||
|
columns: table.columns.map(fp.pick(['columnName', 'notNull', 'autoIncrement'])),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkTableStructure(t1, t2) {
|
||||||
|
// expect(t1.pureName).toEqual(t2.pureName)
|
||||||
|
expect(pickImportantTableInfo(t1)).toEqual(pickImportantTableInfo(t2));
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
randomDbName,
|
randomDbName,
|
||||||
connect,
|
connect,
|
||||||
extractConnection,
|
extractConnection,
|
||||||
testWrapper,
|
testWrapper,
|
||||||
|
checkTableStructure,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user