mysqlsyncr 1.0.48 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/import.js +20 -0
- package/__tests__/import.test.js +27 -0
- package/package.json +3 -2
- package/src/compare.js +2 -0
- package/src/dump.js +3 -3
- package/src/index.js +22 -4
- package/src/socketServer.js +4 -2
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { compare } from '../src/index.js';
|
|
2
|
+
const dotenv = await import('dotenv');
|
|
3
|
+
dotenv.config( { path: '../.env' } );
|
|
4
|
+
console.log(`DB_STRUCTURE_PATH: ${process.env.DB_STRUCTURE_PATH}`);
|
|
5
|
+
console.log(`DB_PASSWORD: ${process.env.DB_PASSWORD}`);
|
|
6
|
+
const config ={
|
|
7
|
+
host: "127.0.0.1",
|
|
8
|
+
user: 'root',
|
|
9
|
+
password: process.env.DB_PASSWORD,
|
|
10
|
+
port: 3306
|
|
11
|
+
};
|
|
12
|
+
const testDbConnection = async () => {
|
|
13
|
+
|
|
14
|
+
const diffs = await compare(config, process.env.DB_STRUCTURE_PATH);
|
|
15
|
+
console.log(diffs);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
testDbConnection();
|
|
19
|
+
|
|
20
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const { DBStructureChecker, compareAllDatabases } = import('../src/index.js');
|
|
2
|
+
const dotenv = require('dotenv');
|
|
3
|
+
dotenv.config();
|
|
4
|
+
const config ={
|
|
5
|
+
host: "127.0.0.1",
|
|
6
|
+
user: 'root',
|
|
7
|
+
password: process.env.DB_PASSWORD,
|
|
8
|
+
port: 3306
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
describe('Connect to database', () => {
|
|
12
|
+
|
|
13
|
+
test('should run a comparison of the DB structure', async () => {
|
|
14
|
+
const checker = new DBStructureChecker(config);
|
|
15
|
+
|
|
16
|
+
const diffs = await compareAllDatabases(
|
|
17
|
+
checker.connection,
|
|
18
|
+
process.env.DB_STRUCTURE_PATH,
|
|
19
|
+
false,
|
|
20
|
+
'compare'
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
expect(Array.isArray(diffs)).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mysqlsyncr",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.50",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@babel/preset-env": "^7.26.0",
|
|
30
30
|
"babel-jest": "^29.7.0",
|
|
31
|
-
"jest": "^29.0.0"
|
|
31
|
+
"jest": "^29.0.0",
|
|
32
|
+
"dotenv": "^16.4.5"
|
|
32
33
|
},
|
|
33
34
|
"babel": {
|
|
34
35
|
"presets": [
|
package/src/compare.js
CHANGED
|
@@ -13,6 +13,8 @@ export const compareAllDatabases = async (connection, inputDir, update = false,
|
|
|
13
13
|
let expectedDatabases = await fs.readdir(inputDir);
|
|
14
14
|
//filter out diffs.json
|
|
15
15
|
expectedDatabases = expectedDatabases.filter(file => file !== 'diffs.json');
|
|
16
|
+
//filter out dumpInfo.json
|
|
17
|
+
expectedDatabases = expectedDatabases.filter(file => file !== 'dumpInfo.json');
|
|
16
18
|
// console.log('Expected databases from input directory:', expectedDatabases);
|
|
17
19
|
|
|
18
20
|
// Check existing databases
|
package/src/dump.js
CHANGED
|
@@ -3,8 +3,8 @@ import fs from 'fs/promises';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { getDatabases, getDatabaseStructure } from './getters.js';
|
|
5
5
|
|
|
6
|
-
const require = createRequire(import.meta.url);
|
|
7
|
-
const { version } = require('../package.json');
|
|
6
|
+
// const require = createRequire(import.meta.url);
|
|
7
|
+
// const { version } = require('../package.json');
|
|
8
8
|
|
|
9
9
|
export const dumpAllDatabases = async (connection, command, options) => {
|
|
10
10
|
let response = {}
|
|
@@ -21,7 +21,7 @@ export const dumpAllDatabases = async (connection, command, options) => {
|
|
|
21
21
|
response[database] = dbStructure;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
await fs.writeFile(path.join(options.output, 'dumpInfo.json'), JSON.stringify({timestamp: new Date().toISOString()
|
|
24
|
+
await fs.writeFile(path.join(options.output, 'dumpInfo.json'), JSON.stringify({timestamp: new Date().toISOString()}, null, 4), 'utf-8');
|
|
25
25
|
return response;
|
|
26
26
|
}
|
|
27
27
|
|
package/src/index.js
CHANGED
|
@@ -45,16 +45,34 @@ class DBStructureChecker {
|
|
|
45
45
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
const compare = async (config, output) => {
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
try {
|
|
51
|
+
const checker = new DBStructureChecker(config);
|
|
52
|
+
checker.connection.on('connect', async () => {
|
|
53
|
+
const diffs = await compareAllDatabases(checker.connection, output, false, 'compare', {output: output});
|
|
54
|
+
resolve(diffs);
|
|
55
|
+
});
|
|
56
|
+
} catch (e) {
|
|
57
|
+
reject(e);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
48
62
|
// Export the DBStructureChecker class
|
|
49
|
-
export { DBStructureChecker, dumpAllDatabases,
|
|
63
|
+
export { DBStructureChecker, dumpAllDatabases, compare, startApiServer };
|
|
50
64
|
|
|
51
65
|
// Only run this if this is the main module
|
|
52
|
-
const isMain =
|
|
66
|
+
const isMain = (() => {
|
|
67
|
+
try {
|
|
68
|
+
return require.main === module;
|
|
69
|
+
} catch (e) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
})();
|
|
53
73
|
|
|
54
74
|
if (isMain) {
|
|
55
75
|
(async () => {
|
|
56
|
-
console.log(`meta: ${import.meta.url}`)
|
|
57
|
-
console.log(`argv: ${process.argv[1]}`)
|
|
58
76
|
const { command, config, argv } = cli();
|
|
59
77
|
console.log("MySQLsyncr started via command line")
|
|
60
78
|
if (command === 'ui') {
|
package/src/socketServer.js
CHANGED
|
@@ -36,8 +36,10 @@ export const startApiServer = (port, argv) => {
|
|
|
36
36
|
app.use(express.json({ limit: '50mb' }));
|
|
37
37
|
app.use(express.urlencoded({ limit: '50mb', extended: true }));
|
|
38
38
|
|
|
39
|
-
const
|
|
40
|
-
|
|
39
|
+
const __dirname = process.platform === "win32"
|
|
40
|
+
? process.cwd().replace(/\\/g, '/')
|
|
41
|
+
: process.cwd();
|
|
42
|
+
|
|
41
43
|
app.use(express.static(join(__dirname, '../ui/dist/spa')));
|
|
42
44
|
|
|
43
45
|
app.post('/api/getDatabasesFromExistingDumps', async (req, res) => {
|