|
| 1 | +> **Note:** If you are starting the project from scratch (with a new, empty database), you do not need to run the migration scripts in this directory. These scripts are only necessary when migrating data from an existing database or upgrading shards. For new deployments, follow the standard database initialization procedures instead. |
| 2 | +
|
| 3 | +Database Migration Scripts |
| 4 | + |
| 5 | +This directory contains scripts for migrating database shards and related data. |
| 6 | + |
| 7 | +## Shard Migration Script |
| 8 | + |
| 9 | +The `shard_migration.sh` script is the main migration orchestrator that runs multiple migration scripts in parallel. |
| 10 | + |
| 11 | +### Usage |
| 12 | + |
| 13 | +The script accepts the following command-line arguments: |
| 14 | + |
| 15 | +- `--db_name`: Database name |
| 16 | +- `--db_user`: Database username |
| 17 | +- `--db_password`: Database password |
| 18 | +- `--host`: Database host |
| 19 | +- `--port`: Database port |
| 20 | + |
| 21 | +### Examples |
| 22 | + |
| 23 | +#### Basic Example: |
| 24 | +```bash |
| 25 | +./shard_migration.sh --db_name my_database --db_user postgres --db_password mypassword --host localhost --port 5432 |
| 26 | +``` |
| 27 | + |
| 28 | +#### Local PostgreSQL Database: |
| 29 | +```bash |
| 30 | +./shard_migration.sh \ |
| 31 | + --db_name read_rpc_db \ |
| 32 | + --db_user postgres \ |
| 33 | + --db_password secretpassword \ |
| 34 | + --host localhost \ |
| 35 | + --port 5432 |
| 36 | +``` |
| 37 | + |
| 38 | +#### Remote Database: |
| 39 | +```bash |
| 40 | +./shard_migration.sh \ |
| 41 | + --db_name production_db \ |
| 42 | + --db_user readrpc_user \ |
| 43 | + --db_password prod_password123 \ |
| 44 | + --host db.example.com \ |
| 45 | + --port 5432 |
| 46 | +``` |
| 47 | + |
| 48 | +#### Using Environment Variables: |
| 49 | +```bash |
| 50 | +# Set environment variables first |
| 51 | +export DB_NAME="my_database" |
| 52 | +export DB_USER="postgres" |
| 53 | +export PGPASSWORD="mypassword" |
| 54 | +export DB_HOST="localhost" |
| 55 | +export DB_PORT="5432" |
| 56 | + |
| 57 | +# Then run the script (it will use the environment variables) |
| 58 | +./shard_migration.sh |
| 59 | +``` |
| 60 | + |
| 61 | +### Prerequisites |
| 62 | + |
| 63 | +1. **Make the script executable:** |
| 64 | + ```bash |
| 65 | + chmod +x shard_migration.sh |
| 66 | + ``` |
| 67 | + |
| 68 | +2. **Make all migration scripts executable:** |
| 69 | + ```bash |
| 70 | + chmod +x migrate_*.sh |
| 71 | + ``` |
| 72 | + |
| 73 | +3. **Ensure all required migration scripts exist:** |
| 74 | + - `migrate_access_keys.sh` |
| 75 | + - `migrate_accounts.sh` |
| 76 | + - `migrate_contracts.sh` |
| 77 | + - `migrate_state_changes.sh` |
| 78 | + |
| 79 | +### How it Works |
| 80 | + |
| 81 | +The `shard_migration.sh` script: |
| 82 | + |
| 83 | +1. Parses command-line arguments and sets environment variables |
| 84 | +2. Creates a log file named `migration_${DB_NAME}.log` |
| 85 | +3. Runs four migration scripts in parallel using the `&` operator |
| 86 | +4. Waits for all migrations to complete using the `wait` command |
| 87 | +5. Logs start and completion times |
| 88 | + |
| 89 | +### Output |
| 90 | + |
| 91 | +- Migration progress and results are logged to `migration_${DB_NAME}.log` |
| 92 | +- Console output shows start and completion timestamps |
| 93 | +- Each individual migration script may produce its own output |
| 94 | + |
| 95 | +### Notes |
| 96 | + |
| 97 | +- All arguments are required for the script to function properly |
| 98 | +- The script runs migrations in parallel to improve performance |
| 99 | +- Make sure you have proper database permissions before running the migration |
| 100 | +- Review the individual migration scripts to understand what data will be migrated |
0 commit comments