SYNC: multi-sql

This commit is contained in:
SPRINX0\prochazka
2025-02-24 12:20:30 +01:00
committed by Diflow
parent 8bdd24aa1e
commit bdd9dc8c9d
27 changed files with 526 additions and 11 deletions

View File

@@ -0,0 +1,56 @@
const path = require('path');
const dbgateApi = require('dbgate-api');
dbgateApi.initializeApiEnvironment();
const dbgatePluginMysql = require('dbgate-plugin-mysql');
dbgateApi.registerPlugins(dbgatePluginMysql);
const dbgatePluginPostgres = require('dbgate-plugin-postgres');
dbgateApi.registerPlugins(dbgatePluginPostgres);
async function createDb(connection, dropDbSql, createDbSql) {
await dbgateApi.executeQuery({
connection,
sql: dropDbSql,
});
await dbgateApi.executeQuery({
connection,
sql: createDbSql,
});
await dbgateApi.importDbFromFolder({
connection: {
...connection,
database: 'my_quitar_shop',
},
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_quitar_shop',
'create database my_quitar_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_quitar_shop',
'create database my_quitar_shop'
);
}
dbgateApi.runScript(run);