mysqlsyncr 1.0.94 → 1.0.96
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/dist/index.cjs +32 -32
- package/dist/index.js +32 -32
- package/package.json +1 -1
- package/src/apply.js +7 -7
- package/src/compare.js +19 -19
- package/src/differences.js +3 -3
- package/src/dump.js +4 -3
- package/src/getters.js +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2927,7 +2927,7 @@ var getDatabaseStructure = /*#__PURE__*/function () {
|
|
|
2927
2927
|
_context2.next = 106;
|
|
2928
2928
|
break;
|
|
2929
2929
|
case 105:
|
|
2930
|
-
|
|
2930
|
+
logger("Trigger ".concat(triggerName, " has no action statement."));
|
|
2931
2931
|
case 106:
|
|
2932
2932
|
_context2.next = 85;
|
|
2933
2933
|
break;
|
|
@@ -3092,7 +3092,7 @@ var getDatabasesFromExistingDumps = /*#__PURE__*/function () {
|
|
|
3092
3092
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
3093
3093
|
while (1) switch (_context2.prev = _context2.next) {
|
|
3094
3094
|
case 0:
|
|
3095
|
-
|
|
3095
|
+
logger('Getting databases from existing dumps in ', options.output);
|
|
3096
3096
|
//check if the folder exists
|
|
3097
3097
|
_context2.next = 3;
|
|
3098
3098
|
return fs$1.stat(options.output)["catch"](function () {
|
|
@@ -3104,7 +3104,7 @@ var getDatabasesFromExistingDumps = /*#__PURE__*/function () {
|
|
|
3104
3104
|
_context2.next = 7;
|
|
3105
3105
|
break;
|
|
3106
3106
|
}
|
|
3107
|
-
|
|
3107
|
+
logger('Folder does not exist');
|
|
3108
3108
|
return _context2.abrupt("return", {});
|
|
3109
3109
|
case 7:
|
|
3110
3110
|
//read directory above to get the dbs. each db is in a named folder with a matching .json.
|
|
@@ -3127,7 +3127,7 @@ var getDatabasesFromExistingDumps = /*#__PURE__*/function () {
|
|
|
3127
3127
|
_context2.next = 19;
|
|
3128
3128
|
break;
|
|
3129
3129
|
}
|
|
3130
|
-
|
|
3130
|
+
logger('Skipping diffs folder');
|
|
3131
3131
|
return _context2.abrupt("continue", 23);
|
|
3132
3132
|
case 19:
|
|
3133
3133
|
_context2.next = 21;
|
|
@@ -3199,7 +3199,7 @@ var findDifferences = function findDifferences(expected, current) {
|
|
|
3199
3199
|
contents.charset;
|
|
3200
3200
|
contents.collate;
|
|
3201
3201
|
if (!current.tables[_tableName]) {
|
|
3202
|
-
|
|
3202
|
+
logger('missing_table', contents);
|
|
3203
3203
|
differences.push({
|
|
3204
3204
|
type: 'missing_table',
|
|
3205
3205
|
tableName: _tableName,
|
|
@@ -3273,7 +3273,7 @@ var findDifferences = function findDifferences(expected, current) {
|
|
|
3273
3273
|
_iterator2.f();
|
|
3274
3274
|
}
|
|
3275
3275
|
} catch (e) {
|
|
3276
|
-
|
|
3276
|
+
logger("Error verifying triggers for table ".concat(_tableName), e);
|
|
3277
3277
|
}
|
|
3278
3278
|
var createTableSql = current.tables[_tableName].createSQL;
|
|
3279
3279
|
if (createTableSql === contents.createSQL) {
|
|
@@ -3330,7 +3330,7 @@ var findDifferences = function findDifferences(expected, current) {
|
|
|
3330
3330
|
return f.Field === field.Field;
|
|
3331
3331
|
});
|
|
3332
3332
|
if (!currentField) {
|
|
3333
|
-
|
|
3333
|
+
logger('Current field not found for', field.Field, 'in table', _tableName);
|
|
3334
3334
|
differences.push({
|
|
3335
3335
|
type: 'missing_field',
|
|
3336
3336
|
tableName: _tableName,
|
|
@@ -3652,7 +3652,7 @@ var applyDifferences$1 = /*#__PURE__*/function () {
|
|
|
3652
3652
|
}
|
|
3653
3653
|
// Step 1: Add column with DEFAULT NULL to handle existing records
|
|
3654
3654
|
addFieldSQL = "ALTER TABLE `".concat(diff.tableName, "` ADD `").concat(diff.field.Field, "` ").concat(diff.field.Type, " DEFAULT NULL;");
|
|
3655
|
-
|
|
3655
|
+
logger("Executing: ".concat(addFieldSQL));
|
|
3656
3656
|
_context.next = 32;
|
|
3657
3657
|
return connection.query(addFieldSQL);
|
|
3658
3658
|
case 32:
|
|
@@ -3661,7 +3661,7 @@ var applyDifferences$1 = /*#__PURE__*/function () {
|
|
|
3661
3661
|
break;
|
|
3662
3662
|
}
|
|
3663
3663
|
modifyFieldSQL = "ALTER TABLE `".concat(diff.tableName, "` MODIFY `").concat(diff.field.Field, "` ").concat(diff.field.Type, " NOT NULL;");
|
|
3664
|
-
|
|
3664
|
+
logger("Executing: ".concat(modifyFieldSQL));
|
|
3665
3665
|
_context.next = 37;
|
|
3666
3666
|
return connection.query(modifyFieldSQL);
|
|
3667
3667
|
case 37:
|
|
@@ -3671,7 +3671,7 @@ var applyDifferences$1 = /*#__PURE__*/function () {
|
|
|
3671
3671
|
}
|
|
3672
3672
|
defaultClause = diff.field.Default === 'CURRENT_TIMESTAMP' ? 'DEFAULT CURRENT_TIMESTAMP' : diff.field.Default !== undefined && diff.field.Default !== null ? "DEFAULT '".concat(diff.field.Default, "'") : '';
|
|
3673
3673
|
_modifyFieldSQL = "ALTER TABLE `".concat(diff.tableName, "` MODIFY `").concat(diff.field.Field, "` ").concat(diff.field.Type, " ").concat(defaultClause, ";");
|
|
3674
|
-
|
|
3674
|
+
logger("Executing: ".concat(_modifyFieldSQL));
|
|
3675
3675
|
_context.next = 43;
|
|
3676
3676
|
return connection.query(_modifyFieldSQL);
|
|
3677
3677
|
case 43:
|
|
@@ -3910,8 +3910,8 @@ var applyDifferences$1 = /*#__PURE__*/function () {
|
|
|
3910
3910
|
break;
|
|
3911
3911
|
}
|
|
3912
3912
|
createTriggerSQL = diff.trigger.Definition;
|
|
3913
|
-
|
|
3914
|
-
|
|
3913
|
+
logger('fixing trigger', diff.trigger.Name);
|
|
3914
|
+
logger("Executing: ".concat(createTriggerSQL));
|
|
3915
3915
|
_context.next = 181;
|
|
3916
3916
|
return connection.query(createTriggerSQL);
|
|
3917
3917
|
case 181:
|
|
@@ -3928,7 +3928,7 @@ var applyDifferences$1 = /*#__PURE__*/function () {
|
|
|
3928
3928
|
return connection.query(dropTriggerSQL);
|
|
3929
3929
|
case 188:
|
|
3930
3930
|
_createTriggerSQL = diff.trigger.Definition;
|
|
3931
|
-
|
|
3931
|
+
logger("Executing: ".concat(_createTriggerSQL));
|
|
3932
3932
|
_context.next = 192;
|
|
3933
3933
|
return connection.query(_createTriggerSQL);
|
|
3934
3934
|
case 192:
|
|
@@ -3951,7 +3951,7 @@ var applyDifferences$1 = /*#__PURE__*/function () {
|
|
|
3951
3951
|
_context.next = 209;
|
|
3952
3952
|
break;
|
|
3953
3953
|
}
|
|
3954
|
-
|
|
3954
|
+
logger('fixing missing database', diff.database);
|
|
3955
3955
|
_createDatabaseSQL = "CREATE DATABASE `".concat(diff.database, "`;");
|
|
3956
3956
|
logger("Executing: ".concat(_createDatabaseSQL));
|
|
3957
3957
|
_context.next = 207;
|
|
@@ -4062,7 +4062,7 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4062
4062
|
expectedDatabases = expectedDatabases.filter(function (file) {
|
|
4063
4063
|
return file !== 'dumpInfo.json';
|
|
4064
4064
|
});
|
|
4065
|
-
|
|
4065
|
+
logger('Expected databases from input directory:', expectedDatabases);
|
|
4066
4066
|
|
|
4067
4067
|
// Check existing databases
|
|
4068
4068
|
_context.next = 14;
|
|
@@ -4072,7 +4072,7 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4072
4072
|
// console.log('Existing databases:', existingDatabases);
|
|
4073
4073
|
allDifferences = {};
|
|
4074
4074
|
missingDatabases = [];
|
|
4075
|
-
|
|
4075
|
+
logger('All differences:', allDifferences);
|
|
4076
4076
|
|
|
4077
4077
|
// Note missing databases and prepare to create them
|
|
4078
4078
|
_iterator = _createForOfIteratorHelper(expectedDatabases);
|
|
@@ -4117,7 +4117,7 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4117
4117
|
_context.next = 59;
|
|
4118
4118
|
break;
|
|
4119
4119
|
}
|
|
4120
|
-
|
|
4120
|
+
logger('Creating missing databases:');
|
|
4121
4121
|
_iterator2 = _createForOfIteratorHelper(missingDatabases);
|
|
4122
4122
|
_context.prev = 39;
|
|
4123
4123
|
_iterator2.s();
|
|
@@ -4127,11 +4127,11 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4127
4127
|
break;
|
|
4128
4128
|
}
|
|
4129
4129
|
database = _step2.value;
|
|
4130
|
-
|
|
4130
|
+
logger("Creating database ".concat(database, "..."));
|
|
4131
4131
|
_context.next = 46;
|
|
4132
4132
|
return connection.query("CREATE DATABASE `".concat(database, "`;"));
|
|
4133
4133
|
case 46:
|
|
4134
|
-
|
|
4134
|
+
logger("Database ".concat(database, " created."));
|
|
4135
4135
|
case 47:
|
|
4136
4136
|
_context.next = 41;
|
|
4137
4137
|
break;
|
|
@@ -4151,12 +4151,12 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4151
4151
|
break;
|
|
4152
4152
|
case 59:
|
|
4153
4153
|
if (missingDatabases.length > 0 && !update) {
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4154
|
+
logger('Missing databases found but update is not enabled. Please enable update to create missing databases.');
|
|
4155
|
+
logger('Please run the command again with the --update flag to create missing databases.');
|
|
4156
|
+
logger('Missing databases:');
|
|
4157
|
+
logger(missingDatabases);
|
|
4158
4158
|
} else {
|
|
4159
|
-
|
|
4159
|
+
logger('All expected databases exist.');
|
|
4160
4160
|
}
|
|
4161
4161
|
case 60:
|
|
4162
4162
|
_iterator3 = _createForOfIteratorHelper(expectedDatabases);
|
|
@@ -4178,7 +4178,7 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4178
4178
|
_context.next = 70;
|
|
4179
4179
|
break;
|
|
4180
4180
|
}
|
|
4181
|
-
|
|
4181
|
+
logger('Skipping database', _database2, 'because it is missing');
|
|
4182
4182
|
return _context.abrupt("continue", 99);
|
|
4183
4183
|
case 70:
|
|
4184
4184
|
filePath = path.join(inputDir, _database2, "".concat(_database2, ".json"));
|
|
@@ -4188,26 +4188,26 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4188
4188
|
case 74:
|
|
4189
4189
|
fileContent = _context.sent;
|
|
4190
4190
|
expectedStructure = JSON.parse(fileContent);
|
|
4191
|
-
|
|
4191
|
+
logger('Getting database structure for', _database2);
|
|
4192
4192
|
_context.next = 79;
|
|
4193
4193
|
return getDatabaseStructure(connection, _database2, command, options);
|
|
4194
4194
|
case 79:
|
|
4195
4195
|
currentStructure = _context.sent;
|
|
4196
|
-
|
|
4196
|
+
logger('Database structure for', _database2, 'obtained');
|
|
4197
4197
|
differences = findDifferences(expectedStructure, currentStructure);
|
|
4198
|
-
|
|
4198
|
+
logger('Differences for', _database2, 'obtained');
|
|
4199
4199
|
if (update) {
|
|
4200
4200
|
_context.next = 88;
|
|
4201
4201
|
break;
|
|
4202
4202
|
}
|
|
4203
|
-
|
|
4203
|
+
logger('Logging differences for', _database2);
|
|
4204
4204
|
logDifferences(differences, _database2, true);
|
|
4205
4205
|
_context.next = 93;
|
|
4206
4206
|
break;
|
|
4207
4207
|
case 88:
|
|
4208
|
-
|
|
4208
|
+
logger('Logging differences for', _database2);
|
|
4209
4209
|
logDifferences(differences, _database2, false);
|
|
4210
|
-
|
|
4210
|
+
logger('Applying differences for', _database2);
|
|
4211
4211
|
_context.next = 93;
|
|
4212
4212
|
return applyDifferences$1(connection, _database2, differences);
|
|
4213
4213
|
case 93:
|
|
@@ -4217,7 +4217,7 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4217
4217
|
case 96:
|
|
4218
4218
|
_context.prev = 96;
|
|
4219
4219
|
_context.t2 = _context["catch"](71);
|
|
4220
|
-
|
|
4220
|
+
logger("Error processing database ".concat(_database2, ":"), _context.t2.message);
|
|
4221
4221
|
case 99:
|
|
4222
4222
|
_context.next = 63;
|
|
4223
4223
|
break;
|
package/dist/index.js
CHANGED
|
@@ -2924,7 +2924,7 @@ var getDatabaseStructure = /*#__PURE__*/function () {
|
|
|
2924
2924
|
_context2.next = 106;
|
|
2925
2925
|
break;
|
|
2926
2926
|
case 105:
|
|
2927
|
-
|
|
2927
|
+
logger("Trigger ".concat(triggerName, " has no action statement."));
|
|
2928
2928
|
case 106:
|
|
2929
2929
|
_context2.next = 85;
|
|
2930
2930
|
break;
|
|
@@ -3089,7 +3089,7 @@ var getDatabasesFromExistingDumps = /*#__PURE__*/function () {
|
|
|
3089
3089
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
3090
3090
|
while (1) switch (_context2.prev = _context2.next) {
|
|
3091
3091
|
case 0:
|
|
3092
|
-
|
|
3092
|
+
logger('Getting databases from existing dumps in ', options.output);
|
|
3093
3093
|
//check if the folder exists
|
|
3094
3094
|
_context2.next = 3;
|
|
3095
3095
|
return fs.stat(options.output)["catch"](function () {
|
|
@@ -3101,7 +3101,7 @@ var getDatabasesFromExistingDumps = /*#__PURE__*/function () {
|
|
|
3101
3101
|
_context2.next = 7;
|
|
3102
3102
|
break;
|
|
3103
3103
|
}
|
|
3104
|
-
|
|
3104
|
+
logger('Folder does not exist');
|
|
3105
3105
|
return _context2.abrupt("return", {});
|
|
3106
3106
|
case 7:
|
|
3107
3107
|
//read directory above to get the dbs. each db is in a named folder with a matching .json.
|
|
@@ -3124,7 +3124,7 @@ var getDatabasesFromExistingDumps = /*#__PURE__*/function () {
|
|
|
3124
3124
|
_context2.next = 19;
|
|
3125
3125
|
break;
|
|
3126
3126
|
}
|
|
3127
|
-
|
|
3127
|
+
logger('Skipping diffs folder');
|
|
3128
3128
|
return _context2.abrupt("continue", 23);
|
|
3129
3129
|
case 19:
|
|
3130
3130
|
_context2.next = 21;
|
|
@@ -3196,7 +3196,7 @@ var findDifferences = function findDifferences(expected, current) {
|
|
|
3196
3196
|
contents.charset;
|
|
3197
3197
|
contents.collate;
|
|
3198
3198
|
if (!current.tables[_tableName]) {
|
|
3199
|
-
|
|
3199
|
+
logger('missing_table', contents);
|
|
3200
3200
|
differences.push({
|
|
3201
3201
|
type: 'missing_table',
|
|
3202
3202
|
tableName: _tableName,
|
|
@@ -3270,7 +3270,7 @@ var findDifferences = function findDifferences(expected, current) {
|
|
|
3270
3270
|
_iterator2.f();
|
|
3271
3271
|
}
|
|
3272
3272
|
} catch (e) {
|
|
3273
|
-
|
|
3273
|
+
logger("Error verifying triggers for table ".concat(_tableName), e);
|
|
3274
3274
|
}
|
|
3275
3275
|
var createTableSql = current.tables[_tableName].createSQL;
|
|
3276
3276
|
if (createTableSql === contents.createSQL) {
|
|
@@ -3327,7 +3327,7 @@ var findDifferences = function findDifferences(expected, current) {
|
|
|
3327
3327
|
return f.Field === field.Field;
|
|
3328
3328
|
});
|
|
3329
3329
|
if (!currentField) {
|
|
3330
|
-
|
|
3330
|
+
logger('Current field not found for', field.Field, 'in table', _tableName);
|
|
3331
3331
|
differences.push({
|
|
3332
3332
|
type: 'missing_field',
|
|
3333
3333
|
tableName: _tableName,
|
|
@@ -3649,7 +3649,7 @@ var applyDifferences$1 = /*#__PURE__*/function () {
|
|
|
3649
3649
|
}
|
|
3650
3650
|
// Step 1: Add column with DEFAULT NULL to handle existing records
|
|
3651
3651
|
addFieldSQL = "ALTER TABLE `".concat(diff.tableName, "` ADD `").concat(diff.field.Field, "` ").concat(diff.field.Type, " DEFAULT NULL;");
|
|
3652
|
-
|
|
3652
|
+
logger("Executing: ".concat(addFieldSQL));
|
|
3653
3653
|
_context.next = 32;
|
|
3654
3654
|
return connection.query(addFieldSQL);
|
|
3655
3655
|
case 32:
|
|
@@ -3658,7 +3658,7 @@ var applyDifferences$1 = /*#__PURE__*/function () {
|
|
|
3658
3658
|
break;
|
|
3659
3659
|
}
|
|
3660
3660
|
modifyFieldSQL = "ALTER TABLE `".concat(diff.tableName, "` MODIFY `").concat(diff.field.Field, "` ").concat(diff.field.Type, " NOT NULL;");
|
|
3661
|
-
|
|
3661
|
+
logger("Executing: ".concat(modifyFieldSQL));
|
|
3662
3662
|
_context.next = 37;
|
|
3663
3663
|
return connection.query(modifyFieldSQL);
|
|
3664
3664
|
case 37:
|
|
@@ -3668,7 +3668,7 @@ var applyDifferences$1 = /*#__PURE__*/function () {
|
|
|
3668
3668
|
}
|
|
3669
3669
|
defaultClause = diff.field.Default === 'CURRENT_TIMESTAMP' ? 'DEFAULT CURRENT_TIMESTAMP' : diff.field.Default !== undefined && diff.field.Default !== null ? "DEFAULT '".concat(diff.field.Default, "'") : '';
|
|
3670
3670
|
_modifyFieldSQL = "ALTER TABLE `".concat(diff.tableName, "` MODIFY `").concat(diff.field.Field, "` ").concat(diff.field.Type, " ").concat(defaultClause, ";");
|
|
3671
|
-
|
|
3671
|
+
logger("Executing: ".concat(_modifyFieldSQL));
|
|
3672
3672
|
_context.next = 43;
|
|
3673
3673
|
return connection.query(_modifyFieldSQL);
|
|
3674
3674
|
case 43:
|
|
@@ -3907,8 +3907,8 @@ var applyDifferences$1 = /*#__PURE__*/function () {
|
|
|
3907
3907
|
break;
|
|
3908
3908
|
}
|
|
3909
3909
|
createTriggerSQL = diff.trigger.Definition;
|
|
3910
|
-
|
|
3911
|
-
|
|
3910
|
+
logger('fixing trigger', diff.trigger.Name);
|
|
3911
|
+
logger("Executing: ".concat(createTriggerSQL));
|
|
3912
3912
|
_context.next = 181;
|
|
3913
3913
|
return connection.query(createTriggerSQL);
|
|
3914
3914
|
case 181:
|
|
@@ -3925,7 +3925,7 @@ var applyDifferences$1 = /*#__PURE__*/function () {
|
|
|
3925
3925
|
return connection.query(dropTriggerSQL);
|
|
3926
3926
|
case 188:
|
|
3927
3927
|
_createTriggerSQL = diff.trigger.Definition;
|
|
3928
|
-
|
|
3928
|
+
logger("Executing: ".concat(_createTriggerSQL));
|
|
3929
3929
|
_context.next = 192;
|
|
3930
3930
|
return connection.query(_createTriggerSQL);
|
|
3931
3931
|
case 192:
|
|
@@ -3948,7 +3948,7 @@ var applyDifferences$1 = /*#__PURE__*/function () {
|
|
|
3948
3948
|
_context.next = 209;
|
|
3949
3949
|
break;
|
|
3950
3950
|
}
|
|
3951
|
-
|
|
3951
|
+
logger('fixing missing database', diff.database);
|
|
3952
3952
|
_createDatabaseSQL = "CREATE DATABASE `".concat(diff.database, "`;");
|
|
3953
3953
|
logger("Executing: ".concat(_createDatabaseSQL));
|
|
3954
3954
|
_context.next = 207;
|
|
@@ -4059,7 +4059,7 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4059
4059
|
expectedDatabases = expectedDatabases.filter(function (file) {
|
|
4060
4060
|
return file !== 'dumpInfo.json';
|
|
4061
4061
|
});
|
|
4062
|
-
|
|
4062
|
+
logger('Expected databases from input directory:', expectedDatabases);
|
|
4063
4063
|
|
|
4064
4064
|
// Check existing databases
|
|
4065
4065
|
_context.next = 14;
|
|
@@ -4069,7 +4069,7 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4069
4069
|
// console.log('Existing databases:', existingDatabases);
|
|
4070
4070
|
allDifferences = {};
|
|
4071
4071
|
missingDatabases = [];
|
|
4072
|
-
|
|
4072
|
+
logger('All differences:', allDifferences);
|
|
4073
4073
|
|
|
4074
4074
|
// Note missing databases and prepare to create them
|
|
4075
4075
|
_iterator = _createForOfIteratorHelper(expectedDatabases);
|
|
@@ -4114,7 +4114,7 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4114
4114
|
_context.next = 59;
|
|
4115
4115
|
break;
|
|
4116
4116
|
}
|
|
4117
|
-
|
|
4117
|
+
logger('Creating missing databases:');
|
|
4118
4118
|
_iterator2 = _createForOfIteratorHelper(missingDatabases);
|
|
4119
4119
|
_context.prev = 39;
|
|
4120
4120
|
_iterator2.s();
|
|
@@ -4124,11 +4124,11 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4124
4124
|
break;
|
|
4125
4125
|
}
|
|
4126
4126
|
database = _step2.value;
|
|
4127
|
-
|
|
4127
|
+
logger("Creating database ".concat(database, "..."));
|
|
4128
4128
|
_context.next = 46;
|
|
4129
4129
|
return connection.query("CREATE DATABASE `".concat(database, "`;"));
|
|
4130
4130
|
case 46:
|
|
4131
|
-
|
|
4131
|
+
logger("Database ".concat(database, " created."));
|
|
4132
4132
|
case 47:
|
|
4133
4133
|
_context.next = 41;
|
|
4134
4134
|
break;
|
|
@@ -4148,12 +4148,12 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4148
4148
|
break;
|
|
4149
4149
|
case 59:
|
|
4150
4150
|
if (missingDatabases.length > 0 && !update) {
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4151
|
+
logger('Missing databases found but update is not enabled. Please enable update to create missing databases.');
|
|
4152
|
+
logger('Please run the command again with the --update flag to create missing databases.');
|
|
4153
|
+
logger('Missing databases:');
|
|
4154
|
+
logger(missingDatabases);
|
|
4155
4155
|
} else {
|
|
4156
|
-
|
|
4156
|
+
logger('All expected databases exist.');
|
|
4157
4157
|
}
|
|
4158
4158
|
case 60:
|
|
4159
4159
|
_iterator3 = _createForOfIteratorHelper(expectedDatabases);
|
|
@@ -4175,7 +4175,7 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4175
4175
|
_context.next = 70;
|
|
4176
4176
|
break;
|
|
4177
4177
|
}
|
|
4178
|
-
|
|
4178
|
+
logger('Skipping database', _database2, 'because it is missing');
|
|
4179
4179
|
return _context.abrupt("continue", 99);
|
|
4180
4180
|
case 70:
|
|
4181
4181
|
filePath = path.join(inputDir, _database2, "".concat(_database2, ".json"));
|
|
@@ -4185,26 +4185,26 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4185
4185
|
case 74:
|
|
4186
4186
|
fileContent = _context.sent;
|
|
4187
4187
|
expectedStructure = JSON.parse(fileContent);
|
|
4188
|
-
|
|
4188
|
+
logger('Getting database structure for', _database2);
|
|
4189
4189
|
_context.next = 79;
|
|
4190
4190
|
return getDatabaseStructure(connection, _database2, command, options);
|
|
4191
4191
|
case 79:
|
|
4192
4192
|
currentStructure = _context.sent;
|
|
4193
|
-
|
|
4193
|
+
logger('Database structure for', _database2, 'obtained');
|
|
4194
4194
|
differences = findDifferences(expectedStructure, currentStructure);
|
|
4195
|
-
|
|
4195
|
+
logger('Differences for', _database2, 'obtained');
|
|
4196
4196
|
if (update) {
|
|
4197
4197
|
_context.next = 88;
|
|
4198
4198
|
break;
|
|
4199
4199
|
}
|
|
4200
|
-
|
|
4200
|
+
logger('Logging differences for', _database2);
|
|
4201
4201
|
logDifferences(differences, _database2, true);
|
|
4202
4202
|
_context.next = 93;
|
|
4203
4203
|
break;
|
|
4204
4204
|
case 88:
|
|
4205
|
-
|
|
4205
|
+
logger('Logging differences for', _database2);
|
|
4206
4206
|
logDifferences(differences, _database2, false);
|
|
4207
|
-
|
|
4207
|
+
logger('Applying differences for', _database2);
|
|
4208
4208
|
_context.next = 93;
|
|
4209
4209
|
return applyDifferences$1(connection, _database2, differences);
|
|
4210
4210
|
case 93:
|
|
@@ -4214,7 +4214,7 @@ var compareAllDatabases = /*#__PURE__*/function () {
|
|
|
4214
4214
|
case 96:
|
|
4215
4215
|
_context.prev = 96;
|
|
4216
4216
|
_context.t2 = _context["catch"](71);
|
|
4217
|
-
|
|
4217
|
+
logger("Error processing database ".concat(_database2, ":"), _context.t2.message);
|
|
4218
4218
|
case 99:
|
|
4219
4219
|
_context.next = 63;
|
|
4220
4220
|
break;
|
package/package.json
CHANGED
package/src/apply.js
CHANGED
|
@@ -56,13 +56,13 @@ export const applyDifferences = async (connection, database, differences) => {
|
|
|
56
56
|
} else if (diff.type === 'missing_field') {
|
|
57
57
|
// Step 1: Add column with DEFAULT NULL to handle existing records
|
|
58
58
|
const addFieldSQL = `ALTER TABLE \`${diff.tableName}\` ADD \`${diff.field.Field}\` ${diff.field.Type} DEFAULT NULL;`;
|
|
59
|
-
|
|
59
|
+
logger(`Executing: ${addFieldSQL}`);
|
|
60
60
|
await connection.query(addFieldSQL);
|
|
61
61
|
|
|
62
62
|
// Step 2: If NOT NULL is required and no default was specified, modify the column to remove DEFAULT NULL
|
|
63
63
|
if (diff.field.NotNull && !diff.field.Default) {
|
|
64
64
|
const modifyFieldSQL = `ALTER TABLE \`${diff.tableName}\` MODIFY \`${diff.field.Field}\` ${diff.field.Type} NOT NULL;`;
|
|
65
|
-
|
|
65
|
+
logger(`Executing: ${modifyFieldSQL}`);
|
|
66
66
|
await connection.query(modifyFieldSQL);
|
|
67
67
|
}
|
|
68
68
|
if(diff.field.Default){
|
|
@@ -72,7 +72,7 @@ export const applyDifferences = async (connection, database, differences) => {
|
|
|
72
72
|
? `DEFAULT '${diff.field.Default}'`
|
|
73
73
|
: '';
|
|
74
74
|
const modifyFieldSQL = `ALTER TABLE \`${diff.tableName}\` MODIFY \`${diff.field.Field}\` ${diff.field.Type} ${defaultClause};`;
|
|
75
|
-
|
|
75
|
+
logger(`Executing: ${modifyFieldSQL}`);
|
|
76
76
|
await connection.query(modifyFieldSQL);
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -207,8 +207,8 @@ export const applyDifferences = async (connection, database, differences) => {
|
|
|
207
207
|
|
|
208
208
|
} else if (diff.type === 'missing_trigger') {
|
|
209
209
|
const createTriggerSQL = diff.trigger.Definition;
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
logger('fixing trigger', diff.trigger.Name)
|
|
211
|
+
logger(`Executing: ${createTriggerSQL}`);
|
|
212
212
|
await connection.query(createTriggerSQL);
|
|
213
213
|
|
|
214
214
|
|
|
@@ -217,7 +217,7 @@ export const applyDifferences = async (connection, database, differences) => {
|
|
|
217
217
|
logger(`Executing: ${dropTriggerSQL}`);
|
|
218
218
|
await connection.query(dropTriggerSQL);
|
|
219
219
|
const createTriggerSQL = diff.trigger.Definition;
|
|
220
|
-
|
|
220
|
+
logger(`Executing: ${createTriggerSQL}`);
|
|
221
221
|
await connection.query(createTriggerSQL);
|
|
222
222
|
|
|
223
223
|
|
|
@@ -227,7 +227,7 @@ export const applyDifferences = async (connection, database, differences) => {
|
|
|
227
227
|
await connection.query(dropTriggerSQL);
|
|
228
228
|
|
|
229
229
|
}else if(diff.type === 'missing_database'){
|
|
230
|
-
|
|
230
|
+
logger('fixing missing database', diff.database)
|
|
231
231
|
const createDatabaseSQL = `CREATE DATABASE \`${diff.database}\`;`;
|
|
232
232
|
logger(`Executing: ${createDatabaseSQL}`);
|
|
233
233
|
await connection.query(createDatabaseSQL);
|
package/src/compare.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'fs/promises';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { getDatabases, getDatabaseStructure } from './getters.js';
|
|
4
4
|
import { findDifferences } from './differences.js';
|
|
5
|
-
import { logDifferences } from './loggers.js';
|
|
5
|
+
import { logDifferences, logger } from './loggers.js';
|
|
6
6
|
import { applyDifferences } from './apply.js';
|
|
7
7
|
|
|
8
8
|
export const compareAllDatabases = async (connection, inputDir, update = false, command, options) => {
|
|
@@ -15,14 +15,14 @@ export const compareAllDatabases = async (connection, inputDir, update = false,
|
|
|
15
15
|
expectedDatabases = expectedDatabases.filter(file => file !== 'diffs.json');
|
|
16
16
|
//filter out dumpInfo.json
|
|
17
17
|
expectedDatabases = expectedDatabases.filter(file => file !== 'dumpInfo.json');
|
|
18
|
-
|
|
18
|
+
logger('Expected databases from input directory:', expectedDatabases);
|
|
19
19
|
|
|
20
20
|
// Check existing databases
|
|
21
21
|
const existingDatabases = await getDatabases(connection);
|
|
22
22
|
// console.log('Existing databases:', existingDatabases);
|
|
23
23
|
const allDifferences = {};
|
|
24
24
|
const missingDatabases = [];
|
|
25
|
-
|
|
25
|
+
logger('All differences:', allDifferences);
|
|
26
26
|
|
|
27
27
|
// Note missing databases and prepare to create them
|
|
28
28
|
for (const database of expectedDatabases) {
|
|
@@ -42,19 +42,19 @@ export const compareAllDatabases = async (connection, inputDir, update = false,
|
|
|
42
42
|
|
|
43
43
|
// Create missing databases at the beginning
|
|
44
44
|
if (missingDatabases.length > 0 && update) {
|
|
45
|
-
|
|
45
|
+
logger('Creating missing databases:');
|
|
46
46
|
for (const database of missingDatabases) {
|
|
47
|
-
|
|
47
|
+
logger(`Creating database ${database}...`);
|
|
48
48
|
await connection.query(`CREATE DATABASE \`${database}\`;`);
|
|
49
|
-
|
|
49
|
+
logger(`Database ${database} created.`);
|
|
50
50
|
}
|
|
51
51
|
}else if (missingDatabases.length > 0 && !update){
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
logger('Missing databases found but update is not enabled. Please enable update to create missing databases.');
|
|
53
|
+
logger('Please run the command again with the --update flag to create missing databases.');
|
|
54
|
+
logger('Missing databases:');
|
|
55
|
+
logger(missingDatabases);
|
|
56
56
|
} else {
|
|
57
|
-
|
|
57
|
+
logger('All expected databases exist.');
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
for (const database of expectedDatabases) {
|
|
@@ -62,7 +62,7 @@ export const compareAllDatabases = async (connection, inputDir, update = false,
|
|
|
62
62
|
continue;
|
|
63
63
|
}
|
|
64
64
|
if(missingDatabases.includes(database)){
|
|
65
|
-
|
|
65
|
+
logger('Skipping database', database, 'because it is missing');
|
|
66
66
|
continue;
|
|
67
67
|
}
|
|
68
68
|
const filePath = path.join(inputDir, database, `${database}.json`);
|
|
@@ -70,23 +70,23 @@ export const compareAllDatabases = async (connection, inputDir, update = false,
|
|
|
70
70
|
try {
|
|
71
71
|
const fileContent = await fs.readFile(filePath, 'utf-8');
|
|
72
72
|
const expectedStructure = JSON.parse(fileContent);
|
|
73
|
-
|
|
73
|
+
logger('Getting database structure for', database);
|
|
74
74
|
const currentStructure = await getDatabaseStructure(connection, database, command, options);
|
|
75
|
-
|
|
75
|
+
logger('Database structure for', database, 'obtained');
|
|
76
76
|
const differences = findDifferences(expectedStructure, currentStructure);
|
|
77
|
-
|
|
77
|
+
logger('Differences for', database, 'obtained');
|
|
78
78
|
if (!update) {
|
|
79
|
-
|
|
79
|
+
logger('Logging differences for', database);
|
|
80
80
|
logDifferences(differences, database, true);
|
|
81
81
|
} else {
|
|
82
|
-
|
|
82
|
+
logger('Logging differences for', database);
|
|
83
83
|
logDifferences(differences, database, false);
|
|
84
|
-
|
|
84
|
+
logger('Applying differences for', database);
|
|
85
85
|
await applyDifferences(connection, database, differences);
|
|
86
86
|
}
|
|
87
87
|
allDifferences[database] = differences;
|
|
88
88
|
} catch (err) {
|
|
89
|
-
|
|
89
|
+
logger(`Error processing database ${database}:`, err.message);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
return allDifferences;
|
package/src/differences.js
CHANGED
|
@@ -19,7 +19,7 @@ export const findDifferences = (expected, current) => {
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
if (!current.tables[tableName]) {
|
|
22
|
-
|
|
22
|
+
logger('missing_table', contents);
|
|
23
23
|
differences.push({ type: 'missing_table', tableName, createSQL: contents.createSQL });
|
|
24
24
|
continue;
|
|
25
25
|
}
|
|
@@ -46,7 +46,7 @@ export const findDifferences = (expected, current) => {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
} catch (e) {
|
|
49
|
-
|
|
49
|
+
logger(`Error verifying triggers for table ${tableName}`, e);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
const createTableSql = current.tables[tableName].createSQL;
|
|
@@ -85,7 +85,7 @@ export const findDifferences = (expected, current) => {
|
|
|
85
85
|
for (const field of columns) {
|
|
86
86
|
const currentField = current.tables[tableName].columns.find(f => f.Field === field.Field);
|
|
87
87
|
if (!currentField) {
|
|
88
|
-
|
|
88
|
+
logger('Current field not found for', field.Field, 'in table', tableName);
|
|
89
89
|
differences.push({ type: 'missing_field', tableName, field });
|
|
90
90
|
continue;
|
|
91
91
|
}
|
package/src/dump.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { getDatabases, getDatabaseStructure } from './getters.js';
|
|
4
|
+
import { logger } from './loggers.js';
|
|
4
5
|
|
|
5
6
|
// const require = createRequire(import.meta.url);
|
|
6
7
|
// const { version } = require('../package.json');
|
|
@@ -25,11 +26,11 @@ export const dumpAllDatabases = async (connection, command, options) => {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export const getDatabasesFromExistingDumps = async (options) => {
|
|
28
|
-
|
|
29
|
+
logger('Getting databases from existing dumps in ', options.output);
|
|
29
30
|
//check if the folder exists
|
|
30
31
|
let exists = await fs.stat(options.output).catch(() => false);
|
|
31
32
|
if (!exists) {
|
|
32
|
-
|
|
33
|
+
logger('Folder does not exist');
|
|
33
34
|
return {};
|
|
34
35
|
}
|
|
35
36
|
//read directory above to get the dbs. each db is in a named folder with a matching .json.
|
|
@@ -39,7 +40,7 @@ export const getDatabasesFromExistingDumps = async (options) => {
|
|
|
39
40
|
const databases = await fs.readdir(path.join(options.output));
|
|
40
41
|
for (const database of databases) {
|
|
41
42
|
if(database.includes('diffs') || database.includes('dumpInfo')){
|
|
42
|
-
|
|
43
|
+
logger('Skipping diffs folder')
|
|
43
44
|
continue
|
|
44
45
|
}
|
|
45
46
|
let dbStructure = await fs.readFile(path.join(options.output, database, `${database}.json`), 'utf8');
|
package/src/getters.js
CHANGED