mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 02:06:01 +00:00
SYNC: mutli-sql tests
This commit is contained in:
committed by
Diflow
parent
5b246fe44c
commit
afcb226111
@@ -1,4 +1,5 @@
|
||||
const path = require('path');
|
||||
const localconfig = require('../.localconfig');
|
||||
|
||||
const dbgateApi = require('dbgate-api');
|
||||
dbgateApi.initializeApiEnvironment();
|
||||
@@ -7,11 +8,15 @@ dbgateApi.registerPlugins(dbgatePluginMysql);
|
||||
const dbgatePluginPostgres = require('dbgate-plugin-postgres');
|
||||
dbgateApi.registerPlugins(dbgatePluginPostgres);
|
||||
|
||||
async function createDb(connection, dropDbSql, createDbSql) {
|
||||
await dbgateApi.executeQuery({
|
||||
connection,
|
||||
sql: dropDbSql,
|
||||
});
|
||||
async function createDb(connection, dropDbSql, createDbSql, database = 'my_guitar_shop') {
|
||||
try {
|
||||
await dbgateApi.executeQuery({
|
||||
connection,
|
||||
sql: dropDbSql,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Failed to drop database', err);
|
||||
}
|
||||
|
||||
await dbgateApi.executeQuery({
|
||||
connection,
|
||||
@@ -21,36 +26,69 @@ async function createDb(connection, dropDbSql, createDbSql) {
|
||||
await dbgateApi.importDbFromFolder({
|
||||
connection: {
|
||||
...connection,
|
||||
database: 'my_guitar_shop',
|
||||
database,
|
||||
},
|
||||
folder: path.resolve(path.join(__dirname, '../data/my-guitar-shop')),
|
||||
});
|
||||
}
|
||||
|
||||
async function run() {
|
||||
await createDb(
|
||||
{
|
||||
server: process.env.SERVER_postgres,
|
||||
user: process.env.USER_postgres,
|
||||
password: process.env.PASSWORD_postgres,
|
||||
port: process.env.PORT_postgres,
|
||||
engine: 'postgres@dbgate-plugin-postgres',
|
||||
},
|
||||
'drop database if exists my_guitar_shop',
|
||||
'create database my_guitar_shop'
|
||||
);
|
||||
if (localconfig.postgres) {
|
||||
await createDb(
|
||||
{
|
||||
server: process.env.SERVER_postgres,
|
||||
user: process.env.USER_postgres,
|
||||
password: process.env.PASSWORD_postgres,
|
||||
port: process.env.PORT_postgres,
|
||||
engine: 'postgres@dbgate-plugin-postgres',
|
||||
},
|
||||
'drop database if exists my_guitar_shop',
|
||||
'create database my_guitar_shop'
|
||||
);
|
||||
}
|
||||
|
||||
await createDb(
|
||||
{
|
||||
server: process.env.SERVER_mysql,
|
||||
user: process.env.USER_mysql,
|
||||
password: process.env.PASSWORD_mysql,
|
||||
port: process.env.PORT_mysql,
|
||||
engine: 'mysql@dbgate-plugin-mysql',
|
||||
},
|
||||
'drop database if exists my_guitar_shop',
|
||||
'create database my_guitar_shop'
|
||||
);
|
||||
if (localconfig.mysql) {
|
||||
await createDb(
|
||||
{
|
||||
server: process.env.SERVER_mysql,
|
||||
user: process.env.USER_mysql,
|
||||
password: process.env.PASSWORD_mysql,
|
||||
port: process.env.PORT_mysql,
|
||||
engine: 'mysql@dbgate-plugin-mysql',
|
||||
},
|
||||
'drop database if exists my_guitar_shop',
|
||||
'create database my_guitar_shop'
|
||||
);
|
||||
}
|
||||
|
||||
if (localconfig.mssql) {
|
||||
await createDb(
|
||||
{
|
||||
server: process.env.SERVER_mssql,
|
||||
user: process.env.USER_mssql,
|
||||
password: process.env.PASSWORD_mssql,
|
||||
port: process.env.PORT_mssql,
|
||||
engine: 'mssql@dbgate-plugin-mssql',
|
||||
},
|
||||
'drop database if exists my_guitar_shop',
|
||||
'create database my_guitar_shop'
|
||||
);
|
||||
}
|
||||
|
||||
if (localconfig.oracle) {
|
||||
await createDb(
|
||||
{
|
||||
server: process.env.SERVER_oracle,
|
||||
user: process.env.USER_oracle,
|
||||
password: process.env.PASSWORD_oracle,
|
||||
port: process.env.PORT_oracle,
|
||||
engine: 'oracle@dbgate-plugin-oracle',
|
||||
},
|
||||
'DROP USER C##my_guitar_shop',
|
||||
'CREATE USER c##my_guitar_shop IDENTIFIED BY my_guitar_shop DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp QUOTA 10M ON users',
|
||||
'C##my_guitar_shop'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
dbgateApi.runScript(run);
|
||||
|
||||
Reference in New Issue
Block a user