mysqlsyncr 1.0.0 → 1.0.3

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # MySQLSync
1
+ # MySQLSyncr
2
2
 
3
- MySQLSync is a command-line tool for managing and comparing MySQL database structures with JSON dumps. It allows users to dump the database structure, compare it with existing JSON files, and update the database based on those JSON definitions.
3
+ MySQLSyncr is a command-line tool for managing and comparing MySQL database structures with JSON dumps. It allows users to dump the database structure, compare it with existing JSON files, and update the database based on those JSON definitions.
4
4
 
5
5
  ## Table of Contents
6
6
 
@@ -11,7 +11,7 @@ MySQLSync is a command-line tool for managing and comparing MySQL database struc
11
11
  - [Usage](#usage)
12
12
  - [Commands](#commands)
13
13
  - [Configuration Options](#configuration-options)
14
- - [Using MySQLSync as a Module](#using-mysqlsync-as-a-module)
14
+ - [Using MySQLSyncr as a Module](#using-mysqlsyncr-as-a-module)
15
15
  - [Contributing](#contributing)
16
16
  - [License](#license)
17
17
 
@@ -29,27 +29,27 @@ MySQLSync is a command-line tool for managing and comparing MySQL database struc
29
29
  To install MySQLSync globally, allowing you to use it from the command line, run the following command:
30
30
 
31
31
  ```bash
32
- npm install -g mysqlsync
32
+ npm install -g mysqlsyncr
33
33
  ```
34
34
 
35
- This will allow you to run the command as `mysqlsync` from anywhere in your terminal.
35
+ This will allow you to run the command as `mysqlsyncr` from anywhere in your terminal.
36
36
 
37
37
  ### Local Installation
38
38
 
39
- If you prefer to use MySQLSync locally within a project, you can install it as a dependency:
39
+ If you prefer to use MySQLSyncr locally within a project, you can install it as a dependency:
40
40
 
41
41
  ```bash
42
- npm install mysqlsync
42
+ npm install mysqlsyncr
43
43
  ```
44
44
 
45
- This will add MySQLSync to your project's `node_modules` and allow you to use it within your project.
45
+ This will add MySQLSyncr to your project's `node_modules` and allow you to use it within your project.
46
46
 
47
47
  ## Usage
48
48
 
49
49
  You can run MySQLSync commands using the following syntax:
50
50
 
51
51
  ```bash
52
- mysqlsync <command> [options]
52
+ mysqlsyncr <command> [options]
53
53
  ```
54
54
 
55
55
  ### Commands
@@ -76,17 +76,17 @@ You can configure the following options when running the commands:
76
76
 
77
77
  1. **Dump the database structure**:
78
78
  ```bash
79
- mysqlsync dump --host localhost --user root --password yourpassword
79
+ mysqlsyncr dump --host localhost --user root --password yourpassword
80
80
  ```
81
81
 
82
82
  2. **Compare the database structure with JSON dumps**:
83
83
  ```bash
84
- mysqlsync compare --host localhost --user root --password yourpassword
84
+ mysqlsyncr compare --host localhost --user root --password yourpassword
85
85
  ```
86
86
 
87
87
  3. **Update the database structure based on JSON dumps**:
88
88
  ```bash
89
- mysqlsync update --host localhost --user root --password yourpassword
89
+ mysqlsyncr update --host localhost --user root --password yourpassword
90
90
  ```
91
91
 
92
92
  ## Using MySQLSync as a Module
@@ -94,7 +94,7 @@ You can configure the following options when running the commands:
94
94
  If you want to use MySQLSync as a module in your own Node.js application, you can require it in your code:
95
95
 
96
96
  ```javascript
97
- import mysqlsync from 'mysqlsync';
97
+ import mysqlsyncr from 'mysqlsyncr';
98
98
 
99
99
  // Example usage
100
100
  const config = {
@@ -107,7 +107,7 @@ const config = {
107
107
 
108
108
  ```javascript
109
109
  // app.js
110
- import mysqlsync from 'mysqlsync';
110
+ import mysqlsyncr from 'mysqlsyncr';
111
111
  import fs from 'fs';
112
112
  import path from 'path';
113
113
 
@@ -123,7 +123,7 @@ const config = {
123
123
  async function dumpDatabase() {
124
124
  try {
125
125
  console.log('Dumping the database structure...');
126
- await mysqlsync.dump(config);
126
+ await mysqlsyncr.dump(config);
127
127
  console.log('Database structure dumped successfully.');
128
128
  } catch (error) {
129
129
  console.error('Error dumping database:', error.message);
@@ -135,7 +135,7 @@ async function compareDatabase() {
135
135
  try {
136
136
  const inputDir = path.join(__dirname, 'db-dump'); // Directory where JSON dumps are stored
137
137
  console.log('Comparing the database structure with JSON dumps...');
138
- const differences = await mysqlsync.compare(config, inputDir);
138
+ const differences = await mysqlsyncr.compare(config, inputDir);
139
139
 
140
140
  if (differences.length > 0) {
141
141
  console.log('Differences found:');
@@ -159,7 +159,7 @@ Make sure to check the source code for available functions and their usage.
159
159
 
160
160
  ## Contributing
161
161
 
162
- Contributions are welcome! If you would like to contribute to MySQLSync, please follow these steps:
162
+ Contributions are welcome! If you would like to contribute to MySQLSyncr, please follow these steps:
163
163
 
164
164
  1. Fork the repository.
165
165
  2. Create a new branch for your feature or bug fix.
@@ -167,9 +167,6 @@ Contributions are welcome! If you would like to contribute to MySQLSync, please
167
167
  4. Push your changes to your forked repository.
168
168
  5. Open a pull request to the main repository.
169
169
 
170
- ### Code of Conduct
171
-
172
- Please adhere to the [Code of Conduct](CODE_OF_CONDUCT.md) when contributing to this project.
173
170
 
174
171
  ## License
175
172
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysqlsyncr",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -10,7 +10,7 @@
10
10
  "start": "node src/index.js"
11
11
  },
12
12
  "bin": {
13
- "mysqlsync": "src/index.js"
13
+ "mysqlsyncr": "src/index.js"
14
14
  },
15
15
  "author": "",
16
16
  "license": "ISC",
package/src/compare.js CHANGED
@@ -16,15 +16,22 @@ export const compareAllDatabases = async (connection, inputDir, update = false,
16
16
  // Check existing databases
17
17
  const existingDatabases = await getDatabases(connection);
18
18
  // console.log('Existing databases:', existingDatabases);
19
-
19
+ const allDifferences = {};
20
20
  const missingDatabases = [];
21
+ console.log('All differences:', allDifferences);
21
22
 
22
23
  // Note missing databases and prepare to create them
23
24
  for (const database of expectedDatabases) {
24
25
  if(options.database && options.database !== database){
25
26
  continue;
26
27
  }
28
+
27
29
  if (!existingDatabases.includes(database)) {
30
+ allDifferences[database] = [{
31
+ database: database,
32
+ type: 'missing_database',
33
+ message: 'Database not found'
34
+ }];
28
35
  missingDatabases.push(database);
29
36
  }
30
37
  }
@@ -42,12 +49,10 @@ export const compareAllDatabases = async (connection, inputDir, update = false,
42
49
  console.error('Please run the command again with the --update flag to create missing databases.');
43
50
  console.error('Missing databases:');
44
51
  console.error(missingDatabases);
45
- return;
46
52
  } else {
47
53
  console.log('All expected databases exist.');
48
54
  }
49
55
 
50
- const allDifferences = {};
51
56
  for (const database of expectedDatabases) {
52
57
  if(options.database && options.database !== database){
53
58
  continue;
@@ -75,6 +80,5 @@ export const compareAllDatabases = async (connection, inputDir, update = false,
75
80
  console.error(`Error processing database ${database}:`, err.message);
76
81
  }
77
82
  }
78
-
79
83
  return allDifferences;
80
84
  }
package/src/index.js CHANGED
@@ -1,12 +1,8 @@
1
- #!/usr/bin/env node
2
-
3
- //TODO
4
-
5
- //1. Check constraints in tables
6
- //2. fix index recognition
1
+ #!/usr/bin/env node
7
2
 
8
3
  import mysql from 'mysql2';
9
4
  import util from 'util';
5
+ import fs from 'fs';
10
6
 
11
7
  import { cli } from './cli.js';
12
8
  import { dumpAllDatabases } from './dump.js';
@@ -58,6 +54,7 @@ class DBStructureChecker {
58
54
  let diffs = await compareAllDatabases(checker.connection, argv.output, false, command, argv); // Dry run
59
55
  let totalDiffs = Object.values(diffs).reduce((acc, arr) => acc + arr.length, 0);
60
56
  console.log('Total differences count:', totalDiffs);
57
+ fs.writeFileSync(argv.output + '/diffs.json', JSON.stringify(diffs, null, 4));
61
58
  } else if (command === 'update') {
62
59
  console.log('Updating the database structure based on JSON dumps');
63
60
  let totalDiffs = Infinity; // Initialize with a large number