mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 02:36:01 +00:00
SYNC: mongo import tests
This commit is contained in:
committed by
Diflow
parent
0046575a4f
commit
2b7f4281c2
@@ -1,7 +1,8 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
mysql: true,
|
// mysql: true,
|
||||||
postgres: true,
|
// postgres: true,
|
||||||
mssql: true,
|
// mssql: true,
|
||||||
oracle: true,
|
// oracle: true,
|
||||||
sqlite: true,
|
// sqlite: true,
|
||||||
|
mongo: true
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,32 +28,32 @@ beforeEach(() => {
|
|||||||
cy.viewport(1250, 900);
|
cy.viewport(1250, 900);
|
||||||
});
|
});
|
||||||
|
|
||||||
function multiTest(testName, testDefinition) {
|
function multiTest(testProps, testDefinition) {
|
||||||
if (localconfig.mysql) {
|
if (localconfig.mysql) {
|
||||||
it(testName + ' MySQL', () => testDefinition('MySql-connection', 'my_guitar_shop', 'mysql@dbgate-plugin-mysql'));
|
it('MySQL', () => testDefinition('MySql-connection', 'my_guitar_shop', 'mysql@dbgate-plugin-mysql'));
|
||||||
}
|
}
|
||||||
if (localconfig.postgres) {
|
if (localconfig.postgres) {
|
||||||
it(testName + ' Postgres', () =>
|
it('Postgres', () => testDefinition('Postgres-connection', 'my_guitar_shop', 'postgres@dbgate-plugin-postgres'));
|
||||||
testDefinition('Postgres-connection', 'my_guitar_shop', 'postgres@dbgate-plugin-postgres')
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (localconfig.mssql) {
|
if (localconfig.mssql) {
|
||||||
it(testName + ' Mssql', () => testDefinition('Mssql-connection', 'my_guitar_shop', 'mssql@dbgate-plugin-mssql'));
|
it('Mssql', () => testDefinition('Mssql-connection', 'my_guitar_shop', 'mssql@dbgate-plugin-mssql'));
|
||||||
}
|
}
|
||||||
if (localconfig.oracle) {
|
if (localconfig.oracle) {
|
||||||
it(testName + ' Oracle', () =>
|
it('Oracle', () =>
|
||||||
testDefinition('Oracle-connection', 'C##MY_GUITAR_SHOP', 'oracle@dbgate-plugin-oracle', {
|
testDefinition('Oracle-connection', 'C##MY_GUITAR_SHOP', 'oracle@dbgate-plugin-oracle', {
|
||||||
implicitTransactions: true,
|
implicitTransactions: true,
|
||||||
})
|
}));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (localconfig.sqlite) {
|
if (localconfig.sqlite) {
|
||||||
it(testName + ' Sqlite', () => testDefinition('Sqlite-connection', null, 'sqlite@dbgate-plugin-sqlite'));
|
it('Sqlite', () => testDefinition('Sqlite-connection', null, 'sqlite@dbgate-plugin-sqlite'));
|
||||||
|
}
|
||||||
|
if (localconfig.mongo && !testProps.skipMongo) {
|
||||||
|
it('MongoDB', () => testDefinition('Mongo-connection', 'my_guitar_shop', 'mongo@dbgate-plugin-mongo'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Transactions', () => {
|
describe('Transactions', () => {
|
||||||
multiTest('Transactions', (connectionName, databaseName, engine, options = {}) => {
|
multiTest({ skipMongo: true }, (connectionName, databaseName, engine, options = {}) => {
|
||||||
const driver = requireEngineDriver(engine);
|
const driver = requireEngineDriver(engine);
|
||||||
const implicitTransactions = options.implicitTransactions ?? false;
|
const implicitTransactions = options.implicitTransactions ?? false;
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ describe('Transactions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Backup table', () => {
|
describe('Backup table', () => {
|
||||||
multiTest('Backup table', (connectionName, databaseName, engine, options = {}) => {
|
multiTest({ skipMongo: true }, (connectionName, databaseName, engine, options = {}) => {
|
||||||
cy.contains(connectionName).click();
|
cy.contains(connectionName).click();
|
||||||
if (databaseName) cy.contains(databaseName).click();
|
if (databaseName) cy.contains(databaseName).click();
|
||||||
cy.contains('customers').rightclick();
|
cy.contains('customers').rightclick();
|
||||||
@@ -113,7 +113,7 @@ describe('Backup table', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Truncate table', () => {
|
describe('Truncate table', () => {
|
||||||
multiTest('Truncate table', (connectionName, databaseName, engine, options = {}) => {
|
multiTest({ skipMongo: true }, (connectionName, databaseName, engine, options = {}) => {
|
||||||
cy.contains(connectionName).click();
|
cy.contains(connectionName).click();
|
||||||
if (databaseName) cy.contains(databaseName).click();
|
if (databaseName) cy.contains(databaseName).click();
|
||||||
cy.contains('order_items').rightclick();
|
cy.contains('order_items').rightclick();
|
||||||
@@ -125,7 +125,7 @@ describe('Truncate table', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Drop table', () => {
|
describe('Drop table', () => {
|
||||||
multiTest('Drop table', (connectionName, databaseName, engine, options = {}) => {
|
multiTest({ skipMongo: true }, (connectionName, databaseName, engine, options = {}) => {
|
||||||
cy.contains(connectionName).click();
|
cy.contains(connectionName).click();
|
||||||
if (databaseName) cy.contains(databaseName).click();
|
if (databaseName) cy.contains(databaseName).click();
|
||||||
cy.contains('order_items').rightclick();
|
cy.contains('order_items').rightclick();
|
||||||
@@ -136,7 +136,7 @@ describe('Drop table', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Import CSV', () => {
|
describe('Import CSV', () => {
|
||||||
multiTest('Import CSV', (connectionName, databaseName, engine, options = {}) => {
|
multiTest({}, (connectionName, databaseName, engine, options = {}) => {
|
||||||
cy.contains(connectionName).click();
|
cy.contains(connectionName).click();
|
||||||
if (databaseName) cy.contains(databaseName).click();
|
if (databaseName) cy.contains(databaseName).click();
|
||||||
cy.testid('ConnectionList_container')
|
cy.testid('ConnectionList_container')
|
||||||
@@ -146,7 +146,7 @@ describe('Import CSV', () => {
|
|||||||
|
|
||||||
cy.get('input[type=file]').selectFile('cypress/fixtures/customers-20.csv', { force: true });
|
cy.get('input[type=file]').selectFile('cypress/fixtures/customers-20.csv', { force: true });
|
||||||
cy.contains('customers-20');
|
cy.contains('customers-20');
|
||||||
cy.testid('ImportExportTab_preview').contains('Jessica').should('be.visible');
|
cy.testid('ImportExportTab_preview_content').contains('50ddd99fAdF48B3').should('be.visible');
|
||||||
|
|
||||||
cy.testid('ImportExportTab_executeButton').click();
|
cy.testid('ImportExportTab_executeButton').click();
|
||||||
cy.contains('20 rows written').should('be.visible');
|
cy.contains('20 rows written').should('be.visible');
|
||||||
@@ -164,7 +164,7 @@ describe('Import CSV', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Import CSV - source error', () => {
|
describe('Import CSV - source error', () => {
|
||||||
multiTest('Import CSV - source error', (connectionName, databaseName, engine, options = {}) => {
|
multiTest({}, (connectionName, databaseName, engine, options = {}) => {
|
||||||
cy.contains(connectionName).click();
|
cy.contains(connectionName).click();
|
||||||
if (databaseName) cy.contains(databaseName).click();
|
if (databaseName) cy.contains(databaseName).click();
|
||||||
cy.testid('ConnectionList_container')
|
cy.testid('ConnectionList_container')
|
||||||
@@ -184,7 +184,7 @@ describe('Import CSV - source error', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Import CSV - target error', () => {
|
describe('Import CSV - target error', () => {
|
||||||
multiTest('Import CSV - target error', (connectionName, databaseName, engine, options = {}) => {
|
multiTest({ skipMongo: true }, (connectionName, databaseName, engine, options = {}) => {
|
||||||
cy.contains(connectionName).click();
|
cy.contains(connectionName).click();
|
||||||
if (databaseName) cy.contains(databaseName).click();
|
if (databaseName) cy.contains(databaseName).click();
|
||||||
cy.testid('ConnectionList_container')
|
cy.testid('ConnectionList_container')
|
||||||
|
|||||||
10
e2e-tests/env/multi-sql/.env
vendored
10
e2e-tests/env/multi-sql/.env
vendored
@@ -1,4 +1,4 @@
|
|||||||
CONNECTIONS=mysql,postgres,mssql,oracle,sqlite
|
CONNECTIONS=mysql,postgres,mssql,oracle,sqlite,mongo
|
||||||
LOG_CONNECTION_SENSITIVE_VALUES=true
|
LOG_CONNECTION_SENSITIVE_VALUES=true
|
||||||
|
|
||||||
LABEL_mysql=MySql-connection
|
LABEL_mysql=MySql-connection
|
||||||
@@ -35,3 +35,11 @@ ENGINE_mssql=mssql@dbgate-plugin-mssql
|
|||||||
LABEL_sqlite=Sqlite-connection
|
LABEL_sqlite=Sqlite-connection
|
||||||
FILE_sqlite=%%E2E_TEST_DATA_DIRECTORY%%/my_guitar_shop.db
|
FILE_sqlite=%%E2E_TEST_DATA_DIRECTORY%%/my_guitar_shop.db
|
||||||
ENGINE_sqlite=sqlite@dbgate-plugin-sqlite
|
ENGINE_sqlite=sqlite@dbgate-plugin-sqlite
|
||||||
|
|
||||||
|
LABEL_mongo=Mongo-connection
|
||||||
|
SERVER_mongo=localhost
|
||||||
|
USER_mongo=root
|
||||||
|
PASSWORD_mongo=Pwd2020Db
|
||||||
|
PORT_mongo=16010
|
||||||
|
ENGINE_mongo=mongo@dbgate-plugin-mongo
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ dbgateApi.registerPlugins(dbgatePluginMysql);
|
|||||||
const dbgatePluginPostgres = require('dbgate-plugin-postgres');
|
const dbgatePluginPostgres = require('dbgate-plugin-postgres');
|
||||||
dbgateApi.registerPlugins(dbgatePluginPostgres);
|
dbgateApi.registerPlugins(dbgatePluginPostgres);
|
||||||
|
|
||||||
async function createDb(connection, dropDbSql, createDbSql, database = 'my_guitar_shop') {
|
async function createDb(connection, dropDbSql, createDbSql, database = 'my_guitar_shop', { dropDatabaseName }) {
|
||||||
if (dropDbSql) {
|
if (dropDbSql) {
|
||||||
try {
|
try {
|
||||||
await dbgateApi.executeQuery({
|
await dbgateApi.executeQuery({
|
||||||
connection,
|
connection,
|
||||||
sql: dropDbSql,
|
sql: dropDbSql,
|
||||||
|
database: dropDatabaseName,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to drop database', err);
|
console.error('Failed to drop database', err);
|
||||||
@@ -108,6 +109,22 @@ async function run() {
|
|||||||
null
|
null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (localconfig.mongo) {
|
||||||
|
await createDb(
|
||||||
|
{
|
||||||
|
server: process.env.SERVER_mongo,
|
||||||
|
user: process.env.USER_mongo,
|
||||||
|
password: process.env.PASSWORD_mongo,
|
||||||
|
port: process.env.PORT_mongo,
|
||||||
|
engine: 'mongo@dbgate-plugin-mongo',
|
||||||
|
},
|
||||||
|
'db.dropDatabase()',
|
||||||
|
null,
|
||||||
|
'my_guitar_shop',
|
||||||
|
{ dropDatabaseName: 'my_guitar_shop' }
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dbgateApi.runScript(run);
|
dbgateApi.runScript(run);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ async function importDbFromFolder({ connection, systemConnection, driver, folder
|
|||||||
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
|
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (driver?.databaseEngineTypes?.includes('sql')) {
|
||||||
const model = await importDbModel(folder);
|
const model = await importDbModel(folder);
|
||||||
|
|
||||||
let modelAdapted = {
|
let modelAdapted = {
|
||||||
@@ -100,6 +101,20 @@ async function importDbFromFolder({ connection, systemConnection, driver, folder
|
|||||||
// create foreign keys
|
// create foreign keys
|
||||||
await executeQuery({ connection, systemConnection: dbhan, driver, sql: dmp.s, logScriptItems: true });
|
await executeQuery({ connection, systemConnection: dbhan, driver, sql: dmp.s, logScriptItems: true });
|
||||||
}
|
}
|
||||||
|
} else if (driver?.databaseEngineTypes?.includes('document')) {
|
||||||
|
for (const file of fs.readdirSync(folder)) {
|
||||||
|
if (!file.endsWith('.jsonl')) continue;
|
||||||
|
const pureName = path.parse(file).name;
|
||||||
|
const src = await jsonLinesReader({ fileName: path.join(folder, file) });
|
||||||
|
const dst = await tableWriter({
|
||||||
|
systemConnection: dbhan,
|
||||||
|
pureName,
|
||||||
|
driver,
|
||||||
|
createIfNotExists: true,
|
||||||
|
});
|
||||||
|
await copyStream(src, dst);
|
||||||
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (!systemConnection) {
|
if (!systemConnection) {
|
||||||
await driver.close(dbhan);
|
await driver.close(dbhan);
|
||||||
|
|||||||
Reference in New Issue
Block a user