2023-02-17 08:15:13 +00:00
|
|
|
const engines = require('../engines');
|
2023-02-17 08:27:16 +00:00
|
|
|
const stream = require('stream');
|
2023-02-17 08:15:13 +00:00
|
|
|
const { testWrapper } = require('../tools');
|
|
|
|
const dataDuplicator = require('dbgate-api/src/shell/dataDuplicator');
|
2023-02-17 08:27:16 +00:00
|
|
|
const { runCommandOnDriver } = require('dbgate-tools');
|
2023-02-17 08:15:13 +00:00
|
|
|
|
|
|
|
describe('Data duplicator', () => {
|
2024-09-13 13:24:29 +00:00
|
|
|
test.each(engines.filter(x => !x.skipDataDuplicator).map(engine => [engine.label, engine]))(
|
2023-02-17 08:15:13 +00:00
|
|
|
'Insert simple data - %s',
|
|
|
|
testWrapper(async (conn, driver, engine) => {
|
2023-02-17 08:27:16 +00:00
|
|
|
runCommandOnDriver(conn, driver, dmp =>
|
|
|
|
dmp.createTable({
|
|
|
|
pureName: 't1',
|
|
|
|
columns: [
|
|
|
|
{ columnName: 'id', dataType: 'int', autoIncrement: true, notNull: true },
|
|
|
|
{ columnName: 'val', dataType: 'varchar(50)' },
|
|
|
|
],
|
|
|
|
primaryKey: {
|
|
|
|
columns: [{ columnName: 'id' }],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
runCommandOnDriver(conn, driver, dmp =>
|
|
|
|
dmp.createTable({
|
|
|
|
pureName: 't2',
|
|
|
|
columns: [
|
|
|
|
{ columnName: 'id', dataType: 'int', autoIncrement: true, notNull: true },
|
|
|
|
{ columnName: 'val', dataType: 'varchar(50)' },
|
|
|
|
{ columnName: 'valfk', dataType: 'int', notNull: true },
|
|
|
|
],
|
|
|
|
primaryKey: {
|
|
|
|
columns: [{ columnName: 'id' }],
|
|
|
|
},
|
|
|
|
foreignKeys: [{ refTableName: 't1', columns: [{ columnName: 'valfk', refColumnName: 'id' }] }],
|
|
|
|
})
|
|
|
|
);
|
2023-02-17 08:15:13 +00:00
|
|
|
|
2023-02-17 08:27:16 +00:00
|
|
|
const gett1 = () =>
|
|
|
|
stream.Readable.from([
|
|
|
|
{ __isStreamHeader: true, __isDynamicStructure: true },
|
2023-02-17 08:15:13 +00:00
|
|
|
{ id: 1, val: 'v1' },
|
|
|
|
{ id: 2, val: 'v2' },
|
|
|
|
{ id: 3, val: 'v3' },
|
2023-02-17 08:27:16 +00:00
|
|
|
]);
|
|
|
|
const gett2 = () =>
|
|
|
|
stream.Readable.from([
|
|
|
|
{ __isStreamHeader: true, __isDynamicStructure: true },
|
2023-02-17 08:15:13 +00:00
|
|
|
{ id: 1, val: 'v1', valfk: 1 },
|
|
|
|
{ id: 2, val: 'v2', valfk: 2 },
|
|
|
|
{ id: 3, val: 'v3', valfk: 3 },
|
2023-02-17 08:27:16 +00:00
|
|
|
]);
|
2023-02-17 08:15:13 +00:00
|
|
|
|
|
|
|
await dataDuplicator({
|
|
|
|
systemConnection: conn,
|
|
|
|
driver,
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
name: 't1',
|
|
|
|
operation: 'copy',
|
2023-02-17 08:27:16 +00:00
|
|
|
openStream: gett1,
|
2023-02-17 08:15:13 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 't2',
|
|
|
|
operation: 'copy',
|
2023-02-17 08:27:16 +00:00
|
|
|
openStream: gett2,
|
2023-02-17 08:15:13 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
await dataDuplicator({
|
|
|
|
systemConnection: conn,
|
|
|
|
driver,
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
name: 't1',
|
|
|
|
operation: 'copy',
|
2023-02-17 08:27:16 +00:00
|
|
|
openStream: gett1,
|
2023-02-17 08:15:13 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 't2',
|
|
|
|
operation: 'copy',
|
2023-02-17 08:27:16 +00:00
|
|
|
openStream: gett2,
|
2023-02-17 08:15:13 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const res1 = await driver.query(conn, `select count(*) as cnt from t1`);
|
|
|
|
expect(res1.rows[0].cnt.toString()).toEqual('6');
|
|
|
|
|
|
|
|
const res2 = await driver.query(conn, `select count(*) as cnt from t2`);
|
|
|
|
expect(res2.rows[0].cnt.toString()).toEqual('6');
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|