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