mysqlsyncr 1.1.6 → 1.1.10
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 +195 -218
- package/dist/index.js +195 -218
- package/package.json +1 -1
- package/src/apply.js +86 -85
package/dist/index.js
CHANGED
|
@@ -134,10 +134,7 @@ function _iterableToArrayLimit(r, l) {
|
|
|
134
134
|
f = true,
|
|
135
135
|
o = false;
|
|
136
136
|
try {
|
|
137
|
-
if (i = (t = t.call(r)).next, 0 === l)
|
|
138
|
-
if (Object(t) !== t) return;
|
|
139
|
-
f = !1;
|
|
140
|
-
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
137
|
+
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
141
138
|
} catch (r) {
|
|
142
139
|
o = true, n = r;
|
|
143
140
|
} finally {
|
|
@@ -3599,7 +3596,7 @@ var applyDifferences = /*#__PURE__*/function () {
|
|
|
3599
3596
|
_iterator = _createForOfIteratorHelper(differences);
|
|
3600
3597
|
_context2.prev = 2;
|
|
3601
3598
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
3602
|
-
var diff, createDatabaseSQL, tableName, createSQL, _tableName, dropTableSQL, addFieldSQL, modifyFieldSQL, defaultClause, _modifyFieldSQL, dropFieldSQL, _tableName2, field, currentField,
|
|
3599
|
+
var diff, createDatabaseSQL, tableName, createSQL, _tableName, dropTableSQL, addFieldSQL, modifyFieldSQL, defaultClause, _modifyFieldSQL, dropFieldSQL, _tableName2, field, currentField, isTimestamp, _defaultClause, hasOnUpdate, _modifyFieldSQL2, existingColumns, columnNames, missingColumns, indexColumns, primaryKeySQL, uniqueSQL, addIndexSQL, dropPrimaryKeySQL, dropIndexSQL, _tableName3, index, _dropPrimaryKeySQL, _dropIndexSQL, _uniqueSQL, addPrimaryKeySQL, _addIndexSQL, dropCurrentProcSQL, createProcSQL, dropViewSQL, createViewSQL, _dropViewSQL, _createViewSQL, _dropViewSQL2, createTriggerSQL, dropTriggerSQL, _createTriggerSQL, _dropTriggerSQL, _createDatabaseSQL;
|
|
3603
3600
|
return _regeneratorRuntime().wrap(function _loop$(_context) {
|
|
3604
3601
|
while (1) switch (_context.prev = _context.next) {
|
|
3605
3602
|
case 0:
|
|
@@ -3629,7 +3626,7 @@ var applyDifferences = /*#__PURE__*/function () {
|
|
|
3629
3626
|
_context.next = 16;
|
|
3630
3627
|
return connection.query(createSQL);
|
|
3631
3628
|
case 16:
|
|
3632
|
-
_context.next =
|
|
3629
|
+
_context.next = 212;
|
|
3633
3630
|
break;
|
|
3634
3631
|
case 18:
|
|
3635
3632
|
if (!(diff.type === 'extra_table')) {
|
|
@@ -3643,7 +3640,7 @@ var applyDifferences = /*#__PURE__*/function () {
|
|
|
3643
3640
|
_context.next = 25;
|
|
3644
3641
|
return connection.query(dropTableSQL);
|
|
3645
3642
|
case 25:
|
|
3646
|
-
_context.next =
|
|
3643
|
+
_context.next = 212;
|
|
3647
3644
|
break;
|
|
3648
3645
|
case 27:
|
|
3649
3646
|
if (!(diff.type === 'missing_field')) {
|
|
@@ -3675,7 +3672,7 @@ var applyDifferences = /*#__PURE__*/function () {
|
|
|
3675
3672
|
_context.next = 43;
|
|
3676
3673
|
return connection.query(_modifyFieldSQL);
|
|
3677
3674
|
case 43:
|
|
3678
|
-
_context.next =
|
|
3675
|
+
_context.next = 212;
|
|
3679
3676
|
break;
|
|
3680
3677
|
case 45:
|
|
3681
3678
|
if (!(diff.type === 'extra_field')) {
|
|
@@ -3687,132 +3684,112 @@ var applyDifferences = /*#__PURE__*/function () {
|
|
|
3687
3684
|
_context.next = 50;
|
|
3688
3685
|
return connection.query(dropFieldSQL);
|
|
3689
3686
|
case 50:
|
|
3690
|
-
_context.next =
|
|
3687
|
+
_context.next = 212;
|
|
3691
3688
|
break;
|
|
3692
3689
|
case 52:
|
|
3693
3690
|
if (!(diff.type === 'mismatched_field')) {
|
|
3694
|
-
_context.next =
|
|
3695
|
-
break;
|
|
3696
|
-
}
|
|
3697
|
-
_tableName2 = diff.tableName, field = diff.field, currentField = diff.currentField; // Helper function to determine if we need batch processing
|
|
3698
|
-
needsBatchProcessing = function needsBatchProcessing() {
|
|
3699
|
-
var currentType = currentField.Type.toLowerCase();
|
|
3700
|
-
var newType = field.Type.toLowerCase();
|
|
3701
|
-
|
|
3702
|
-
// Decimal changes
|
|
3703
|
-
if (currentType.includes('decimal') && newType.includes('decimal')) {
|
|
3704
|
-
return true;
|
|
3705
|
-
}
|
|
3706
|
-
|
|
3707
|
-
// VARCHAR/CHAR length reductions
|
|
3708
|
-
if ((currentType.includes('varchar') || currentType.includes('char')) && (newType.includes('varchar') || newType.includes('char'))) {
|
|
3709
|
-
var _currentType$match, _newType$match;
|
|
3710
|
-
var currentLength = parseInt(((_currentType$match = currentType.match(/\((\d+)\)/)) === null || _currentType$match === undefined ? undefined : _currentType$match[1]) || '0');
|
|
3711
|
-
var newLength = parseInt(((_newType$match = newType.match(/\((\d+)\)/)) === null || _newType$match === undefined ? undefined : _newType$match[1]) || '0');
|
|
3712
|
-
return newLength < currentLength;
|
|
3713
|
-
}
|
|
3714
|
-
|
|
3715
|
-
// TEXT to VARCHAR conversions
|
|
3716
|
-
if (currentType.includes('text') && newType.includes('varchar')) {
|
|
3717
|
-
return true;
|
|
3718
|
-
}
|
|
3719
|
-
|
|
3720
|
-
// Numeric type downgrades
|
|
3721
|
-
var numericDowngrades = {
|
|
3722
|
-
'bigint': ['int', 'mediumint', 'smallint', 'tinyint'],
|
|
3723
|
-
'int': ['mediumint', 'smallint', 'tinyint'],
|
|
3724
|
-
'mediumint': ['smallint', 'tinyint'],
|
|
3725
|
-
'smallint': ['tinyint'],
|
|
3726
|
-
'double': ['float', 'decimal'],
|
|
3727
|
-
'float': ['decimal']
|
|
3728
|
-
};
|
|
3729
|
-
for (var _i = 0, _Object$entries = Object.entries(numericDowngrades); _i < _Object$entries.length; _i++) {
|
|
3730
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
3731
|
-
larger = _Object$entries$_i[0],
|
|
3732
|
-
smaller = _Object$entries$_i[1];
|
|
3733
|
-
if (currentType.includes(larger) && smaller.some(function (t) {
|
|
3734
|
-
return newType.includes(t);
|
|
3735
|
-
})) {
|
|
3736
|
-
return true;
|
|
3737
|
-
}
|
|
3738
|
-
}
|
|
3739
|
-
return false;
|
|
3740
|
-
};
|
|
3741
|
-
if (!needsBatchProcessing()) {
|
|
3742
|
-
_context.next = 90;
|
|
3743
|
-
break;
|
|
3744
|
-
}
|
|
3745
|
-
// Step 1: Add new column
|
|
3746
|
-
addColumnSQL = "ALTER TABLE `".concat(_tableName2, "` ADD COLUMN `").concat(field.Field, "_new` ").concat(field.Type, " DEFAULT NULL;");
|
|
3747
|
-
logger("Adding new column for type conversion: ".concat(addColumnSQL));
|
|
3748
|
-
_context.next = 60;
|
|
3749
|
-
return connection.query(addColumnSQL);
|
|
3750
|
-
case 60:
|
|
3751
|
-
// Step 2: Copy data in batches
|
|
3752
|
-
totalUpdated = 0;
|
|
3753
|
-
batchSize = 10000;
|
|
3754
|
-
batchCount = 0;
|
|
3755
|
-
case 63:
|
|
3756
|
-
updateSQL = "\n UPDATE `".concat(_tableName2, "` \n SET `").concat(field.Field, "_new` = `").concat(field.Field, "`\n WHERE `").concat(field.Field, "_new` IS NULL \n AND `").concat(field.Field, "` IS NOT NULL\n LIMIT ").concat(batchSize, ";\n ");
|
|
3757
|
-
_context.next = 67;
|
|
3758
|
-
return connection.query(updateSQL);
|
|
3759
|
-
case 67:
|
|
3760
|
-
result = _context.sent;
|
|
3761
|
-
rowsAffected = result.affectedRows;
|
|
3762
|
-
if (!(rowsAffected === 0)) {
|
|
3763
|
-
_context.next = 71;
|
|
3691
|
+
_context.next = 63;
|
|
3764
3692
|
break;
|
|
3765
3693
|
}
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
//
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
//
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3694
|
+
_tableName2 = diff.tableName, field = diff.field, currentField = diff.currentField; // use alter table rather than adding fields
|
|
3695
|
+
// // Helper function to determine if we need batch processing
|
|
3696
|
+
// const needsBatchProcessing = () => {
|
|
3697
|
+
// const currentType = currentField.Type.toLowerCase();
|
|
3698
|
+
// const newType = field.Type.toLowerCase();
|
|
3699
|
+
// // Decimal changes
|
|
3700
|
+
// if (currentType.includes('decimal') && newType.includes('decimal')) {
|
|
3701
|
+
// return true;
|
|
3702
|
+
// }
|
|
3703
|
+
// // VARCHAR/CHAR length reductions
|
|
3704
|
+
// if ((currentType.includes('varchar') || currentType.includes('char')) &&
|
|
3705
|
+
// (newType.includes('varchar') || newType.includes('char'))) {
|
|
3706
|
+
// const currentLength = parseInt(currentType.match(/\((\d+)\)/)?.[1] || '0');
|
|
3707
|
+
// const newLength = parseInt(newType.match(/\((\d+)\)/)?.[1] || '0');
|
|
3708
|
+
// return newLength < currentLength;
|
|
3709
|
+
// }
|
|
3710
|
+
// // TEXT to VARCHAR conversions
|
|
3711
|
+
// if (currentType.includes('text') && newType.includes('varchar')) {
|
|
3712
|
+
// return true;
|
|
3713
|
+
// }
|
|
3714
|
+
// // Numeric type downgrades
|
|
3715
|
+
// const numericDowngrades = {
|
|
3716
|
+
// 'bigint': ['int', 'mediumint', 'smallint', 'tinyint'],
|
|
3717
|
+
// 'int': ['mediumint', 'smallint', 'tinyint'],
|
|
3718
|
+
// 'mediumint': ['smallint', 'tinyint'],
|
|
3719
|
+
// 'smallint': ['tinyint'],
|
|
3720
|
+
// 'double': ['float', 'decimal'],
|
|
3721
|
+
// 'float': ['decimal']
|
|
3722
|
+
// };
|
|
3723
|
+
// for (const [larger, smaller] of Object.entries(numericDowngrades)) {
|
|
3724
|
+
// if (currentType.includes(larger) && smaller.some(t => newType.includes(t))) {
|
|
3725
|
+
// return true;
|
|
3726
|
+
// }
|
|
3727
|
+
// }
|
|
3728
|
+
// return false;
|
|
3729
|
+
// };
|
|
3730
|
+
// if (needsBatchProcessing()) {
|
|
3731
|
+
// // Step 1: Add new column
|
|
3732
|
+
// const addColumnSQL = `ALTER TABLE \`${tableName}\` ADD COLUMN \`${field.Field}_new\` ${field.Type} DEFAULT NULL;`;
|
|
3733
|
+
// console.log(`Adding new column for type conversion: ${addColumnSQL}`);
|
|
3734
|
+
// await connection.query(addColumnSQL);
|
|
3735
|
+
// // Step 2: Copy data in batches
|
|
3736
|
+
// let totalUpdated = 0;
|
|
3737
|
+
// let batchSize = 10000;
|
|
3738
|
+
// let batchCount = 0;
|
|
3739
|
+
// while (true) {
|
|
3740
|
+
// const updateSQL = `
|
|
3741
|
+
// UPDATE \`${tableName}\`
|
|
3742
|
+
// SET \`${field.Field}_new\` = \`${field.Field}\`
|
|
3743
|
+
// WHERE \`${field.Field}_new\` IS NULL
|
|
3744
|
+
// AND \`${field.Field}\` IS NOT NULL
|
|
3745
|
+
// LIMIT ${batchSize};
|
|
3746
|
+
// `;
|
|
3747
|
+
// const result = await connection.query(updateSQL);
|
|
3748
|
+
// const rowsAffected = result.affectedRows;
|
|
3749
|
+
// if (rowsAffected === 0) break;
|
|
3750
|
+
// totalUpdated += rowsAffected;
|
|
3751
|
+
// batchCount++;
|
|
3752
|
+
// console.log(`Batch ${batchCount}: Converted ${rowsAffected} rows. Total converted: ${totalUpdated}`);
|
|
3753
|
+
// }
|
|
3754
|
+
// // Step 3: Verify data (optional)
|
|
3755
|
+
// const verifySQL = `
|
|
3756
|
+
// SELECT COUNT(*) as mismatch FROM \`${tableName}\`
|
|
3757
|
+
// WHERE \`${field.Field}\` IS NOT NULL
|
|
3758
|
+
// AND \`${field.Field}_new\` IS NULL;
|
|
3759
|
+
// `;
|
|
3760
|
+
// const [verifyResult] = await connection.query(verifySQL);
|
|
3761
|
+
// if (verifyResult.mismatch > 0) {
|
|
3762
|
+
// console.log(`Warning: ${verifyResult.mismatch} rows may have failed conversion`);
|
|
3763
|
+
// }
|
|
3764
|
+
// // Step 4: Swap columns
|
|
3765
|
+
// const swapColumnsSQL = `
|
|
3766
|
+
// ALTER TABLE \`${tableName}\`
|
|
3767
|
+
// DROP COLUMN \`${field.Field}\`,
|
|
3768
|
+
// RENAME COLUMN \`${field.Field}_new\` TO \`${field.Field}\`
|
|
3769
|
+
// `;
|
|
3770
|
+
// console.log(`Executing: ${swapColumnsSQL}`);
|
|
3771
|
+
// await connection.query(swapColumnsSQL);
|
|
3772
|
+
// console.log(`Completed type conversion for ${field.Field}. Total rows converted: ${totalUpdated}`);
|
|
3773
|
+
// } else {
|
|
3796
3774
|
// Original mismatched field handling for simple changes
|
|
3797
3775
|
isTimestamp = field.Type.toLowerCase().includes('timestamp'); // Handle timestamp specific attributes
|
|
3798
3776
|
_defaultClause = field.Default === 'CURRENT_TIMESTAMP' ? 'DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP' : field.Default === 'NULL' ? isTimestamp ? 'NULL DEFAULT NULL' : 'DEFAULT NULL' : field.Default !== undefined && field.Default !== null ? "DEFAULT '".concat(field.Default, "'") : isTimestamp ? 'NULL DEFAULT NULL' : 'DEFAULT NULL'; // Remove ON UPDATE CURRENT_TIMESTAMP if we're changing away from CURRENT_TIMESTAMP
|
|
3799
|
-
|
|
3800
|
-
hasOnUpdate = (_currentField === null || _currentField === undefined ? undefined : _currentField.Default) === 'CURRENT_TIMESTAMP' && field.Default !== 'CURRENT_TIMESTAMP';
|
|
3777
|
+
hasOnUpdate = (currentField === null || currentField === undefined ? undefined : currentField.Default) === 'CURRENT_TIMESTAMP' && field.Default !== 'CURRENT_TIMESTAMP';
|
|
3801
3778
|
_modifyFieldSQL2 = "ALTER TABLE `".concat(_tableName2, "` CHANGE `").concat(field.Field, "` `").concat(field.Field, "` ").concat(field.Type, " ").concat(field.NotNull ? 'NOT NULL' : '', " ").concat(_defaultClause).concat(hasOnUpdate ? ' ON UPDATE CURRENT_TIMESTAMP' : '', ";");
|
|
3802
3779
|
console.log("Executing: ".concat(_modifyFieldSQL2));
|
|
3803
|
-
_context.next =
|
|
3780
|
+
_context.next = 61;
|
|
3804
3781
|
return connection.query(_modifyFieldSQL2);
|
|
3805
|
-
case
|
|
3806
|
-
_context.next =
|
|
3782
|
+
case 61:
|
|
3783
|
+
_context.next = 212;
|
|
3807
3784
|
break;
|
|
3808
|
-
case
|
|
3785
|
+
case 63:
|
|
3809
3786
|
if (!(diff.type === 'missing_index')) {
|
|
3810
|
-
_context.next =
|
|
3787
|
+
_context.next = 95;
|
|
3811
3788
|
break;
|
|
3812
3789
|
}
|
|
3813
|
-
_context.next =
|
|
3790
|
+
_context.next = 66;
|
|
3814
3791
|
return connection.query("SHOW COLUMNS FROM `".concat(diff.tableName, "`"));
|
|
3815
|
-
case
|
|
3792
|
+
case 66:
|
|
3816
3793
|
existingColumns = _context.sent;
|
|
3817
3794
|
columnNames = existingColumns.map(function (col) {
|
|
3818
3795
|
return col.Field;
|
|
@@ -3821,260 +3798,260 @@ var applyDifferences = /*#__PURE__*/function () {
|
|
|
3821
3798
|
return !columnNames.includes(col);
|
|
3822
3799
|
}) : [];
|
|
3823
3800
|
if (!(missingColumns.length > 0)) {
|
|
3824
|
-
_context.next =
|
|
3801
|
+
_context.next = 72;
|
|
3825
3802
|
break;
|
|
3826
3803
|
}
|
|
3827
3804
|
logger("Cannot create index ".concat(diff.index.Name, " on ").concat(diff.tableName, ". Missing columns: ").concat(missingColumns.join(', ')));
|
|
3828
3805
|
return _context.abrupt("return", 0);
|
|
3829
|
-
case
|
|
3806
|
+
case 72:
|
|
3830
3807
|
// Prepare the index columns with proper formatting
|
|
3831
3808
|
indexColumns = diff.index.ColumnName.map(function (col) {
|
|
3832
3809
|
return "`".concat(col, "`");
|
|
3833
3810
|
}); // Format column names
|
|
3834
3811
|
// Handle PRIMARY index creation
|
|
3835
3812
|
if (!(diff.index.Name === 'PRIMARY')) {
|
|
3836
|
-
_context.next =
|
|
3813
|
+
_context.next = 84;
|
|
3837
3814
|
break;
|
|
3838
3815
|
}
|
|
3839
3816
|
if (!(indexColumns.length > 0)) {
|
|
3840
|
-
_context.next =
|
|
3817
|
+
_context.next = 81;
|
|
3841
3818
|
break;
|
|
3842
3819
|
}
|
|
3843
3820
|
primaryKeySQL = "ALTER TABLE `".concat(diff.tableName, "` ADD PRIMARY KEY (").concat(indexColumns.join(', '), ");");
|
|
3844
3821
|
console.log("Executing: ".concat(primaryKeySQL));
|
|
3845
|
-
_context.next =
|
|
3822
|
+
_context.next = 79;
|
|
3846
3823
|
return connection.query(primaryKeySQL);
|
|
3847
|
-
case
|
|
3848
|
-
_context.next =
|
|
3824
|
+
case 79:
|
|
3825
|
+
_context.next = 82;
|
|
3849
3826
|
break;
|
|
3850
|
-
case
|
|
3827
|
+
case 81:
|
|
3851
3828
|
logger("Cannot create PRIMARY index on ".concat(diff.tableName, ". ColumnName is undefined or empty."), diff.index);
|
|
3852
|
-
case
|
|
3853
|
-
_context.next =
|
|
3829
|
+
case 82:
|
|
3830
|
+
_context.next = 93;
|
|
3854
3831
|
break;
|
|
3855
|
-
case
|
|
3832
|
+
case 84:
|
|
3856
3833
|
// Create the new index with UNIQUE if applicable
|
|
3857
3834
|
uniqueSQL = diff.index.Unique ? 'UNIQUE ' : ''; // Check if the index is unique
|
|
3858
3835
|
if (!(indexColumns.length > 0)) {
|
|
3859
|
-
_context.next =
|
|
3836
|
+
_context.next = 92;
|
|
3860
3837
|
break;
|
|
3861
3838
|
}
|
|
3862
3839
|
addIndexSQL = "ALTER TABLE `".concat(diff.tableName, "` ADD ").concat(uniqueSQL, "INDEX `").concat(diff.index.Name, "` (").concat(indexColumns.join(', '), ");");
|
|
3863
3840
|
console.log("Executing: ".concat(addIndexSQL));
|
|
3864
|
-
_context.next =
|
|
3841
|
+
_context.next = 90;
|
|
3865
3842
|
return connection.query(addIndexSQL);
|
|
3866
|
-
case
|
|
3867
|
-
_context.next =
|
|
3843
|
+
case 90:
|
|
3844
|
+
_context.next = 93;
|
|
3868
3845
|
break;
|
|
3869
|
-
case
|
|
3846
|
+
case 92:
|
|
3870
3847
|
logger("Cannot create index ".concat(diff.index.Name, " on ").concat(diff.tableName, ". ColumnName is undefined or empty."), diff.index);
|
|
3871
|
-
case
|
|
3872
|
-
_context.next =
|
|
3848
|
+
case 93:
|
|
3849
|
+
_context.next = 212;
|
|
3873
3850
|
break;
|
|
3874
|
-
case
|
|
3851
|
+
case 95:
|
|
3875
3852
|
if (!(diff.type === 'extra_index')) {
|
|
3876
|
-
_context.next =
|
|
3853
|
+
_context.next = 109;
|
|
3877
3854
|
break;
|
|
3878
3855
|
}
|
|
3879
3856
|
if (!(diff.index.Name === 'PRIMARY')) {
|
|
3880
|
-
_context.next =
|
|
3857
|
+
_context.next = 103;
|
|
3881
3858
|
break;
|
|
3882
3859
|
}
|
|
3883
3860
|
dropPrimaryKeySQL = "ALTER TABLE `".concat(diff.tableName, "` DROP PRIMARY KEY;");
|
|
3884
3861
|
console.log("Executing: ".concat(dropPrimaryKeySQL));
|
|
3885
|
-
_context.next =
|
|
3862
|
+
_context.next = 101;
|
|
3886
3863
|
return connection.query(dropPrimaryKeySQL);
|
|
3887
|
-
case
|
|
3888
|
-
_context.next =
|
|
3864
|
+
case 101:
|
|
3865
|
+
_context.next = 107;
|
|
3889
3866
|
break;
|
|
3890
|
-
case
|
|
3867
|
+
case 103:
|
|
3891
3868
|
dropIndexSQL = "DROP INDEX `".concat(diff.index.Name, "` ON `").concat(diff.tableName, "`;");
|
|
3892
3869
|
console.log("Executing: ".concat(dropIndexSQL));
|
|
3893
|
-
_context.next =
|
|
3870
|
+
_context.next = 107;
|
|
3894
3871
|
return connection.query(dropIndexSQL);
|
|
3895
|
-
case
|
|
3896
|
-
_context.next =
|
|
3872
|
+
case 107:
|
|
3873
|
+
_context.next = 212;
|
|
3897
3874
|
break;
|
|
3898
|
-
case
|
|
3875
|
+
case 109:
|
|
3899
3876
|
if (!(diff.type === 'mismatched_index')) {
|
|
3900
|
-
_context.next =
|
|
3877
|
+
_context.next = 137;
|
|
3901
3878
|
break;
|
|
3902
3879
|
}
|
|
3903
3880
|
_tableName3 = diff.tableName, index = diff.index; // Drop the existing index
|
|
3904
3881
|
if (!(index.Name === 'PRIMARY')) {
|
|
3905
|
-
_context.next =
|
|
3882
|
+
_context.next = 118;
|
|
3906
3883
|
break;
|
|
3907
3884
|
}
|
|
3908
3885
|
_dropPrimaryKeySQL = "ALTER TABLE `".concat(_tableName3, "` DROP PRIMARY KEY;");
|
|
3909
3886
|
console.log("Executing: ".concat(_dropPrimaryKeySQL));
|
|
3910
|
-
_context.next =
|
|
3887
|
+
_context.next = 116;
|
|
3911
3888
|
return connection.query(_dropPrimaryKeySQL);
|
|
3912
|
-
case
|
|
3913
|
-
_context.next =
|
|
3889
|
+
case 116:
|
|
3890
|
+
_context.next = 122;
|
|
3914
3891
|
break;
|
|
3915
|
-
case
|
|
3892
|
+
case 118:
|
|
3916
3893
|
_dropIndexSQL = "DROP INDEX `".concat(index.Name, "` ON `").concat(_tableName3, "`;");
|
|
3917
3894
|
console.log("Executing: ".concat(_dropIndexSQL));
|
|
3918
|
-
_context.next =
|
|
3895
|
+
_context.next = 122;
|
|
3919
3896
|
return connection.query(_dropIndexSQL);
|
|
3920
|
-
case
|
|
3897
|
+
case 122:
|
|
3921
3898
|
console.log('index', index);
|
|
3922
3899
|
|
|
3923
3900
|
// Create the new index
|
|
3924
3901
|
_uniqueSQL = index.Unique ? 'UNIQUE ' : ''; // Check if the index is unique
|
|
3925
3902
|
if (!(index.Name === 'PRIMARY')) {
|
|
3926
|
-
_context.next =
|
|
3903
|
+
_context.next = 131;
|
|
3927
3904
|
break;
|
|
3928
3905
|
}
|
|
3929
3906
|
addPrimaryKeySQL = "ALTER TABLE `".concat(_tableName3, "` ADD PRIMARY KEY (").concat(index.ColumnName.join(', '), ");");
|
|
3930
3907
|
console.log("Executing: ".concat(addPrimaryKeySQL));
|
|
3931
|
-
_context.next =
|
|
3908
|
+
_context.next = 129;
|
|
3932
3909
|
return connection.query(addPrimaryKeySQL);
|
|
3933
|
-
case
|
|
3934
|
-
_context.next =
|
|
3910
|
+
case 129:
|
|
3911
|
+
_context.next = 135;
|
|
3935
3912
|
break;
|
|
3936
|
-
case
|
|
3913
|
+
case 131:
|
|
3937
3914
|
_addIndexSQL = "ALTER TABLE `".concat(_tableName3, "` ADD ").concat(_uniqueSQL, "INDEX `").concat(index.Name, "` (").concat(index.ColumnName.join(', '), ");"); // Include UNIQUE if applicable
|
|
3938
3915
|
console.log("Executing: ".concat(_addIndexSQL));
|
|
3939
|
-
_context.next =
|
|
3916
|
+
_context.next = 135;
|
|
3940
3917
|
return connection.query(_addIndexSQL);
|
|
3941
|
-
case
|
|
3942
|
-
_context.next =
|
|
3918
|
+
case 135:
|
|
3919
|
+
_context.next = 212;
|
|
3943
3920
|
break;
|
|
3944
|
-
case
|
|
3921
|
+
case 137:
|
|
3945
3922
|
if (!(diff.type === 'missing_procedure' || diff.type === 'mismatched_procedure')) {
|
|
3946
|
-
_context.next =
|
|
3923
|
+
_context.next = 148;
|
|
3947
3924
|
break;
|
|
3948
3925
|
}
|
|
3949
3926
|
// Drop the procedure if it exists
|
|
3950
3927
|
dropCurrentProcSQL = "DROP PROCEDURE IF EXISTS `".concat(diff.Name, "`;");
|
|
3951
3928
|
console.log("Executing: ".concat(dropCurrentProcSQL));
|
|
3952
|
-
_context.next =
|
|
3929
|
+
_context.next = 142;
|
|
3953
3930
|
return connection.query(dropCurrentProcSQL);
|
|
3954
|
-
case
|
|
3931
|
+
case 142:
|
|
3955
3932
|
// Create the procedure
|
|
3956
3933
|
createProcSQL = diff.Definition;
|
|
3957
3934
|
console.log("Executing: ".concat(createProcSQL)); // Log the SQL statement
|
|
3958
|
-
_context.next =
|
|
3935
|
+
_context.next = 146;
|
|
3959
3936
|
return connection.query(createProcSQL);
|
|
3960
|
-
case
|
|
3961
|
-
_context.next =
|
|
3937
|
+
case 146:
|
|
3938
|
+
_context.next = 212;
|
|
3962
3939
|
break;
|
|
3963
|
-
case
|
|
3940
|
+
case 148:
|
|
3964
3941
|
if (!(diff.type === 'missing_view')) {
|
|
3965
|
-
_context.next =
|
|
3942
|
+
_context.next = 159;
|
|
3966
3943
|
break;
|
|
3967
3944
|
}
|
|
3968
3945
|
dropViewSQL = "DROP VIEW IF EXISTS `".concat(diff.viewName, "`;");
|
|
3969
3946
|
console.log("Executing: ".concat(dropViewSQL));
|
|
3970
|
-
_context.next =
|
|
3947
|
+
_context.next = 153;
|
|
3971
3948
|
return connection.query(dropViewSQL);
|
|
3972
|
-
case
|
|
3949
|
+
case 153:
|
|
3973
3950
|
createViewSQL = diff.definition; // Use the expected definition to create the view
|
|
3974
3951
|
console.log("Executing: ".concat(createViewSQL));
|
|
3975
|
-
_context.next =
|
|
3952
|
+
_context.next = 157;
|
|
3976
3953
|
return connection.query(createViewSQL);
|
|
3977
|
-
case
|
|
3978
|
-
_context.next =
|
|
3954
|
+
case 157:
|
|
3955
|
+
_context.next = 212;
|
|
3979
3956
|
break;
|
|
3980
|
-
case
|
|
3957
|
+
case 159:
|
|
3981
3958
|
if (!(diff.type === 'mismatched_view')) {
|
|
3982
|
-
_context.next =
|
|
3959
|
+
_context.next = 170;
|
|
3983
3960
|
break;
|
|
3984
3961
|
}
|
|
3985
3962
|
_dropViewSQL = "DROP VIEW IF EXISTS `".concat(diff.viewName, "`;");
|
|
3986
3963
|
console.log("Executing: ".concat(_dropViewSQL));
|
|
3987
|
-
_context.next =
|
|
3964
|
+
_context.next = 164;
|
|
3988
3965
|
return connection.query(_dropViewSQL);
|
|
3989
|
-
case
|
|
3966
|
+
case 164:
|
|
3990
3967
|
_createViewSQL = diff.definition; // Use the expected definition to create the view
|
|
3991
3968
|
console.log("Executing: ".concat(_createViewSQL));
|
|
3992
|
-
_context.next =
|
|
3969
|
+
_context.next = 168;
|
|
3993
3970
|
return connection.query(_createViewSQL);
|
|
3994
|
-
case
|
|
3995
|
-
_context.next =
|
|
3971
|
+
case 168:
|
|
3972
|
+
_context.next = 212;
|
|
3996
3973
|
break;
|
|
3997
|
-
case
|
|
3974
|
+
case 170:
|
|
3998
3975
|
if (!(diff.type === 'extra_view')) {
|
|
3999
|
-
_context.next =
|
|
3976
|
+
_context.next = 177;
|
|
4000
3977
|
break;
|
|
4001
3978
|
}
|
|
4002
3979
|
_dropViewSQL2 = "DROP VIEW IF EXISTS `".concat(diff.viewName, "`;");
|
|
4003
3980
|
console.log("Executing: ".concat(_dropViewSQL2));
|
|
4004
|
-
_context.next =
|
|
3981
|
+
_context.next = 175;
|
|
4005
3982
|
return connection.query(_dropViewSQL2);
|
|
4006
|
-
case
|
|
4007
|
-
_context.next =
|
|
3983
|
+
case 175:
|
|
3984
|
+
_context.next = 212;
|
|
4008
3985
|
break;
|
|
4009
|
-
case
|
|
3986
|
+
case 177:
|
|
4010
3987
|
if (!(diff.type === 'missing_trigger')) {
|
|
4011
|
-
_context.next =
|
|
3988
|
+
_context.next = 185;
|
|
4012
3989
|
break;
|
|
4013
3990
|
}
|
|
4014
3991
|
createTriggerSQL = diff.trigger.Definition;
|
|
4015
3992
|
logger('fixing trigger', diff.trigger.Name);
|
|
4016
3993
|
console.log("Executing: ".concat(createTriggerSQL));
|
|
4017
|
-
_context.next =
|
|
3994
|
+
_context.next = 183;
|
|
4018
3995
|
return connection.query(createTriggerSQL);
|
|
4019
|
-
case
|
|
4020
|
-
_context.next =
|
|
3996
|
+
case 183:
|
|
3997
|
+
_context.next = 212;
|
|
4021
3998
|
break;
|
|
4022
|
-
case
|
|
3999
|
+
case 185:
|
|
4023
4000
|
if (!(diff.type === 'mismatched_trigger')) {
|
|
4024
|
-
_context.next =
|
|
4001
|
+
_context.next = 196;
|
|
4025
4002
|
break;
|
|
4026
4003
|
}
|
|
4027
4004
|
dropTriggerSQL = "DROP TRIGGER IF EXISTS `".concat(diff.trigger.Name, "`;");
|
|
4028
4005
|
console.log("Executing: ".concat(dropTriggerSQL));
|
|
4029
|
-
_context.next =
|
|
4006
|
+
_context.next = 190;
|
|
4030
4007
|
return connection.query(dropTriggerSQL);
|
|
4031
|
-
case
|
|
4008
|
+
case 190:
|
|
4032
4009
|
_createTriggerSQL = diff.trigger.Definition;
|
|
4033
4010
|
console.log("Executing: ".concat(_createTriggerSQL));
|
|
4034
|
-
_context.next =
|
|
4011
|
+
_context.next = 194;
|
|
4035
4012
|
return connection.query(_createTriggerSQL);
|
|
4036
|
-
case
|
|
4037
|
-
_context.next =
|
|
4013
|
+
case 194:
|
|
4014
|
+
_context.next = 212;
|
|
4038
4015
|
break;
|
|
4039
|
-
case
|
|
4016
|
+
case 196:
|
|
4040
4017
|
if (!(diff.type === 'extra_trigger')) {
|
|
4041
|
-
_context.next =
|
|
4018
|
+
_context.next = 203;
|
|
4042
4019
|
break;
|
|
4043
4020
|
}
|
|
4044
4021
|
_dropTriggerSQL = "DROP TRIGGER IF EXISTS `".concat(diff.trigger.Name, "`;");
|
|
4045
4022
|
console.log("Executing: ".concat(_dropTriggerSQL));
|
|
4046
|
-
_context.next =
|
|
4023
|
+
_context.next = 201;
|
|
4047
4024
|
return connection.query(_dropTriggerSQL);
|
|
4048
|
-
case
|
|
4049
|
-
_context.next =
|
|
4025
|
+
case 201:
|
|
4026
|
+
_context.next = 212;
|
|
4050
4027
|
break;
|
|
4051
|
-
case
|
|
4028
|
+
case 203:
|
|
4052
4029
|
if (!(diff.type === 'missing_database')) {
|
|
4053
|
-
_context.next =
|
|
4030
|
+
_context.next = 211;
|
|
4054
4031
|
break;
|
|
4055
4032
|
}
|
|
4056
4033
|
logger('fixing missing database', diff.database);
|
|
4057
4034
|
_createDatabaseSQL = "CREATE DATABASE `".concat(diff.database, "`;");
|
|
4058
4035
|
console.log("Executing: ".concat(_createDatabaseSQL));
|
|
4059
|
-
_context.next =
|
|
4036
|
+
_context.next = 209;
|
|
4060
4037
|
return connection.query(_createDatabaseSQL);
|
|
4061
|
-
case
|
|
4062
|
-
_context.next =
|
|
4038
|
+
case 209:
|
|
4039
|
+
_context.next = 212;
|
|
4063
4040
|
break;
|
|
4064
|
-
case
|
|
4041
|
+
case 211:
|
|
4065
4042
|
logger("Error applying difference of type:".concat(diff.type), diff);
|
|
4066
|
-
case
|
|
4067
|
-
_context.next =
|
|
4043
|
+
case 212:
|
|
4044
|
+
_context.next = 217;
|
|
4068
4045
|
break;
|
|
4069
|
-
case
|
|
4070
|
-
_context.prev =
|
|
4046
|
+
case 214:
|
|
4047
|
+
_context.prev = 214;
|
|
4071
4048
|
_context.t0 = _context["catch"](1);
|
|
4072
4049
|
logger("Error applying difference of type:".concat(diff.type, ". Error: ").concat(_context.t0.message), diff);
|
|
4073
|
-
case
|
|
4050
|
+
case 217:
|
|
4074
4051
|
case "end":
|
|
4075
4052
|
return _context.stop();
|
|
4076
4053
|
}
|
|
4077
|
-
}, _loop, null, [[1,
|
|
4054
|
+
}, _loop, null, [[1, 214]]);
|
|
4078
4055
|
});
|
|
4079
4056
|
_iterator.s();
|
|
4080
4057
|
case 5:
|