mysqlsyncr 1.0.98 → 1.1.2

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
@@ -3610,7 +3610,7 @@ var applyDifferences = /*#__PURE__*/function () {
3610
3610
  break;
3611
3611
  }
3612
3612
  createDatabaseSQL = "CREATE DATABASE `".concat(differences[0].database, "`;");
3613
- logger("Executing: ".concat(createDatabaseSQL));
3613
+ console.log("Executing: ".concat(createDatabaseSQL));
3614
3614
  _context.next = 7;
3615
3615
  return connection.query(createDatabaseSQL);
3616
3616
  case 7:
@@ -3625,7 +3625,7 @@ var applyDifferences = /*#__PURE__*/function () {
3625
3625
  }
3626
3626
  tableName = diff.tableName, createSQL = diff.createSQL;
3627
3627
  logger("Creating missing table ".concat(tableName));
3628
- logger("Executing: ".concat(createSQL));
3628
+ console.log("Executing: ".concat(createSQL));
3629
3629
  _context.next = 16;
3630
3630
  return connection.query(createSQL);
3631
3631
  case 16:
@@ -3639,7 +3639,7 @@ var applyDifferences = /*#__PURE__*/function () {
3639
3639
  _tableName = diff.tableName;
3640
3640
  logger("Dropping extra table ".concat(_tableName));
3641
3641
  dropTableSQL = "DROP TABLE `".concat(_tableName, "`;");
3642
- logger("Executing: ".concat(dropTableSQL));
3642
+ console.log("Executing: ".concat(dropTableSQL));
3643
3643
  _context.next = 25;
3644
3644
  return connection.query(dropTableSQL);
3645
3645
  case 25:
@@ -3652,7 +3652,7 @@ var applyDifferences = /*#__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
- logger("Executing: ".concat(addFieldSQL));
3655
+ console.log("Executing: ".concat(addFieldSQL));
3656
3656
  _context.next = 32;
3657
3657
  return connection.query(addFieldSQL);
3658
3658
  case 32:
@@ -3661,7 +3661,7 @@ var applyDifferences = /*#__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
- logger("Executing: ".concat(modifyFieldSQL));
3664
+ console.log("Executing: ".concat(modifyFieldSQL));
3665
3665
  _context.next = 37;
3666
3666
  return connection.query(modifyFieldSQL);
3667
3667
  case 37:
@@ -3671,7 +3671,7 @@ var applyDifferences = /*#__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
- logger("Executing: ".concat(_modifyFieldSQL));
3674
+ console.log("Executing: ".concat(_modifyFieldSQL));
3675
3675
  _context.next = 43;
3676
3676
  return connection.query(_modifyFieldSQL);
3677
3677
  case 43:
@@ -3683,7 +3683,7 @@ var applyDifferences = /*#__PURE__*/function () {
3683
3683
  break;
3684
3684
  }
3685
3685
  dropFieldSQL = "ALTER TABLE `".concat(diff.tableName, "` DROP COLUMN `").concat(diff.field.Field, "`;");
3686
- logger("Executing: ".concat(dropFieldSQL));
3686
+ console.log("Executing: ".concat(dropFieldSQL));
3687
3687
  _context.next = 50;
3688
3688
  return connection.query(dropFieldSQL);
3689
3689
  case 50:
@@ -3695,9 +3695,9 @@ var applyDifferences = /*#__PURE__*/function () {
3695
3695
  break;
3696
3696
  }
3697
3697
  _tableName2 = diff.tableName, field = diff.field;
3698
- _defaultClause = field.Default === 'CURRENT_TIMESTAMP' ? 'DEFAULT CURRENT_TIMESTAMP' : field.Default !== undefined && field.Default !== null ? "DEFAULT '".concat(field.Default, "'") : '';
3698
+ _defaultClause = field.Default === 'CURRENT_TIMESTAMP' ? 'DEFAULT CURRENT_TIMESTAMP' : field.Default === 'NULL' ? 'DEFAULT NULL' : field.Default !== undefined && field.Default !== null ? "DEFAULT '".concat(field.Default, "'") : 'DEFAULT NULL';
3699
3699
  _dropFieldSQL = "ALTER TABLE `".concat(_tableName2, "` CHANGE `").concat(field.Field, "` `").concat(field.Field, "` ").concat(field.Type, " ").concat(field.NotNull ? 'NOT NULL' : '', " ").concat(_defaultClause, ";");
3700
- logger("Executing: ".concat(_dropFieldSQL));
3700
+ console.log("Executing: ".concat(_dropFieldSQL));
3701
3701
  _context.next = 59;
3702
3702
  return connection.query(_dropFieldSQL);
3703
3703
  case 59:
@@ -3739,7 +3739,7 @@ var applyDifferences = /*#__PURE__*/function () {
3739
3739
  break;
3740
3740
  }
3741
3741
  primaryKeySQL = "ALTER TABLE `".concat(diff.tableName, "` ADD PRIMARY KEY (").concat(indexColumns.join(', '), ");");
3742
- logger("Executing: ".concat(primaryKeySQL));
3742
+ console.log("Executing: ".concat(primaryKeySQL));
3743
3743
  _context.next = 77;
3744
3744
  return connection.query(primaryKeySQL);
3745
3745
  case 77:
@@ -3758,7 +3758,7 @@ var applyDifferences = /*#__PURE__*/function () {
3758
3758
  break;
3759
3759
  }
3760
3760
  addIndexSQL = "ALTER TABLE `".concat(diff.tableName, "` ADD ").concat(uniqueSQL, "INDEX `").concat(diff.index.Name, "` (").concat(indexColumns.join(', '), ");");
3761
- logger("Executing: ".concat(addIndexSQL));
3761
+ console.log("Executing: ".concat(addIndexSQL));
3762
3762
  _context.next = 88;
3763
3763
  return connection.query(addIndexSQL);
3764
3764
  case 88:
@@ -3779,7 +3779,7 @@ var applyDifferences = /*#__PURE__*/function () {
3779
3779
  break;
3780
3780
  }
3781
3781
  dropPrimaryKeySQL = "ALTER TABLE `".concat(diff.tableName, "` DROP PRIMARY KEY;");
3782
- logger("Executing: ".concat(dropPrimaryKeySQL));
3782
+ console.log("Executing: ".concat(dropPrimaryKeySQL));
3783
3783
  _context.next = 99;
3784
3784
  return connection.query(dropPrimaryKeySQL);
3785
3785
  case 99:
@@ -3787,7 +3787,7 @@ var applyDifferences = /*#__PURE__*/function () {
3787
3787
  break;
3788
3788
  case 101:
3789
3789
  dropIndexSQL = "DROP INDEX `".concat(diff.index.Name, "` ON `").concat(diff.tableName, "`;");
3790
- logger("Executing: ".concat(dropIndexSQL));
3790
+ console.log("Executing: ".concat(dropIndexSQL));
3791
3791
  _context.next = 105;
3792
3792
  return connection.query(dropIndexSQL);
3793
3793
  case 105:
@@ -3804,7 +3804,7 @@ var applyDifferences = /*#__PURE__*/function () {
3804
3804
  break;
3805
3805
  }
3806
3806
  _dropPrimaryKeySQL = "ALTER TABLE `".concat(_tableName3, "` DROP PRIMARY KEY;");
3807
- logger("Executing: ".concat(_dropPrimaryKeySQL));
3807
+ console.log("Executing: ".concat(_dropPrimaryKeySQL));
3808
3808
  _context.next = 114;
3809
3809
  return connection.query(_dropPrimaryKeySQL);
3810
3810
  case 114:
@@ -3812,7 +3812,7 @@ var applyDifferences = /*#__PURE__*/function () {
3812
3812
  break;
3813
3813
  case 116:
3814
3814
  _dropIndexSQL = "DROP INDEX `".concat(index.Name, "` ON `").concat(_tableName3, "`;");
3815
- logger("Executing: ".concat(_dropIndexSQL));
3815
+ console.log("Executing: ".concat(_dropIndexSQL));
3816
3816
  _context.next = 120;
3817
3817
  return connection.query(_dropIndexSQL);
3818
3818
  case 120:
@@ -3825,7 +3825,7 @@ var applyDifferences = /*#__PURE__*/function () {
3825
3825
  break;
3826
3826
  }
3827
3827
  addPrimaryKeySQL = "ALTER TABLE `".concat(_tableName3, "` ADD PRIMARY KEY (").concat(index.ColumnName.join(', '), ");");
3828
- logger("Executing: ".concat(addPrimaryKeySQL));
3828
+ console.log("Executing: ".concat(addPrimaryKeySQL));
3829
3829
  _context.next = 127;
3830
3830
  return connection.query(addPrimaryKeySQL);
3831
3831
  case 127:
@@ -3833,7 +3833,7 @@ var applyDifferences = /*#__PURE__*/function () {
3833
3833
  break;
3834
3834
  case 129:
3835
3835
  _addIndexSQL = "ALTER TABLE `".concat(_tableName3, "` ADD ").concat(_uniqueSQL, "INDEX `").concat(index.Name, "` (").concat(index.ColumnName.join(', '), ");"); // Include UNIQUE if applicable
3836
- logger("Executing: ".concat(_addIndexSQL));
3836
+ console.log("Executing: ".concat(_addIndexSQL));
3837
3837
  _context.next = 133;
3838
3838
  return connection.query(_addIndexSQL);
3839
3839
  case 133:
@@ -3846,13 +3846,13 @@ var applyDifferences = /*#__PURE__*/function () {
3846
3846
  }
3847
3847
  // Drop the procedure if it exists
3848
3848
  dropCurrentProcSQL = "DROP PROCEDURE IF EXISTS `".concat(diff.Name, "`;");
3849
- logger("Executing: ".concat(dropCurrentProcSQL));
3849
+ console.log("Executing: ".concat(dropCurrentProcSQL));
3850
3850
  _context.next = 140;
3851
3851
  return connection.query(dropCurrentProcSQL);
3852
3852
  case 140:
3853
3853
  // Create the procedure
3854
3854
  createProcSQL = diff.Definition;
3855
- logger("Executing: ".concat(createProcSQL)); // Log the SQL statement
3855
+ console.log("Executing: ".concat(createProcSQL)); // Log the SQL statement
3856
3856
  _context.next = 144;
3857
3857
  return connection.query(createProcSQL);
3858
3858
  case 144:
@@ -3864,12 +3864,12 @@ var applyDifferences = /*#__PURE__*/function () {
3864
3864
  break;
3865
3865
  }
3866
3866
  dropViewSQL = "DROP VIEW IF EXISTS `".concat(diff.viewName, "`;");
3867
- logger("Executing: ".concat(dropViewSQL));
3867
+ console.log("Executing: ".concat(dropViewSQL));
3868
3868
  _context.next = 151;
3869
3869
  return connection.query(dropViewSQL);
3870
3870
  case 151:
3871
3871
  createViewSQL = diff.definition; // Use the expected definition to create the view
3872
- logger("Executing: ".concat(createViewSQL));
3872
+ console.log("Executing: ".concat(createViewSQL));
3873
3873
  _context.next = 155;
3874
3874
  return connection.query(createViewSQL);
3875
3875
  case 155:
@@ -3881,12 +3881,12 @@ var applyDifferences = /*#__PURE__*/function () {
3881
3881
  break;
3882
3882
  }
3883
3883
  _dropViewSQL = "DROP VIEW IF EXISTS `".concat(diff.viewName, "`;");
3884
- logger("Executing: ".concat(_dropViewSQL));
3884
+ console.log("Executing: ".concat(_dropViewSQL));
3885
3885
  _context.next = 162;
3886
3886
  return connection.query(_dropViewSQL);
3887
3887
  case 162:
3888
3888
  _createViewSQL = diff.definition; // Use the expected definition to create the view
3889
- logger("Executing: ".concat(_createViewSQL));
3889
+ console.log("Executing: ".concat(_createViewSQL));
3890
3890
  _context.next = 166;
3891
3891
  return connection.query(_createViewSQL);
3892
3892
  case 166:
@@ -3898,7 +3898,7 @@ var applyDifferences = /*#__PURE__*/function () {
3898
3898
  break;
3899
3899
  }
3900
3900
  _dropViewSQL2 = "DROP VIEW IF EXISTS `".concat(diff.viewName, "`;");
3901
- logger("Executing: ".concat(_dropViewSQL2));
3901
+ console.log("Executing: ".concat(_dropViewSQL2));
3902
3902
  _context.next = 173;
3903
3903
  return connection.query(_dropViewSQL2);
3904
3904
  case 173:
@@ -3911,7 +3911,7 @@ var applyDifferences = /*#__PURE__*/function () {
3911
3911
  }
3912
3912
  createTriggerSQL = diff.trigger.Definition;
3913
3913
  logger('fixing trigger', diff.trigger.Name);
3914
- logger("Executing: ".concat(createTriggerSQL));
3914
+ console.log("Executing: ".concat(createTriggerSQL));
3915
3915
  _context.next = 181;
3916
3916
  return connection.query(createTriggerSQL);
3917
3917
  case 181:
@@ -3923,12 +3923,12 @@ var applyDifferences = /*#__PURE__*/function () {
3923
3923
  break;
3924
3924
  }
3925
3925
  dropTriggerSQL = "DROP TRIGGER IF EXISTS `".concat(diff.trigger.Name, "`;");
3926
- logger("Executing: ".concat(dropTriggerSQL));
3926
+ console.log("Executing: ".concat(dropTriggerSQL));
3927
3927
  _context.next = 188;
3928
3928
  return connection.query(dropTriggerSQL);
3929
3929
  case 188:
3930
3930
  _createTriggerSQL = diff.trigger.Definition;
3931
- logger("Executing: ".concat(_createTriggerSQL));
3931
+ console.log("Executing: ".concat(_createTriggerSQL));
3932
3932
  _context.next = 192;
3933
3933
  return connection.query(_createTriggerSQL);
3934
3934
  case 192:
@@ -3940,7 +3940,7 @@ var applyDifferences = /*#__PURE__*/function () {
3940
3940
  break;
3941
3941
  }
3942
3942
  _dropTriggerSQL = "DROP TRIGGER IF EXISTS `".concat(diff.trigger.Name, "`;");
3943
- logger("Executing: ".concat(_dropTriggerSQL));
3943
+ console.log("Executing: ".concat(_dropTriggerSQL));
3944
3944
  _context.next = 199;
3945
3945
  return connection.query(_dropTriggerSQL);
3946
3946
  case 199:
@@ -3953,7 +3953,7 @@ var applyDifferences = /*#__PURE__*/function () {
3953
3953
  }
3954
3954
  logger('fixing missing database', diff.database);
3955
3955
  _createDatabaseSQL = "CREATE DATABASE `".concat(diff.database, "`;");
3956
- logger("Executing: ".concat(_createDatabaseSQL));
3956
+ console.log("Executing: ".concat(_createDatabaseSQL));
3957
3957
  _context.next = 207;
3958
3958
  return connection.query(_createDatabaseSQL);
3959
3959
  case 207:
package/dist/index.js CHANGED
@@ -3607,7 +3607,7 @@ var applyDifferences = /*#__PURE__*/function () {
3607
3607
  break;
3608
3608
  }
3609
3609
  createDatabaseSQL = "CREATE DATABASE `".concat(differences[0].database, "`;");
3610
- logger("Executing: ".concat(createDatabaseSQL));
3610
+ console.log("Executing: ".concat(createDatabaseSQL));
3611
3611
  _context.next = 7;
3612
3612
  return connection.query(createDatabaseSQL);
3613
3613
  case 7:
@@ -3622,7 +3622,7 @@ var applyDifferences = /*#__PURE__*/function () {
3622
3622
  }
3623
3623
  tableName = diff.tableName, createSQL = diff.createSQL;
3624
3624
  logger("Creating missing table ".concat(tableName));
3625
- logger("Executing: ".concat(createSQL));
3625
+ console.log("Executing: ".concat(createSQL));
3626
3626
  _context.next = 16;
3627
3627
  return connection.query(createSQL);
3628
3628
  case 16:
@@ -3636,7 +3636,7 @@ var applyDifferences = /*#__PURE__*/function () {
3636
3636
  _tableName = diff.tableName;
3637
3637
  logger("Dropping extra table ".concat(_tableName));
3638
3638
  dropTableSQL = "DROP TABLE `".concat(_tableName, "`;");
3639
- logger("Executing: ".concat(dropTableSQL));
3639
+ console.log("Executing: ".concat(dropTableSQL));
3640
3640
  _context.next = 25;
3641
3641
  return connection.query(dropTableSQL);
3642
3642
  case 25:
@@ -3649,7 +3649,7 @@ var applyDifferences = /*#__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
- logger("Executing: ".concat(addFieldSQL));
3652
+ console.log("Executing: ".concat(addFieldSQL));
3653
3653
  _context.next = 32;
3654
3654
  return connection.query(addFieldSQL);
3655
3655
  case 32:
@@ -3658,7 +3658,7 @@ var applyDifferences = /*#__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
- logger("Executing: ".concat(modifyFieldSQL));
3661
+ console.log("Executing: ".concat(modifyFieldSQL));
3662
3662
  _context.next = 37;
3663
3663
  return connection.query(modifyFieldSQL);
3664
3664
  case 37:
@@ -3668,7 +3668,7 @@ var applyDifferences = /*#__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
- logger("Executing: ".concat(_modifyFieldSQL));
3671
+ console.log("Executing: ".concat(_modifyFieldSQL));
3672
3672
  _context.next = 43;
3673
3673
  return connection.query(_modifyFieldSQL);
3674
3674
  case 43:
@@ -3680,7 +3680,7 @@ var applyDifferences = /*#__PURE__*/function () {
3680
3680
  break;
3681
3681
  }
3682
3682
  dropFieldSQL = "ALTER TABLE `".concat(diff.tableName, "` DROP COLUMN `").concat(diff.field.Field, "`;");
3683
- logger("Executing: ".concat(dropFieldSQL));
3683
+ console.log("Executing: ".concat(dropFieldSQL));
3684
3684
  _context.next = 50;
3685
3685
  return connection.query(dropFieldSQL);
3686
3686
  case 50:
@@ -3692,9 +3692,9 @@ var applyDifferences = /*#__PURE__*/function () {
3692
3692
  break;
3693
3693
  }
3694
3694
  _tableName2 = diff.tableName, field = diff.field;
3695
- _defaultClause = field.Default === 'CURRENT_TIMESTAMP' ? 'DEFAULT CURRENT_TIMESTAMP' : field.Default !== undefined && field.Default !== null ? "DEFAULT '".concat(field.Default, "'") : '';
3695
+ _defaultClause = field.Default === 'CURRENT_TIMESTAMP' ? 'DEFAULT CURRENT_TIMESTAMP' : field.Default === 'NULL' ? 'DEFAULT NULL' : field.Default !== undefined && field.Default !== null ? "DEFAULT '".concat(field.Default, "'") : 'DEFAULT NULL';
3696
3696
  _dropFieldSQL = "ALTER TABLE `".concat(_tableName2, "` CHANGE `").concat(field.Field, "` `").concat(field.Field, "` ").concat(field.Type, " ").concat(field.NotNull ? 'NOT NULL' : '', " ").concat(_defaultClause, ";");
3697
- logger("Executing: ".concat(_dropFieldSQL));
3697
+ console.log("Executing: ".concat(_dropFieldSQL));
3698
3698
  _context.next = 59;
3699
3699
  return connection.query(_dropFieldSQL);
3700
3700
  case 59:
@@ -3736,7 +3736,7 @@ var applyDifferences = /*#__PURE__*/function () {
3736
3736
  break;
3737
3737
  }
3738
3738
  primaryKeySQL = "ALTER TABLE `".concat(diff.tableName, "` ADD PRIMARY KEY (").concat(indexColumns.join(', '), ");");
3739
- logger("Executing: ".concat(primaryKeySQL));
3739
+ console.log("Executing: ".concat(primaryKeySQL));
3740
3740
  _context.next = 77;
3741
3741
  return connection.query(primaryKeySQL);
3742
3742
  case 77:
@@ -3755,7 +3755,7 @@ var applyDifferences = /*#__PURE__*/function () {
3755
3755
  break;
3756
3756
  }
3757
3757
  addIndexSQL = "ALTER TABLE `".concat(diff.tableName, "` ADD ").concat(uniqueSQL, "INDEX `").concat(diff.index.Name, "` (").concat(indexColumns.join(', '), ");");
3758
- logger("Executing: ".concat(addIndexSQL));
3758
+ console.log("Executing: ".concat(addIndexSQL));
3759
3759
  _context.next = 88;
3760
3760
  return connection.query(addIndexSQL);
3761
3761
  case 88:
@@ -3776,7 +3776,7 @@ var applyDifferences = /*#__PURE__*/function () {
3776
3776
  break;
3777
3777
  }
3778
3778
  dropPrimaryKeySQL = "ALTER TABLE `".concat(diff.tableName, "` DROP PRIMARY KEY;");
3779
- logger("Executing: ".concat(dropPrimaryKeySQL));
3779
+ console.log("Executing: ".concat(dropPrimaryKeySQL));
3780
3780
  _context.next = 99;
3781
3781
  return connection.query(dropPrimaryKeySQL);
3782
3782
  case 99:
@@ -3784,7 +3784,7 @@ var applyDifferences = /*#__PURE__*/function () {
3784
3784
  break;
3785
3785
  case 101:
3786
3786
  dropIndexSQL = "DROP INDEX `".concat(diff.index.Name, "` ON `").concat(diff.tableName, "`;");
3787
- logger("Executing: ".concat(dropIndexSQL));
3787
+ console.log("Executing: ".concat(dropIndexSQL));
3788
3788
  _context.next = 105;
3789
3789
  return connection.query(dropIndexSQL);
3790
3790
  case 105:
@@ -3801,7 +3801,7 @@ var applyDifferences = /*#__PURE__*/function () {
3801
3801
  break;
3802
3802
  }
3803
3803
  _dropPrimaryKeySQL = "ALTER TABLE `".concat(_tableName3, "` DROP PRIMARY KEY;");
3804
- logger("Executing: ".concat(_dropPrimaryKeySQL));
3804
+ console.log("Executing: ".concat(_dropPrimaryKeySQL));
3805
3805
  _context.next = 114;
3806
3806
  return connection.query(_dropPrimaryKeySQL);
3807
3807
  case 114:
@@ -3809,7 +3809,7 @@ var applyDifferences = /*#__PURE__*/function () {
3809
3809
  break;
3810
3810
  case 116:
3811
3811
  _dropIndexSQL = "DROP INDEX `".concat(index.Name, "` ON `").concat(_tableName3, "`;");
3812
- logger("Executing: ".concat(_dropIndexSQL));
3812
+ console.log("Executing: ".concat(_dropIndexSQL));
3813
3813
  _context.next = 120;
3814
3814
  return connection.query(_dropIndexSQL);
3815
3815
  case 120:
@@ -3822,7 +3822,7 @@ var applyDifferences = /*#__PURE__*/function () {
3822
3822
  break;
3823
3823
  }
3824
3824
  addPrimaryKeySQL = "ALTER TABLE `".concat(_tableName3, "` ADD PRIMARY KEY (").concat(index.ColumnName.join(', '), ");");
3825
- logger("Executing: ".concat(addPrimaryKeySQL));
3825
+ console.log("Executing: ".concat(addPrimaryKeySQL));
3826
3826
  _context.next = 127;
3827
3827
  return connection.query(addPrimaryKeySQL);
3828
3828
  case 127:
@@ -3830,7 +3830,7 @@ var applyDifferences = /*#__PURE__*/function () {
3830
3830
  break;
3831
3831
  case 129:
3832
3832
  _addIndexSQL = "ALTER TABLE `".concat(_tableName3, "` ADD ").concat(_uniqueSQL, "INDEX `").concat(index.Name, "` (").concat(index.ColumnName.join(', '), ");"); // Include UNIQUE if applicable
3833
- logger("Executing: ".concat(_addIndexSQL));
3833
+ console.log("Executing: ".concat(_addIndexSQL));
3834
3834
  _context.next = 133;
3835
3835
  return connection.query(_addIndexSQL);
3836
3836
  case 133:
@@ -3843,13 +3843,13 @@ var applyDifferences = /*#__PURE__*/function () {
3843
3843
  }
3844
3844
  // Drop the procedure if it exists
3845
3845
  dropCurrentProcSQL = "DROP PROCEDURE IF EXISTS `".concat(diff.Name, "`;");
3846
- logger("Executing: ".concat(dropCurrentProcSQL));
3846
+ console.log("Executing: ".concat(dropCurrentProcSQL));
3847
3847
  _context.next = 140;
3848
3848
  return connection.query(dropCurrentProcSQL);
3849
3849
  case 140:
3850
3850
  // Create the procedure
3851
3851
  createProcSQL = diff.Definition;
3852
- logger("Executing: ".concat(createProcSQL)); // Log the SQL statement
3852
+ console.log("Executing: ".concat(createProcSQL)); // Log the SQL statement
3853
3853
  _context.next = 144;
3854
3854
  return connection.query(createProcSQL);
3855
3855
  case 144:
@@ -3861,12 +3861,12 @@ var applyDifferences = /*#__PURE__*/function () {
3861
3861
  break;
3862
3862
  }
3863
3863
  dropViewSQL = "DROP VIEW IF EXISTS `".concat(diff.viewName, "`;");
3864
- logger("Executing: ".concat(dropViewSQL));
3864
+ console.log("Executing: ".concat(dropViewSQL));
3865
3865
  _context.next = 151;
3866
3866
  return connection.query(dropViewSQL);
3867
3867
  case 151:
3868
3868
  createViewSQL = diff.definition; // Use the expected definition to create the view
3869
- logger("Executing: ".concat(createViewSQL));
3869
+ console.log("Executing: ".concat(createViewSQL));
3870
3870
  _context.next = 155;
3871
3871
  return connection.query(createViewSQL);
3872
3872
  case 155:
@@ -3878,12 +3878,12 @@ var applyDifferences = /*#__PURE__*/function () {
3878
3878
  break;
3879
3879
  }
3880
3880
  _dropViewSQL = "DROP VIEW IF EXISTS `".concat(diff.viewName, "`;");
3881
- logger("Executing: ".concat(_dropViewSQL));
3881
+ console.log("Executing: ".concat(_dropViewSQL));
3882
3882
  _context.next = 162;
3883
3883
  return connection.query(_dropViewSQL);
3884
3884
  case 162:
3885
3885
  _createViewSQL = diff.definition; // Use the expected definition to create the view
3886
- logger("Executing: ".concat(_createViewSQL));
3886
+ console.log("Executing: ".concat(_createViewSQL));
3887
3887
  _context.next = 166;
3888
3888
  return connection.query(_createViewSQL);
3889
3889
  case 166:
@@ -3895,7 +3895,7 @@ var applyDifferences = /*#__PURE__*/function () {
3895
3895
  break;
3896
3896
  }
3897
3897
  _dropViewSQL2 = "DROP VIEW IF EXISTS `".concat(diff.viewName, "`;");
3898
- logger("Executing: ".concat(_dropViewSQL2));
3898
+ console.log("Executing: ".concat(_dropViewSQL2));
3899
3899
  _context.next = 173;
3900
3900
  return connection.query(_dropViewSQL2);
3901
3901
  case 173:
@@ -3908,7 +3908,7 @@ var applyDifferences = /*#__PURE__*/function () {
3908
3908
  }
3909
3909
  createTriggerSQL = diff.trigger.Definition;
3910
3910
  logger('fixing trigger', diff.trigger.Name);
3911
- logger("Executing: ".concat(createTriggerSQL));
3911
+ console.log("Executing: ".concat(createTriggerSQL));
3912
3912
  _context.next = 181;
3913
3913
  return connection.query(createTriggerSQL);
3914
3914
  case 181:
@@ -3920,12 +3920,12 @@ var applyDifferences = /*#__PURE__*/function () {
3920
3920
  break;
3921
3921
  }
3922
3922
  dropTriggerSQL = "DROP TRIGGER IF EXISTS `".concat(diff.trigger.Name, "`;");
3923
- logger("Executing: ".concat(dropTriggerSQL));
3923
+ console.log("Executing: ".concat(dropTriggerSQL));
3924
3924
  _context.next = 188;
3925
3925
  return connection.query(dropTriggerSQL);
3926
3926
  case 188:
3927
3927
  _createTriggerSQL = diff.trigger.Definition;
3928
- logger("Executing: ".concat(_createTriggerSQL));
3928
+ console.log("Executing: ".concat(_createTriggerSQL));
3929
3929
  _context.next = 192;
3930
3930
  return connection.query(_createTriggerSQL);
3931
3931
  case 192:
@@ -3937,7 +3937,7 @@ var applyDifferences = /*#__PURE__*/function () {
3937
3937
  break;
3938
3938
  }
3939
3939
  _dropTriggerSQL = "DROP TRIGGER IF EXISTS `".concat(diff.trigger.Name, "`;");
3940
- logger("Executing: ".concat(_dropTriggerSQL));
3940
+ console.log("Executing: ".concat(_dropTriggerSQL));
3941
3941
  _context.next = 199;
3942
3942
  return connection.query(_dropTriggerSQL);
3943
3943
  case 199:
@@ -3950,7 +3950,7 @@ var applyDifferences = /*#__PURE__*/function () {
3950
3950
  }
3951
3951
  logger('fixing missing database', diff.database);
3952
3952
  _createDatabaseSQL = "CREATE DATABASE `".concat(diff.database, "`;");
3953
- logger("Executing: ".concat(_createDatabaseSQL));
3953
+ console.log("Executing: ".concat(_createDatabaseSQL));
3954
3954
  _context.next = 207;
3955
3955
  return connection.query(_createDatabaseSQL);
3956
3956
  case 207:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysqlsyncr",
3
- "version": "1.0.98",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/apply.js CHANGED
@@ -33,7 +33,7 @@ export const applyDifferences = async (connection, database, differences) => {
33
33
 
34
34
  if(diff.type == 'missing_database'){
35
35
  const createDatabaseSQL = `CREATE DATABASE \`${differences[0].database}\`;`;
36
- logger(`Executing: ${createDatabaseSQL}`);
36
+ console.log(`Executing: ${createDatabaseSQL}`);
37
37
  await connection.query(createDatabaseSQL);
38
38
  continue;
39
39
  }
@@ -43,26 +43,26 @@ export const applyDifferences = async (connection, database, differences) => {
43
43
  if (diff.type === 'missing_table') {
44
44
  const { tableName, createSQL } = diff;
45
45
  logger(`Creating missing table ${tableName}`);
46
- logger(`Executing: ${createSQL}`);
46
+ console.log(`Executing: ${createSQL}`);
47
47
  await connection.query(createSQL);
48
48
 
49
49
  } else if (diff.type === 'extra_table') {
50
50
  const { tableName } = diff;
51
51
  logger(`Dropping extra table ${tableName}`);
52
52
  const dropTableSQL = `DROP TABLE \`${tableName}\`;`;
53
- logger(`Executing: ${dropTableSQL}`);
53
+ console.log(`Executing: ${dropTableSQL}`);
54
54
  await connection.query(dropTableSQL);
55
55
 
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
- logger(`Executing: ${addFieldSQL}`);
59
+ console.log(`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
- logger(`Executing: ${modifyFieldSQL}`);
65
+ console.log(`Executing: ${modifyFieldSQL}`);
66
66
  await connection.query(modifyFieldSQL);
67
67
  }
68
68
  if(diff.field.Default){
@@ -72,25 +72,27 @@ 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
- logger(`Executing: ${modifyFieldSQL}`);
75
+ console.log(`Executing: ${modifyFieldSQL}`);
76
76
  await connection.query(modifyFieldSQL);
77
77
  }
78
78
 
79
79
  } else if (diff.type === 'extra_field') {
80
80
  const dropFieldSQL = `ALTER TABLE \`${diff.tableName}\` DROP COLUMN \`${diff.field.Field}\`;`;
81
- logger(`Executing: ${dropFieldSQL}`);
81
+ console.log(`Executing: ${dropFieldSQL}`);
82
82
  await connection.query(dropFieldSQL);
83
83
 
84
84
  } else if (diff.type === 'mismatched_field') {
85
85
  const { tableName, field } = diff;
86
86
  const defaultClause = field.Default === 'CURRENT_TIMESTAMP'
87
87
  ? 'DEFAULT CURRENT_TIMESTAMP'
88
- : field.Default !== undefined && field.Default !== null
89
- ? `DEFAULT '${field.Default}'`
90
- : '';
88
+ : field.Default === 'NULL'
89
+ ? 'DEFAULT NULL'
90
+ : field.Default !== undefined && field.Default !== null
91
+ ? `DEFAULT '${field.Default}'`
92
+ : 'DEFAULT NULL';
91
93
 
92
94
  const dropFieldSQL = `ALTER TABLE \`${tableName}\` CHANGE \`${field.Field}\` \`${field.Field}\` ${field.Type} ${field.NotNull ? 'NOT NULL' : ''} ${defaultClause};`;
93
- logger(`Executing: ${dropFieldSQL}`);
95
+ console.log(`Executing: ${dropFieldSQL}`);
94
96
  await connection.query(dropFieldSQL);
95
97
 
96
98
  } else if (diff.type === 'missing_index') {
@@ -112,7 +114,7 @@ export const applyDifferences = async (connection, database, differences) => {
112
114
  if (diff.index.Name === 'PRIMARY') {
113
115
  if (indexColumns.length > 0) {
114
116
  const primaryKeySQL = `ALTER TABLE \`${diff.tableName}\` ADD PRIMARY KEY (${indexColumns.join(', ')});`;
115
- logger(`Executing: ${primaryKeySQL}`);
117
+ console.log(`Executing: ${primaryKeySQL}`);
116
118
  await connection.query(primaryKeySQL);
117
119
  } else {
118
120
  logger(`Cannot create PRIMARY index on ${diff.tableName}. ColumnName is undefined or empty.`, diff.index);
@@ -122,7 +124,7 @@ export const applyDifferences = async (connection, database, differences) => {
122
124
  const uniqueSQL = diff.index.Unique ? 'UNIQUE ' : ''; // Check if the index is unique
123
125
  if (indexColumns.length > 0) {
124
126
  const addIndexSQL = `ALTER TABLE \`${diff.tableName}\` ADD ${uniqueSQL}INDEX \`${diff.index.Name}\` (${indexColumns.join(', ')});`;
125
- logger(`Executing: ${addIndexSQL}`);
127
+ console.log(`Executing: ${addIndexSQL}`);
126
128
  await connection.query(addIndexSQL);
127
129
  } else {
128
130
  logger(`Cannot create index ${diff.index.Name} on ${diff.tableName}. ColumnName is undefined or empty.`, diff.index);
@@ -133,11 +135,11 @@ export const applyDifferences = async (connection, database, differences) => {
133
135
  // Handle dropping of extra indexes
134
136
  if (diff.index.Name === 'PRIMARY') {
135
137
  const dropPrimaryKeySQL = `ALTER TABLE \`${diff.tableName}\` DROP PRIMARY KEY;`;
136
- logger(`Executing: ${dropPrimaryKeySQL}`);
138
+ console.log(`Executing: ${dropPrimaryKeySQL}`);
137
139
  await connection.query(dropPrimaryKeySQL);
138
140
  } else {
139
141
  const dropIndexSQL = `DROP INDEX \`${diff.index.Name}\` ON \`${diff.tableName}\`;`;
140
- logger(`Executing: ${dropIndexSQL}`);
142
+ console.log(`Executing: ${dropIndexSQL}`);
141
143
  await connection.query(dropIndexSQL);
142
144
  }
143
145
 
@@ -146,11 +148,11 @@ export const applyDifferences = async (connection, database, differences) => {
146
148
  // Drop the existing index
147
149
  if (index.Name === 'PRIMARY') {
148
150
  const dropPrimaryKeySQL = `ALTER TABLE \`${tableName}\` DROP PRIMARY KEY;`;
149
- logger(`Executing: ${dropPrimaryKeySQL}`);
151
+ console.log(`Executing: ${dropPrimaryKeySQL}`);
150
152
  await connection.query(dropPrimaryKeySQL);
151
153
  } else {
152
154
  const dropIndexSQL = `DROP INDEX \`${index.Name}\` ON \`${tableName}\`;`;
153
- logger(`Executing: ${dropIndexSQL}`);
155
+ console.log(`Executing: ${dropIndexSQL}`);
154
156
  await connection.query(dropIndexSQL);
155
157
  }
156
158
  console.log('index', index)
@@ -159,11 +161,11 @@ export const applyDifferences = async (connection, database, differences) => {
159
161
  const uniqueSQL = index.Unique ? 'UNIQUE ' : ''; // Check if the index is unique
160
162
  if (index.Name === 'PRIMARY') {
161
163
  const addPrimaryKeySQL = `ALTER TABLE \`${tableName}\` ADD PRIMARY KEY (${index.ColumnName.join(', ')});`;
162
- logger(`Executing: ${addPrimaryKeySQL}`);
164
+ console.log(`Executing: ${addPrimaryKeySQL}`);
163
165
  await connection.query(addPrimaryKeySQL);
164
166
  } else {
165
167
  const addIndexSQL = `ALTER TABLE \`${tableName}\` ADD ${uniqueSQL}INDEX \`${index.Name}\` (${index.ColumnName.join(', ')});`; // Include UNIQUE if applicable
166
- logger(`Executing: ${addIndexSQL}`);
168
+ console.log(`Executing: ${addIndexSQL}`);
167
169
  await connection.query(addIndexSQL);
168
170
  }
169
171
 
@@ -171,65 +173,65 @@ export const applyDifferences = async (connection, database, differences) => {
171
173
 
172
174
  // Drop the procedure if it exists
173
175
  const dropCurrentProcSQL = `DROP PROCEDURE IF EXISTS \`${diff.Name}\`;`;
174
- logger(`Executing: ${dropCurrentProcSQL}`);
176
+ console.log(`Executing: ${dropCurrentProcSQL}`);
175
177
  await connection.query(dropCurrentProcSQL);
176
178
 
177
179
  // Create the procedure
178
180
  const createProcSQL = diff.Definition;
179
- logger(`Executing: ${createProcSQL}`); // Log the SQL statement
181
+ console.log(`Executing: ${createProcSQL}`); // Log the SQL statement
180
182
  await connection.query(createProcSQL);
181
183
 
182
184
 
183
185
 
184
186
  } else if (diff.type === 'missing_view') {
185
187
  const dropViewSQL = `DROP VIEW IF EXISTS \`${diff.viewName}\`;`;
186
- logger(`Executing: ${dropViewSQL}`);
188
+ console.log(`Executing: ${dropViewSQL}`);
187
189
  await connection.query(dropViewSQL);
188
190
  const createViewSQL = diff.definition; // Use the expected definition to create the view
189
- logger(`Executing: ${createViewSQL}`);
191
+ console.log(`Executing: ${createViewSQL}`);
190
192
  await connection.query(createViewSQL);
191
193
 
192
194
 
193
195
  } else if (diff.type === 'mismatched_view') {
194
196
  const dropViewSQL = `DROP VIEW IF EXISTS \`${diff.viewName}\`;`;
195
- logger(`Executing: ${dropViewSQL}`);
197
+ console.log(`Executing: ${dropViewSQL}`);
196
198
  await connection.query(dropViewSQL);
197
199
  const createViewSQL = diff.definition; // Use the expected definition to create the view
198
- logger(`Executing: ${createViewSQL}`);
200
+ console.log(`Executing: ${createViewSQL}`);
199
201
  await connection.query(createViewSQL);
200
202
 
201
203
 
202
204
  } else if (diff.type === 'extra_view') {
203
205
  const dropViewSQL = `DROP VIEW IF EXISTS \`${diff.viewName}\`;`;
204
- logger(`Executing: ${dropViewSQL}`);
206
+ console.log(`Executing: ${dropViewSQL}`);
205
207
  await connection.query(dropViewSQL);
206
208
 
207
209
 
208
210
  } else if (diff.type === 'missing_trigger') {
209
211
  const createTriggerSQL = diff.trigger.Definition;
210
212
  logger('fixing trigger', diff.trigger.Name)
211
- logger(`Executing: ${createTriggerSQL}`);
213
+ console.log(`Executing: ${createTriggerSQL}`);
212
214
  await connection.query(createTriggerSQL);
213
215
 
214
216
 
215
217
  } else if (diff.type === 'mismatched_trigger') {
216
218
  const dropTriggerSQL = `DROP TRIGGER IF EXISTS \`${diff.trigger.Name}\`;`;
217
- logger(`Executing: ${dropTriggerSQL}`);
219
+ console.log(`Executing: ${dropTriggerSQL}`);
218
220
  await connection.query(dropTriggerSQL);
219
221
  const createTriggerSQL = diff.trigger.Definition;
220
- logger(`Executing: ${createTriggerSQL}`);
222
+ console.log(`Executing: ${createTriggerSQL}`);
221
223
  await connection.query(createTriggerSQL);
222
224
 
223
225
 
224
226
  } else if (diff.type === 'extra_trigger') {
225
227
  const dropTriggerSQL = `DROP TRIGGER IF EXISTS \`${diff.trigger.Name}\`;`;
226
- logger(`Executing: ${dropTriggerSQL}`);
228
+ console.log(`Executing: ${dropTriggerSQL}`);
227
229
  await connection.query(dropTriggerSQL);
228
230
 
229
231
  }else if(diff.type === 'missing_database'){
230
232
  logger('fixing missing database', diff.database)
231
233
  const createDatabaseSQL = `CREATE DATABASE \`${diff.database}\`;`;
232
- logger(`Executing: ${createDatabaseSQL}`);
234
+ console.log(`Executing: ${createDatabaseSQL}`);
233
235
  await connection.query(createDatabaseSQL);
234
236
  } else {
235
237
  logger(`Error applying difference of type:${diff.type}`, diff)