Feat: migrate script (#14076)

### What problem does this PR solve?

Add command line arguments for mysql config.

### Type of change

- [x] Other (please describe): tool scripts.
This commit is contained in:
Lynn
2026-04-13 20:45:11 +08:00
committed by GitHub
parent 853021ff2a
commit 47d3741dcc
2 changed files with 61 additions and 12 deletions

View File

@@ -72,13 +72,20 @@ tenant_model (depends on tenant_model_provider and tenant_model_instance)
python mysql_migration.py [OPTIONS]
```
| Option | Short | Description |
|--------|-------|-------------|
| `--config` | `-c` | Path to YAML config file (required) |
| `--stages` | `-s` | Comma-separated list of stages to run |
| `--list-stages` | `-l` | List available stages and exit |
| `--execute` | `-e` | Execute full migration (create tables and migrate data) |
| `--create-table-only` | - | Only create target tables, skip data migration |
| Option | Short | Description | Default |
|--------|-------|-------------|---------|
| `--host` | - | MySQL host | `localhost` |
| `--port` | - | MySQL port | `3306` |
| `--user` | - | MySQL user | `root` |
| `--password` | - | MySQL password | (empty) |
| `--database` | - | MySQL database name | `rag_flow` |
| `--config` | `-c` | Path to YAML config file | - |
| `--stages` | `-s` | Comma-separated list of stages to run | - |
| `--list-stages` | `-l` | List available stages and exit | - |
| `--execute` | `-e` | Execute full migration (create tables and migrate data) | `False` |
| `--create-table-only` | - | Only create target tables, skip data migration | `False` |
> **Note**: MySQL connection can be configured via command line arguments (`--host`, `--port`, `--user`, `--password`, `--database`) or via a YAML config file (`--config`). Command line arguments take precedence over config file values.
### Execution Modes
@@ -86,7 +93,11 @@ The script has three mutually exclusive modes:
1. **Dry-Run Mode** (default): Check only, no database writes
```bash
# Using config file
python mysql_migration.py --stages tenant_model_provider --config config.yaml
# Using command line MySQL connection
python mysql_migration.py --stages tenant_model_provider --host localhost --port 3306 --user root
```
2. **Create Table Only Mode**: Create target tables without migrating data
@@ -129,7 +140,10 @@ mysql:
# List all available stages
python mysql_migration.py --list-stages
# Dry run single stage
# Dry run single stage using command line MySQL connection
python mysql_migration.py --stages tenant_model_provider --host localhost --port 3306 --user root --password secret
# Dry run single stage using config file
python mysql_migration.py --stages tenant_model_provider --config /path/to/config.yaml
# Create tables only for multiple stages
@@ -137,6 +151,9 @@ python mysql_migration.py --stages tenant_model_provider,tenant_model_instance -
# Execute full migration for all stages (in dependency order)
python mysql_migration.py --stages tenant_model_provider,tenant_model_instance,tenant_model --config /path/to/config.yaml --execute
# Use config file with command line password override
python mysql_migration.py --stages tenant_model_provider --config /path/to/config.yaml --password mypassword --execute
```
## Output Interpretation

View File

@@ -795,9 +795,12 @@ Examples:
# List available stages
python mysql_migration.py --list-stages
# Dry run (default - check only, no write)
# Dry run (default - check only, no write) with config file
python mysql_migration.py --stages tenant_model_provider --config /path/to/config.yaml
# Dry run with command line MySQL connection
python mysql_migration.py --stages tenant_model_provider --host localhost --port 3306 --user root --password secret
# Create target tables only (no data migration)
python mysql_migration.py --stages tenant_model_provider --config /path/to/config.yaml --create-table-only
@@ -809,6 +812,18 @@ Examples:
"""
)
# MySQL connection options
parser.add_argument('--host', type=str, default='localhost',
help='MySQL host (default: localhost)')
parser.add_argument('--port', type=int, default=3306,
help='MySQL port (default: 3306)')
parser.add_argument('--user', type=str, default='root',
help='MySQL user (default: root)')
parser.add_argument('--password', type=str, default='',
help='MySQL password (default: empty)')
parser.add_argument('--database', type=str, default='rag_flow',
help='MySQL database name (default: rag_flow)')
# Configuration options
parser.add_argument('--config', '-c', type=str, help='Path to YAML config file')
@@ -834,12 +849,29 @@ Examples:
stages = [s.strip() for s in args.stages.split(',')]
# Load configuration
# Load configuration: command line args take precedence over config file
if args.config:
config = MigrationConfig.from_config_file(args.config)
# Override with command line args if provided
if args.host != 'localhost':
config.host = args.host
if args.port != 3306:
config.port = args.port
if args.user != 'root':
config.user = args.user
if args.password != '':
config.password = args.password
if args.database != 'rag_flow':
config.database = args.database
else:
logging.error("No config file specified. Use --config to specify config file.")
sys.exit(1)
# Use command line args directly
config = MigrationConfig(
host=args.host,
port=args.port,
user=args.user,
password=args.password,
database=args.database
)
logger.info(f"MySQL Configuration: host={config.host}, port={config.port}, "
f"user={config.user}, database={config.database}")