mysqlsyncr 1.1.0 → 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 +28 -28
- package/dist/index.js +28 -28
- package/package.json +1 -1
- package/src/apply.js +28 -28
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3686
|
+
console.log("Executing: ".concat(dropFieldSQL));
|
|
3687
3687
|
_context.next = 50;
|
|
3688
3688
|
return connection.query(dropFieldSQL);
|
|
3689
3689
|
case 50:
|
|
@@ -3697,7 +3697,7 @@ var applyDifferences = /*#__PURE__*/function () {
|
|
|
3697
3697
|
_tableName2 = diff.tableName, field = diff.field;
|
|
3698
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3683
|
+
console.log("Executing: ".concat(dropFieldSQL));
|
|
3684
3684
|
_context.next = 50;
|
|
3685
3685
|
return connection.query(dropFieldSQL);
|
|
3686
3686
|
case 50:
|
|
@@ -3694,7 +3694,7 @@ var applyDifferences = /*#__PURE__*/function () {
|
|
|
3694
3694
|
_tableName2 = diff.tableName, field = diff.field;
|
|
3695
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
65
|
+
console.log(`Executing: ${modifyFieldSQL}`);
|
|
66
66
|
await connection.query(modifyFieldSQL);
|
|
67
67
|
}
|
|
68
68
|
if(diff.field.Default){
|
|
@@ -72,13 +72,13 @@ export const applyDifferences = async (connection, database, differences) => {
|
|
|
72
72
|
? `DEFAULT '${diff.field.Default}'`
|
|
73
73
|
: '';
|
|
74
74
|
const modifyFieldSQL = `ALTER TABLE \`${diff.tableName}\` MODIFY \`${diff.field.Field}\` ${diff.field.Type} ${defaultClause};`;
|
|
75
|
-
|
|
75
|
+
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
|
-
|
|
81
|
+
console.log(`Executing: ${dropFieldSQL}`);
|
|
82
82
|
await connection.query(dropFieldSQL);
|
|
83
83
|
|
|
84
84
|
} else if (diff.type === 'mismatched_field') {
|
|
@@ -92,7 +92,7 @@ export const applyDifferences = async (connection, database, differences) => {
|
|
|
92
92
|
: 'DEFAULT NULL';
|
|
93
93
|
|
|
94
94
|
const dropFieldSQL = `ALTER TABLE \`${tableName}\` CHANGE \`${field.Field}\` \`${field.Field}\` ${field.Type} ${field.NotNull ? 'NOT NULL' : ''} ${defaultClause};`;
|
|
95
|
-
|
|
95
|
+
console.log(`Executing: ${dropFieldSQL}`);
|
|
96
96
|
await connection.query(dropFieldSQL);
|
|
97
97
|
|
|
98
98
|
} else if (diff.type === 'missing_index') {
|
|
@@ -114,7 +114,7 @@ export const applyDifferences = async (connection, database, differences) => {
|
|
|
114
114
|
if (diff.index.Name === 'PRIMARY') {
|
|
115
115
|
if (indexColumns.length > 0) {
|
|
116
116
|
const primaryKeySQL = `ALTER TABLE \`${diff.tableName}\` ADD PRIMARY KEY (${indexColumns.join(', ')});`;
|
|
117
|
-
|
|
117
|
+
console.log(`Executing: ${primaryKeySQL}`);
|
|
118
118
|
await connection.query(primaryKeySQL);
|
|
119
119
|
} else {
|
|
120
120
|
logger(`Cannot create PRIMARY index on ${diff.tableName}. ColumnName is undefined or empty.`, diff.index);
|
|
@@ -124,7 +124,7 @@ export const applyDifferences = async (connection, database, differences) => {
|
|
|
124
124
|
const uniqueSQL = diff.index.Unique ? 'UNIQUE ' : ''; // Check if the index is unique
|
|
125
125
|
if (indexColumns.length > 0) {
|
|
126
126
|
const addIndexSQL = `ALTER TABLE \`${diff.tableName}\` ADD ${uniqueSQL}INDEX \`${diff.index.Name}\` (${indexColumns.join(', ')});`;
|
|
127
|
-
|
|
127
|
+
console.log(`Executing: ${addIndexSQL}`);
|
|
128
128
|
await connection.query(addIndexSQL);
|
|
129
129
|
} else {
|
|
130
130
|
logger(`Cannot create index ${diff.index.Name} on ${diff.tableName}. ColumnName is undefined or empty.`, diff.index);
|
|
@@ -135,11 +135,11 @@ export const applyDifferences = async (connection, database, differences) => {
|
|
|
135
135
|
// Handle dropping of extra indexes
|
|
136
136
|
if (diff.index.Name === 'PRIMARY') {
|
|
137
137
|
const dropPrimaryKeySQL = `ALTER TABLE \`${diff.tableName}\` DROP PRIMARY KEY;`;
|
|
138
|
-
|
|
138
|
+
console.log(`Executing: ${dropPrimaryKeySQL}`);
|
|
139
139
|
await connection.query(dropPrimaryKeySQL);
|
|
140
140
|
} else {
|
|
141
141
|
const dropIndexSQL = `DROP INDEX \`${diff.index.Name}\` ON \`${diff.tableName}\`;`;
|
|
142
|
-
|
|
142
|
+
console.log(`Executing: ${dropIndexSQL}`);
|
|
143
143
|
await connection.query(dropIndexSQL);
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -148,11 +148,11 @@ export const applyDifferences = async (connection, database, differences) => {
|
|
|
148
148
|
// Drop the existing index
|
|
149
149
|
if (index.Name === 'PRIMARY') {
|
|
150
150
|
const dropPrimaryKeySQL = `ALTER TABLE \`${tableName}\` DROP PRIMARY KEY;`;
|
|
151
|
-
|
|
151
|
+
console.log(`Executing: ${dropPrimaryKeySQL}`);
|
|
152
152
|
await connection.query(dropPrimaryKeySQL);
|
|
153
153
|
} else {
|
|
154
154
|
const dropIndexSQL = `DROP INDEX \`${index.Name}\` ON \`${tableName}\`;`;
|
|
155
|
-
|
|
155
|
+
console.log(`Executing: ${dropIndexSQL}`);
|
|
156
156
|
await connection.query(dropIndexSQL);
|
|
157
157
|
}
|
|
158
158
|
console.log('index', index)
|
|
@@ -161,11 +161,11 @@ export const applyDifferences = async (connection, database, differences) => {
|
|
|
161
161
|
const uniqueSQL = index.Unique ? 'UNIQUE ' : ''; // Check if the index is unique
|
|
162
162
|
if (index.Name === 'PRIMARY') {
|
|
163
163
|
const addPrimaryKeySQL = `ALTER TABLE \`${tableName}\` ADD PRIMARY KEY (${index.ColumnName.join(', ')});`;
|
|
164
|
-
|
|
164
|
+
console.log(`Executing: ${addPrimaryKeySQL}`);
|
|
165
165
|
await connection.query(addPrimaryKeySQL);
|
|
166
166
|
} else {
|
|
167
167
|
const addIndexSQL = `ALTER TABLE \`${tableName}\` ADD ${uniqueSQL}INDEX \`${index.Name}\` (${index.ColumnName.join(', ')});`; // Include UNIQUE if applicable
|
|
168
|
-
|
|
168
|
+
console.log(`Executing: ${addIndexSQL}`);
|
|
169
169
|
await connection.query(addIndexSQL);
|
|
170
170
|
}
|
|
171
171
|
|
|
@@ -173,65 +173,65 @@ export const applyDifferences = async (connection, database, differences) => {
|
|
|
173
173
|
|
|
174
174
|
// Drop the procedure if it exists
|
|
175
175
|
const dropCurrentProcSQL = `DROP PROCEDURE IF EXISTS \`${diff.Name}\`;`;
|
|
176
|
-
|
|
176
|
+
console.log(`Executing: ${dropCurrentProcSQL}`);
|
|
177
177
|
await connection.query(dropCurrentProcSQL);
|
|
178
178
|
|
|
179
179
|
// Create the procedure
|
|
180
180
|
const createProcSQL = diff.Definition;
|
|
181
|
-
|
|
181
|
+
console.log(`Executing: ${createProcSQL}`); // Log the SQL statement
|
|
182
182
|
await connection.query(createProcSQL);
|
|
183
183
|
|
|
184
184
|
|
|
185
185
|
|
|
186
186
|
} else if (diff.type === 'missing_view') {
|
|
187
187
|
const dropViewSQL = `DROP VIEW IF EXISTS \`${diff.viewName}\`;`;
|
|
188
|
-
|
|
188
|
+
console.log(`Executing: ${dropViewSQL}`);
|
|
189
189
|
await connection.query(dropViewSQL);
|
|
190
190
|
const createViewSQL = diff.definition; // Use the expected definition to create the view
|
|
191
|
-
|
|
191
|
+
console.log(`Executing: ${createViewSQL}`);
|
|
192
192
|
await connection.query(createViewSQL);
|
|
193
193
|
|
|
194
194
|
|
|
195
195
|
} else if (diff.type === 'mismatched_view') {
|
|
196
196
|
const dropViewSQL = `DROP VIEW IF EXISTS \`${diff.viewName}\`;`;
|
|
197
|
-
|
|
197
|
+
console.log(`Executing: ${dropViewSQL}`);
|
|
198
198
|
await connection.query(dropViewSQL);
|
|
199
199
|
const createViewSQL = diff.definition; // Use the expected definition to create the view
|
|
200
|
-
|
|
200
|
+
console.log(`Executing: ${createViewSQL}`);
|
|
201
201
|
await connection.query(createViewSQL);
|
|
202
202
|
|
|
203
203
|
|
|
204
204
|
} else if (diff.type === 'extra_view') {
|
|
205
205
|
const dropViewSQL = `DROP VIEW IF EXISTS \`${diff.viewName}\`;`;
|
|
206
|
-
|
|
206
|
+
console.log(`Executing: ${dropViewSQL}`);
|
|
207
207
|
await connection.query(dropViewSQL);
|
|
208
208
|
|
|
209
209
|
|
|
210
210
|
} else if (diff.type === 'missing_trigger') {
|
|
211
211
|
const createTriggerSQL = diff.trigger.Definition;
|
|
212
212
|
logger('fixing trigger', diff.trigger.Name)
|
|
213
|
-
|
|
213
|
+
console.log(`Executing: ${createTriggerSQL}`);
|
|
214
214
|
await connection.query(createTriggerSQL);
|
|
215
215
|
|
|
216
216
|
|
|
217
217
|
} else if (diff.type === 'mismatched_trigger') {
|
|
218
218
|
const dropTriggerSQL = `DROP TRIGGER IF EXISTS \`${diff.trigger.Name}\`;`;
|
|
219
|
-
|
|
219
|
+
console.log(`Executing: ${dropTriggerSQL}`);
|
|
220
220
|
await connection.query(dropTriggerSQL);
|
|
221
221
|
const createTriggerSQL = diff.trigger.Definition;
|
|
222
|
-
|
|
222
|
+
console.log(`Executing: ${createTriggerSQL}`);
|
|
223
223
|
await connection.query(createTriggerSQL);
|
|
224
224
|
|
|
225
225
|
|
|
226
226
|
} else if (diff.type === 'extra_trigger') {
|
|
227
227
|
const dropTriggerSQL = `DROP TRIGGER IF EXISTS \`${diff.trigger.Name}\`;`;
|
|
228
|
-
|
|
228
|
+
console.log(`Executing: ${dropTriggerSQL}`);
|
|
229
229
|
await connection.query(dropTriggerSQL);
|
|
230
230
|
|
|
231
231
|
}else if(diff.type === 'missing_database'){
|
|
232
232
|
logger('fixing missing database', diff.database)
|
|
233
233
|
const createDatabaseSQL = `CREATE DATABASE \`${diff.database}\`;`;
|
|
234
|
-
|
|
234
|
+
console.log(`Executing: ${createDatabaseSQL}`);
|
|
235
235
|
await connection.query(createDatabaseSQL);
|
|
236
236
|
} else {
|
|
237
237
|
logger(`Error applying difference of type:${diff.type}`, diff)
|