@berthojoris/mcp-mysql-server 1.7.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 +797 -33
- package/README.md +400 -138
- package/dist/config/featureConfig.js +16 -0
- package/dist/index.d.ts +180 -0
- package/dist/index.js +133 -0
- package/dist/mcp-server.js +421 -0
- package/dist/tools/migrationTools.d.ts +96 -0
- package/dist/tools/migrationTools.js +546 -0
- package/dist/tools/schemaVersioningTools.d.ts +147 -0
- package/dist/tools/schemaVersioningTools.js +1007 -0
- package/package.json +2 -2
package/DOCUMENTATIONS.md
CHANGED
|
@@ -8,26 +8,27 @@ This file contains detailed documentation for all features of the MySQL MCP Serv
|
|
|
8
8
|
|
|
9
9
|
1. [DDL Operations](#ποΈ-ddl-operations)
|
|
10
10
|
2. [Data Export Tools](#π€-data-export-tools)
|
|
11
|
-
3. [Data Import Tools](#π₯-data-import-tools)
|
|
12
|
-
4. [Database Backup & Restore](#πΎ-database-backup--restore)
|
|
13
|
-
5. [
|
|
14
|
-
6. [
|
|
15
|
-
7. [
|
|
16
|
-
8. [
|
|
17
|
-
9. [
|
|
18
|
-
10. [
|
|
19
|
-
11. [
|
|
20
|
-
12. [
|
|
21
|
-
13. [
|
|
22
|
-
14. [
|
|
23
|
-
15. [
|
|
24
|
-
16. [
|
|
25
|
-
17. [
|
|
26
|
-
18. [Query
|
|
27
|
-
19. [
|
|
28
|
-
20. [
|
|
29
|
-
21. [
|
|
30
|
-
22. [
|
|
11
|
+
3. [Data Import Tools](#π₯-data-import-tools)
|
|
12
|
+
4. [Database Backup & Restore](#πΎ-database-backup--restore)
|
|
13
|
+
5. [Data Migration Tools](#π-data-migration-tools) - NEW!
|
|
14
|
+
6. [Transaction Management](#π°-transaction-management)
|
|
15
|
+
7. [Stored Procedures](#π§-stored-procedures)
|
|
16
|
+
8. [Views Management](#ποΈ-views-management)
|
|
17
|
+
9. [Triggers Management](#β‘-triggers-management)
|
|
18
|
+
10. [Functions Management](#π’-functions-management)
|
|
19
|
+
11. [Index Management](#π-index-management)
|
|
20
|
+
12. [Constraint Management](#π-constraint-management)
|
|
21
|
+
13. [Table Maintenance](#π§-table-maintenance)
|
|
22
|
+
14. [Process & Server Management](#π-process--server-management)
|
|
23
|
+
15. [Usage Examples](#π-usage-examples)
|
|
24
|
+
16. [Query Logging & Automatic SQL Display](#π-query-logging--automatic-sql-display)
|
|
25
|
+
17. [Security Features](#π-security-features)
|
|
26
|
+
18. [Query Result Caching](#πΎ-query-result-caching)
|
|
27
|
+
19. [Query Optimization Hints](#π―-query-optimization-hints)
|
|
28
|
+
20. [Bulk Operations](#π-bulk-operations)
|
|
29
|
+
21. [Troubleshooting](#π οΈ-troubleshooting)
|
|
30
|
+
22. [License](#π-license)
|
|
31
|
+
23. [Roadmap](#πΊοΈ-roadmap)
|
|
31
32
|
|
|
32
33
|
---
|
|
33
34
|
|
|
@@ -481,6 +482,769 @@ Get a complete overview of all database objects:
|
|
|
481
482
|
|
|
482
483
|
---
|
|
483
484
|
|
|
485
|
+
## π Data Migration Tools
|
|
486
|
+
|
|
487
|
+
The MySQL MCP Server provides powerful data migration utilities for copying, moving, and synchronizing data between tables.
|
|
488
|
+
|
|
489
|
+
### Data Migration Tools Overview
|
|
490
|
+
|
|
491
|
+
| Tool | Description | Permission |
|
|
492
|
+
|------|-------------|------------|
|
|
493
|
+
| `copy_table_data` | Copy data from one table to another | `create` |
|
|
494
|
+
| `move_table_data` | Move data (copy + delete from source) | `create`, `delete` |
|
|
495
|
+
| `clone_table` | Clone table structure with optional data | `ddl` |
|
|
496
|
+
| `compare_table_structure` | Compare structure of two tables | `list` |
|
|
497
|
+
| `sync_table_data` | Synchronize data between tables | `update` |
|
|
498
|
+
|
|
499
|
+
### Copy Table Data
|
|
500
|
+
|
|
501
|
+
Copy data from one table to another with optional column mapping and filtering.
|
|
502
|
+
|
|
503
|
+
```json
|
|
504
|
+
{
|
|
505
|
+
"tool": "copy_table_data",
|
|
506
|
+
"arguments": {
|
|
507
|
+
"source_table": "users",
|
|
508
|
+
"target_table": "users_backup",
|
|
509
|
+
"batch_size": 1000
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
**With Column Mapping:**
|
|
515
|
+
```json
|
|
516
|
+
{
|
|
517
|
+
"tool": "copy_table_data",
|
|
518
|
+
"arguments": {
|
|
519
|
+
"source_table": "old_customers",
|
|
520
|
+
"target_table": "customers",
|
|
521
|
+
"column_mapping": {
|
|
522
|
+
"customer_name": "name",
|
|
523
|
+
"customer_email": "email",
|
|
524
|
+
"customer_phone": "phone"
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
**With Filters:**
|
|
531
|
+
```json
|
|
532
|
+
{
|
|
533
|
+
"tool": "copy_table_data",
|
|
534
|
+
"arguments": {
|
|
535
|
+
"source_table": "orders",
|
|
536
|
+
"target_table": "archived_orders",
|
|
537
|
+
"filters": [
|
|
538
|
+
{ "field": "status", "operator": "eq", "value": "completed" },
|
|
539
|
+
{ "field": "created_at", "operator": "lt", "value": "2024-01-01" }
|
|
540
|
+
]
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
**Response:**
|
|
546
|
+
```json
|
|
547
|
+
{
|
|
548
|
+
"status": "success",
|
|
549
|
+
"data": {
|
|
550
|
+
"message": "Data copied successfully",
|
|
551
|
+
"rows_copied": 5000,
|
|
552
|
+
"source_table": "orders",
|
|
553
|
+
"target_table": "archived_orders"
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
### Move Table Data
|
|
559
|
+
|
|
560
|
+
Move data from one table to another (copies data then deletes from source).
|
|
561
|
+
|
|
562
|
+
```json
|
|
563
|
+
{
|
|
564
|
+
"tool": "move_table_data",
|
|
565
|
+
"arguments": {
|
|
566
|
+
"source_table": "active_sessions",
|
|
567
|
+
"target_table": "expired_sessions",
|
|
568
|
+
"filters": [
|
|
569
|
+
{ "field": "expires_at", "operator": "lt", "value": "2024-01-01" }
|
|
570
|
+
]
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
**Response:**
|
|
576
|
+
```json
|
|
577
|
+
{
|
|
578
|
+
"status": "success",
|
|
579
|
+
"data": {
|
|
580
|
+
"message": "Data moved successfully",
|
|
581
|
+
"rows_moved": 1500,
|
|
582
|
+
"source_table": "active_sessions",
|
|
583
|
+
"target_table": "expired_sessions"
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
### Clone Table
|
|
589
|
+
|
|
590
|
+
Clone a table structure with or without data.
|
|
591
|
+
|
|
592
|
+
```json
|
|
593
|
+
{
|
|
594
|
+
"tool": "clone_table",
|
|
595
|
+
"arguments": {
|
|
596
|
+
"source_table": "products",
|
|
597
|
+
"new_table_name": "products_staging",
|
|
598
|
+
"include_data": false,
|
|
599
|
+
"include_indexes": true
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
**Clone with Data:**
|
|
605
|
+
```json
|
|
606
|
+
{
|
|
607
|
+
"tool": "clone_table",
|
|
608
|
+
"arguments": {
|
|
609
|
+
"source_table": "users",
|
|
610
|
+
"new_table_name": "users_test",
|
|
611
|
+
"include_data": true
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
**Response:**
|
|
617
|
+
```json
|
|
618
|
+
{
|
|
619
|
+
"status": "success",
|
|
620
|
+
"data": {
|
|
621
|
+
"message": "Table cloned successfully",
|
|
622
|
+
"source_table": "products",
|
|
623
|
+
"new_table": "products_staging",
|
|
624
|
+
"include_data": false,
|
|
625
|
+
"include_indexes": true
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
### Compare Table Structure
|
|
631
|
+
|
|
632
|
+
Compare the structure of two tables to identify differences.
|
|
633
|
+
|
|
634
|
+
```json
|
|
635
|
+
{
|
|
636
|
+
"tool": "compare_table_structure",
|
|
637
|
+
"arguments": {
|
|
638
|
+
"table1": "users",
|
|
639
|
+
"table2": "users_backup"
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
**Response:**
|
|
645
|
+
```json
|
|
646
|
+
{
|
|
647
|
+
"status": "success",
|
|
648
|
+
"data": {
|
|
649
|
+
"table1": "users",
|
|
650
|
+
"table2": "users_backup",
|
|
651
|
+
"identical": false,
|
|
652
|
+
"differences": {
|
|
653
|
+
"columns_only_in_table1": ["last_login", "avatar_url"],
|
|
654
|
+
"columns_only_in_table2": [],
|
|
655
|
+
"column_type_differences": [
|
|
656
|
+
{
|
|
657
|
+
"column": "email",
|
|
658
|
+
"table1_type": "VARCHAR(255)",
|
|
659
|
+
"table2_type": "VARCHAR(100)"
|
|
660
|
+
}
|
|
661
|
+
],
|
|
662
|
+
"index_differences": {
|
|
663
|
+
"only_in_table1": ["idx_last_login"],
|
|
664
|
+
"only_in_table2": []
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
### Sync Table Data
|
|
672
|
+
|
|
673
|
+
Synchronize data between two tables based on a key column. Supports three modes:
|
|
674
|
+
- **insert_only**: Only insert new records that don't exist in target
|
|
675
|
+
- **update_only**: Only update existing records in target
|
|
676
|
+
- **upsert**: Both insert new and update existing records (default)
|
|
677
|
+
|
|
678
|
+
```json
|
|
679
|
+
{
|
|
680
|
+
"tool": "sync_table_data",
|
|
681
|
+
"arguments": {
|
|
682
|
+
"source_table": "products_master",
|
|
683
|
+
"target_table": "products_replica",
|
|
684
|
+
"key_column": "product_id",
|
|
685
|
+
"sync_mode": "upsert"
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
**Sync Specific Columns:**
|
|
691
|
+
```json
|
|
692
|
+
{
|
|
693
|
+
"tool": "sync_table_data",
|
|
694
|
+
"arguments": {
|
|
695
|
+
"source_table": "inventory_main",
|
|
696
|
+
"target_table": "inventory_cache",
|
|
697
|
+
"key_column": "sku",
|
|
698
|
+
"columns_to_sync": ["quantity", "price", "updated_at"],
|
|
699
|
+
"sync_mode": "update_only"
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
**Response:**
|
|
705
|
+
```json
|
|
706
|
+
{
|
|
707
|
+
"status": "success",
|
|
708
|
+
"data": {
|
|
709
|
+
"message": "Sync completed successfully",
|
|
710
|
+
"source_table": "products_master",
|
|
711
|
+
"target_table": "products_replica",
|
|
712
|
+
"rows_inserted": 150,
|
|
713
|
+
"rows_updated": 3200,
|
|
714
|
+
"sync_mode": "upsert"
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
### Migration Best Practices
|
|
720
|
+
|
|
721
|
+
1. **Backup before migration** - Always backup target tables before large migrations
|
|
722
|
+
2. **Use filters** - Migrate data in chunks using filters to avoid timeouts
|
|
723
|
+
3. **Test with small batches** - Test migration logic with small datasets first
|
|
724
|
+
4. **Verify data integrity** - Use `compare_table_structure` before migration
|
|
725
|
+
5. **Monitor performance** - Adjust `batch_size` based on table size and server capacity
|
|
726
|
+
|
|
727
|
+
### Common Migration Patterns
|
|
728
|
+
|
|
729
|
+
**Pattern 1: Archive Old Data**
|
|
730
|
+
```json
|
|
731
|
+
// Move old orders to archive table
|
|
732
|
+
{
|
|
733
|
+
"tool": "move_table_data",
|
|
734
|
+
"arguments": {
|
|
735
|
+
"source_table": "orders",
|
|
736
|
+
"target_table": "orders_archive",
|
|
737
|
+
"filters": [
|
|
738
|
+
{ "field": "created_at", "operator": "lt", "value": "2023-01-01" }
|
|
739
|
+
]
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
**Pattern 2: Create Staging Table**
|
|
745
|
+
```json
|
|
746
|
+
// Clone structure for staging
|
|
747
|
+
{
|
|
748
|
+
"tool": "clone_table",
|
|
749
|
+
"arguments": {
|
|
750
|
+
"source_table": "products",
|
|
751
|
+
"new_table_name": "products_staging",
|
|
752
|
+
"include_data": false
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
**Pattern 3: Replicate Data Across Tables**
|
|
758
|
+
```json
|
|
759
|
+
// Keep replica in sync with master
|
|
760
|
+
{
|
|
761
|
+
"tool": "sync_table_data",
|
|
762
|
+
"arguments": {
|
|
763
|
+
"source_table": "users_master",
|
|
764
|
+
"target_table": "users_read_replica",
|
|
765
|
+
"key_column": "id",
|
|
766
|
+
"sync_mode": "upsert"
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
---
|
|
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
|
+
|
|
484
1248
|
## π° Transaction Management
|
|
485
1249
|
|
|
486
1250
|
The MySQL MCP Server provides full ACID transaction support, allowing you to group multiple database operations into atomic units.
|
|
@@ -2093,13 +2857,13 @@ MIT License - see [LICENSE](LICENSE) file for details.
|
|
|
2093
2857
|
- β
**Process Management** - Server processes, status, and query analysis - **COMPLETED!**
|
|
2094
2858
|
|
|
2095
2859
|
### Enterprise Features
|
|
2096
|
-
-
|
|
2097
|
-
-
|
|
2860
|
+
- β
**Database backup and restore tools** - **COMPLETED!**
|
|
2861
|
+
- β
**Data export/import utilities** (CSV, JSON, SQL dumps) - **COMPLETED!**
|
|
2862
|
+
- β
**Data migration utilities** - **COMPLETED!**
|
|
2863
|
+
- β
**Schema versioning and migrations** - **COMPLETED!**
|
|
2098
2864
|
- [ ] **Performance monitoring and metrics**
|
|
2099
2865
|
- [ ] **Connection pool monitoring**
|
|
2100
2866
|
- [ ] **Audit logging and compliance**
|
|
2101
|
-
- [ ] **Data migration utilities**
|
|
2102
|
-
- [ ] **Schema versioning and migrations**
|
|
2103
2867
|
|
|
2104
2868
|
### Database Adapters
|
|
2105
2869
|
- [ ] PostgreSQL adapter
|
|
@@ -2117,14 +2881,14 @@ MIT License - see [LICENSE](LICENSE) file for details.
|
|
|
2117
2881
|
- [ ] **Database health checks** - Comprehensive system health monitoring
|
|
2118
2882
|
|
|
2119
2883
|
#### **Phase 2: Data Management** π
|
|
2120
|
-
-
|
|
2121
|
-
-
|
|
2122
|
-
-
|
|
2884
|
+
- β
**Database backup and restore tools** - Essential for production data safety - **COMPLETED!**
|
|
2885
|
+
- β
**Data migration utilities** - Move data between databases and environments - **COMPLETED!**
|
|
2886
|
+
- β
**Enhanced export/import** - Support for JSON, SQL dump formats - **COMPLETED!**
|
|
2123
2887
|
- [ ] **Query history & analytics** - Track and analyze database usage patterns
|
|
2124
2888
|
|
|
2125
2889
|
#### **Phase 3: Enterprise Features** π’
|
|
2126
2890
|
- [ ] **Audit logging and compliance** - Track all database operations for security
|
|
2127
|
-
-
|
|
2891
|
+
- β
**Schema versioning and migrations** - Version control for database schema changes - **COMPLETED!**
|
|
2128
2892
|
- β
**Query optimization** - Automatic query analysis and optimization suggestions - **COMPLETED!**
|
|
2129
2893
|
- [ ] **Advanced security features** - Enhanced access control and monitoring
|
|
2130
2894
|
|
|
@@ -2149,11 +2913,11 @@ MIT License - see [LICENSE](LICENSE) file for details.
|
|
|
2149
2913
|
| Query Optimization | Medium | Medium | 9 | β
COMPLETED |
|
|
2150
2914
|
| Database Backup/Restore | High | High | 10 | β
COMPLETED |
|
|
2151
2915
|
| Data Export/Import (JSON, SQL) | High | Medium | 11 | β
COMPLETED |
|
|
2152
|
-
|
|
|
2153
|
-
|
|
|
2154
|
-
|
|
|
2155
|
-
|
|
|
2156
|
-
|
|
|
2916
|
+
| Data Migration | High | High | 12 | β
COMPLETED |
|
|
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 |
|
|
2157
2921
|
|
|
2158
2922
|
---
|
|
2159
2923
|
|