@berthojoris/mcp-mysql-server 1.8.0 → 1.9.0

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/DOCUMENTATIONS.md CHANGED
@@ -770,6 +770,481 @@ Synchronize data between two tables based on a key column. Supports three modes:
770
770
 
771
771
  ---
772
772
 
773
+ ## 🔄 Schema Versioning and Migrations
774
+
775
+ The MySQL MCP Server provides comprehensive schema versioning and migration tools for managing database schema changes in a controlled, trackable manner. This feature enables version control for your database schema with support for applying and rolling back migrations.
776
+
777
+ ### Schema Versioning Tools Overview
778
+
779
+ | Tool | Description | Permission |
780
+ |------|-------------|------------|
781
+ | `init_migrations_table` | Initialize the migrations tracking table | ddl |
782
+ | `create_migration` | Create a new migration entry | ddl |
783
+ | `apply_migrations` | Apply pending migrations | ddl |
784
+ | `rollback_migration` | Rollback applied migrations | ddl |
785
+ | `get_migration_status` | Get migration history and status | list |
786
+ | `get_schema_version` | Get current schema version | list |
787
+ | `validate_migrations` | Validate migrations for issues | list |
788
+ | `reset_failed_migration` | Reset a failed migration to pending | ddl |
789
+ | `generate_migration_from_diff` | Generate migration from table comparison | ddl |
790
+
791
+ ### ⚠️ Enable Schema Versioning
792
+
793
+ Schema versioning operations require `ddl` permission:
794
+
795
+ ```json
796
+ "args": [
797
+ "--mysql-host", "localhost",
798
+ "--mysql-user", "root",
799
+ "--mysql-password", "password",
800
+ "--mysql-database", "mydb",
801
+ "--permissions", "list,read,create,update,delete,ddl"
802
+ ]
803
+ ```
804
+
805
+ ### Initialize Migrations Table
806
+
807
+ Before using migrations, initialize the tracking table:
808
+
809
+ ```json
810
+ {
811
+ "tool": "init_migrations_table",
812
+ "arguments": {}
813
+ }
814
+ ```
815
+
816
+ **Response:**
817
+ ```json
818
+ {
819
+ "status": "success",
820
+ "data": {
821
+ "message": "Migrations table '_schema_migrations' initialized successfully",
822
+ "table_name": "_schema_migrations"
823
+ }
824
+ }
825
+ ```
826
+
827
+ ### Creating Migrations
828
+
829
+ Create a migration with up and down SQL:
830
+
831
+ ```json
832
+ {
833
+ "tool": "create_migration",
834
+ "arguments": {
835
+ "name": "add_users_table",
836
+ "description": "Create the users table with basic fields",
837
+ "up_sql": "CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) NOT NULL UNIQUE, name VARCHAR(100), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);",
838
+ "down_sql": "DROP TABLE IF EXISTS users;"
839
+ }
840
+ }
841
+ ```
842
+
843
+ **Response:**
844
+ ```json
845
+ {
846
+ "status": "success",
847
+ "data": {
848
+ "message": "Migration 'add_users_table' created successfully",
849
+ "version": "20240115120000",
850
+ "name": "add_users_table",
851
+ "checksum": "a1b2c3d4",
852
+ "status": "pending"
853
+ }
854
+ }
855
+ ```
856
+
857
+ #### Multi-Statement Migrations
858
+
859
+ Migrations can contain multiple SQL statements separated by semicolons:
860
+
861
+ ```json
862
+ {
863
+ "tool": "create_migration",
864
+ "arguments": {
865
+ "name": "add_orders_and_items",
866
+ "up_sql": "CREATE TABLE orders (id INT AUTO_INCREMENT PRIMARY KEY, user_id INT, total DECIMAL(10,2), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP); CREATE TABLE order_items (id INT AUTO_INCREMENT PRIMARY KEY, order_id INT, product_id INT, quantity INT, price DECIMAL(10,2)); ALTER TABLE order_items ADD CONSTRAINT fk_order FOREIGN KEY (order_id) REFERENCES orders(id);",
867
+ "down_sql": "DROP TABLE IF EXISTS order_items; DROP TABLE IF EXISTS orders;"
868
+ }
869
+ }
870
+ ```
871
+
872
+ ### Applying Migrations
873
+
874
+ Apply all pending migrations:
875
+
876
+ ```json
877
+ {
878
+ "tool": "apply_migrations",
879
+ "arguments": {}
880
+ }
881
+ ```
882
+
883
+ **Response:**
884
+ ```json
885
+ {
886
+ "status": "success",
887
+ "data": {
888
+ "message": "Successfully applied 3 migration(s)",
889
+ "applied_count": 3,
890
+ "failed_count": 0,
891
+ "applied_migrations": [
892
+ {"version": "20240115120000", "name": "add_users_table", "execution_time_ms": 45},
893
+ {"version": "20240115130000", "name": "add_orders_table", "execution_time_ms": 32},
894
+ {"version": "20240115140000", "name": "add_products_table", "execution_time_ms": 28}
895
+ ]
896
+ }
897
+ }
898
+ ```
899
+
900
+ #### Apply to Specific Version
901
+
902
+ ```json
903
+ {
904
+ "tool": "apply_migrations",
905
+ "arguments": {
906
+ "target_version": "20240115130000"
907
+ }
908
+ }
909
+ ```
910
+
911
+ #### Dry Run Mode
912
+
913
+ Preview migrations without executing:
914
+
915
+ ```json
916
+ {
917
+ "tool": "apply_migrations",
918
+ "arguments": {
919
+ "dry_run": true
920
+ }
921
+ }
922
+ ```
923
+
924
+ ### Rolling Back Migrations
925
+
926
+ Rollback the last migration:
927
+
928
+ ```json
929
+ {
930
+ "tool": "rollback_migration",
931
+ "arguments": {
932
+ "steps": 1
933
+ }
934
+ }
935
+ ```
936
+
937
+ Rollback multiple migrations:
938
+
939
+ ```json
940
+ {
941
+ "tool": "rollback_migration",
942
+ "arguments": {
943
+ "steps": 3
944
+ }
945
+ }
946
+ ```
947
+
948
+ Rollback to a specific version (exclusive):
949
+
950
+ ```json
951
+ {
952
+ "tool": "rollback_migration",
953
+ "arguments": {
954
+ "target_version": "20240115120000"
955
+ }
956
+ }
957
+ ```
958
+
959
+ **Response:**
960
+ ```json
961
+ {
962
+ "status": "success",
963
+ "data": {
964
+ "message": "Successfully rolled back 2 migration(s)",
965
+ "rolled_back_count": 2,
966
+ "failed_count": 0,
967
+ "rolled_back_migrations": [
968
+ {"version": "20240115140000", "name": "add_products_table", "execution_time_ms": 15},
969
+ {"version": "20240115130000", "name": "add_orders_table", "execution_time_ms": 12}
970
+ ]
971
+ }
972
+ }
973
+ ```
974
+
975
+ ### Getting Schema Version
976
+
977
+ Check the current schema version:
978
+
979
+ ```json
980
+ {
981
+ "tool": "get_schema_version",
982
+ "arguments": {}
983
+ }
984
+ ```
985
+
986
+ **Response:**
987
+ ```json
988
+ {
989
+ "status": "success",
990
+ "data": {
991
+ "current_version": "20240115140000",
992
+ "current_migration_name": "add_products_table",
993
+ "applied_at": "2024-01-15T14:30:00.000Z",
994
+ "pending_migrations": 2,
995
+ "migrations_table_exists": true
996
+ }
997
+ }
998
+ ```
999
+
1000
+ ### Getting Migration Status
1001
+
1002
+ View migration history with status:
1003
+
1004
+ ```json
1005
+ {
1006
+ "tool": "get_migration_status",
1007
+ "arguments": {
1008
+ "limit": 10
1009
+ }
1010
+ }
1011
+ ```
1012
+
1013
+ Filter by status:
1014
+
1015
+ ```json
1016
+ {
1017
+ "tool": "get_migration_status",
1018
+ "arguments": {
1019
+ "status": "failed"
1020
+ }
1021
+ }
1022
+ ```
1023
+
1024
+ **Response:**
1025
+ ```json
1026
+ {
1027
+ "status": "success",
1028
+ "data": {
1029
+ "current_version": "20240115140000",
1030
+ "summary": {
1031
+ "total": 5,
1032
+ "pending": 1,
1033
+ "applied": 3,
1034
+ "failed": 1,
1035
+ "rolled_back": 0
1036
+ },
1037
+ "migrations": [
1038
+ {
1039
+ "id": 5,
1040
+ "version": "20240115150000",
1041
+ "name": "add_analytics_table",
1042
+ "status": "pending",
1043
+ "applied_at": null,
1044
+ "execution_time_ms": null
1045
+ },
1046
+ {
1047
+ "id": 4,
1048
+ "version": "20240115140000",
1049
+ "name": "add_products_table",
1050
+ "status": "applied",
1051
+ "applied_at": "2024-01-15T14:30:00.000Z",
1052
+ "execution_time_ms": 28
1053
+ }
1054
+ ]
1055
+ }
1056
+ }
1057
+ ```
1058
+
1059
+ ### Validating Migrations
1060
+
1061
+ Check migrations for potential issues:
1062
+
1063
+ ```json
1064
+ {
1065
+ "tool": "validate_migrations",
1066
+ "arguments": {}
1067
+ }
1068
+ ```
1069
+
1070
+ **Response:**
1071
+ ```json
1072
+ {
1073
+ "status": "success",
1074
+ "data": {
1075
+ "valid": false,
1076
+ "total_migrations": 5,
1077
+ "issues_count": 1,
1078
+ "warnings_count": 2,
1079
+ "issues": [
1080
+ {
1081
+ "type": "checksum_mismatch",
1082
+ "version": "20240115120000",
1083
+ "name": "add_users_table",
1084
+ "message": "Migration 'add_users_table' checksum mismatch - migration may have been modified after being applied"
1085
+ }
1086
+ ],
1087
+ "warnings": [
1088
+ {
1089
+ "type": "missing_down_sql",
1090
+ "version": "20240115150000",
1091
+ "name": "add_analytics_table",
1092
+ "message": "Migration 'add_analytics_table' has no down_sql - rollback will not be possible"
1093
+ },
1094
+ {
1095
+ "type": "blocked_migrations",
1096
+ "message": "1 pending migration(s) are blocked by failed migration 'add_audit_table'"
1097
+ }
1098
+ ]
1099
+ }
1100
+ }
1101
+ ```
1102
+
1103
+ ### Resetting Failed Migrations
1104
+
1105
+ Reset a failed migration to try again:
1106
+
1107
+ ```json
1108
+ {
1109
+ "tool": "reset_failed_migration",
1110
+ "arguments": {
1111
+ "version": "20240115145000"
1112
+ }
1113
+ }
1114
+ ```
1115
+
1116
+ **Response:**
1117
+ ```json
1118
+ {
1119
+ "status": "success",
1120
+ "data": {
1121
+ "message": "Migration 'add_audit_table' (20240115145000) has been reset to pending status",
1122
+ "version": "20240115145000",
1123
+ "name": "add_audit_table",
1124
+ "previous_status": "failed",
1125
+ "new_status": "pending"
1126
+ }
1127
+ }
1128
+ ```
1129
+
1130
+ ### Generating Migrations from Table Differences
1131
+
1132
+ Automatically generate a migration by comparing two table structures:
1133
+
1134
+ ```json
1135
+ {
1136
+ "tool": "generate_migration_from_diff",
1137
+ "arguments": {
1138
+ "table1": "users_v2",
1139
+ "table2": "users",
1140
+ "migration_name": "update_users_to_v2"
1141
+ }
1142
+ }
1143
+ ```
1144
+
1145
+ **Response:**
1146
+ ```json
1147
+ {
1148
+ "status": "success",
1149
+ "data": {
1150
+ "message": "Migration 'update_users_to_v2' generated with 3 change(s)",
1151
+ "version": "20240115160000",
1152
+ "changes_count": 3,
1153
+ "up_sql": "ALTER TABLE `users` ADD COLUMN `phone` VARCHAR(20) NULL;\nALTER TABLE `users` ADD COLUMN `avatar_url` VARCHAR(500) NULL;\nALTER TABLE `users` MODIFY COLUMN `name` VARCHAR(200) NOT NULL;",
1154
+ "down_sql": "ALTER TABLE `users` DROP COLUMN `phone`;\nALTER TABLE `users` DROP COLUMN `avatar_url`;\nALTER TABLE `users` MODIFY COLUMN `name` VARCHAR(100) NULL;",
1155
+ "source_table": "users_v2",
1156
+ "target_table": "users"
1157
+ }
1158
+ }
1159
+ ```
1160
+
1161
+ ### Migration Best Practices
1162
+
1163
+ 1. **Always include down_sql**: Enable rollback capability for all migrations
1164
+ 2. **Test migrations first**: Use `dry_run: true` to preview changes
1165
+ 3. **Validate before applying**: Run `validate_migrations` to check for issues
1166
+ 4. **Use descriptive names**: Make migration names clear and meaningful
1167
+ 5. **Keep migrations small**: One logical change per migration
1168
+ 6. **Version control migrations**: Store migration SQL in your VCS
1169
+ 7. **Never modify applied migrations**: Create new migrations for changes
1170
+ 8. **Backup before migrating**: Always backup production databases first
1171
+
1172
+ ### Common Migration Patterns
1173
+
1174
+ #### Adding a Column
1175
+
1176
+ ```json
1177
+ {
1178
+ "tool": "create_migration",
1179
+ "arguments": {
1180
+ "name": "add_user_phone",
1181
+ "up_sql": "ALTER TABLE users ADD COLUMN phone VARCHAR(20) NULL AFTER email;",
1182
+ "down_sql": "ALTER TABLE users DROP COLUMN phone;"
1183
+ }
1184
+ }
1185
+ ```
1186
+
1187
+ #### Adding an Index
1188
+
1189
+ ```json
1190
+ {
1191
+ "tool": "create_migration",
1192
+ "arguments": {
1193
+ "name": "add_email_index",
1194
+ "up_sql": "CREATE INDEX idx_users_email ON users(email);",
1195
+ "down_sql": "DROP INDEX idx_users_email ON users;"
1196
+ }
1197
+ }
1198
+ ```
1199
+
1200
+ #### Renaming a Column
1201
+
1202
+ ```json
1203
+ {
1204
+ "tool": "create_migration",
1205
+ "arguments": {
1206
+ "name": "rename_user_name_to_full_name",
1207
+ "up_sql": "ALTER TABLE users CHANGE COLUMN name full_name VARCHAR(100);",
1208
+ "down_sql": "ALTER TABLE users CHANGE COLUMN full_name name VARCHAR(100);"
1209
+ }
1210
+ }
1211
+ ```
1212
+
1213
+ #### Adding Foreign Key
1214
+
1215
+ ```json
1216
+ {
1217
+ "tool": "create_migration",
1218
+ "arguments": {
1219
+ "name": "add_orders_user_fk",
1220
+ "up_sql": "ALTER TABLE orders ADD CONSTRAINT fk_orders_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;",
1221
+ "down_sql": "ALTER TABLE orders DROP FOREIGN KEY fk_orders_user;"
1222
+ }
1223
+ }
1224
+ ```
1225
+
1226
+ ### Migration Table Schema
1227
+
1228
+ The `_schema_migrations` table stores all migration information:
1229
+
1230
+ | Column | Type | Description |
1231
+ |--------|------|-------------|
1232
+ | id | INT | Auto-increment primary key |
1233
+ | version | VARCHAR(14) | Migration version (timestamp-based) |
1234
+ | name | VARCHAR(255) | Migration name |
1235
+ | description | TEXT | Optional description |
1236
+ | up_sql | LONGTEXT | SQL to apply migration |
1237
+ | down_sql | LONGTEXT | SQL to rollback migration |
1238
+ | checksum | VARCHAR(64) | Checksum of up_sql for integrity |
1239
+ | applied_at | TIMESTAMP | When migration was applied |
1240
+ | applied_by | VARCHAR(255) | User who applied migration |
1241
+ | execution_time_ms | INT | Execution time in milliseconds |
1242
+ | status | ENUM | pending, applied, failed, rolled_back |
1243
+ | error_message | TEXT | Error message if failed |
1244
+ | created_at | TIMESTAMP | When migration was created |
1245
+
1246
+ ---
1247
+
773
1248
  ## 💰 Transaction Management
774
1249
 
775
1250
  The MySQL MCP Server provides full ACID transaction support, allowing you to group multiple database operations into atomic units.
@@ -2385,10 +2860,10 @@ MIT License - see [LICENSE](LICENSE) file for details.
2385
2860
  - ✅ **Database backup and restore tools** - **COMPLETED!**
2386
2861
  - ✅ **Data export/import utilities** (CSV, JSON, SQL dumps) - **COMPLETED!**
2387
2862
  - ✅ **Data migration utilities** - **COMPLETED!**
2863
+ - ✅ **Schema versioning and migrations** - **COMPLETED!**
2388
2864
  - [ ] **Performance monitoring and metrics**
2389
2865
  - [ ] **Connection pool monitoring**
2390
2866
  - [ ] **Audit logging and compliance**
2391
- - [ ] **Schema versioning and migrations**
2392
2867
 
2393
2868
  ### Database Adapters
2394
2869
  - [ ] PostgreSQL adapter
@@ -2413,7 +2888,7 @@ MIT License - see [LICENSE](LICENSE) file for details.
2413
2888
 
2414
2889
  #### **Phase 3: Enterprise Features** 🏢
2415
2890
  - [ ] **Audit logging and compliance** - Track all database operations for security
2416
- - [ ] **Schema versioning and migrations** - Version control for database schema changes
2891
+ - **Schema versioning and migrations** - Version control for database schema changes - **COMPLETED!**
2417
2892
  - ✅ **Query optimization** - Automatic query analysis and optimization suggestions - **COMPLETED!**
2418
2893
  - [ ] **Advanced security features** - Enhanced access control and monitoring
2419
2894
 
@@ -2439,10 +2914,10 @@ MIT License - see [LICENSE](LICENSE) file for details.
2439
2914
  | Database Backup/Restore | High | High | 10 | ✅ COMPLETED |
2440
2915
  | Data Export/Import (JSON, SQL) | High | Medium | 11 | ✅ COMPLETED |
2441
2916
  | Data Migration | High | High | 12 | ✅ COMPLETED |
2442
- | Performance Monitoring | High | Medium | 13 | Pending |
2443
- | PostgreSQL Adapter | High | High | 14 | Pending |
2444
- | Audit Logging | Medium | Low | 14 | Pending |
2445
- | Schema Versioning | Medium | Medium | 15 | Pending |
2917
+ | Schema Versioning | Medium | Medium | 13 | COMPLETED |
2918
+ | Performance Monitoring | High | Medium | 14 | Pending |
2919
+ | PostgreSQL Adapter | High | High | 15 | Pending |
2920
+ | Audit Logging | Medium | Low | 16 | Pending |
2446
2921
 
2447
2922
  ---
2448
2923