# Mirror Production Data > **Note:** These tools were created by Claude Code as a simple way to kick the tires on data migrations. > They are not intended for production use. Tools to fetch and load production registry data for local testing and migration debugging. ## Overview These scripts help you: 1. Fetch all server data from the production registry API 2. Load it into a local PostgreSQL database 3. Test migrations against real production data ## Prerequisites - Go — see the [prerequisites in the root README](../../README.md#pre-requisites) for the required version - PostgreSQL (via Docker or local installation) - Required Go packages: ```bash go get github.com/google/uuid github.com/lib/pq ``` ## Usage ### 1. Fetch Production Data ```bash # From the project root directory go run scripts/mirror_data/fetch_production_data.go ``` This will: - Fetch all servers from https://registry.modelcontextprotocol.io/v0/servers - Handle pagination automatically - Save data to `scripts/mirror_data/production_servers.json` - Be respectful to the API with rate limiting Output: `production_servers.json` containing all server records ### 2. Set Up Test Database Start a PostgreSQL container for testing: ```bash docker run -d --name test-postgres \ -p 5433:5432 \ -e POSTGRES_PASSWORD=testpass \ -e POSTGRES_DB=registry_test \ postgres:16 ``` Or reset an existing database: ```bash docker exec test-postgres psql -U postgres postgres -c "DROP DATABASE IF EXISTS registry_test;" docker exec test-postgres psql -U postgres postgres -c "CREATE DATABASE registry_test;" ``` ### 3. Load Production Data ```bash # From the project root directory go run scripts/mirror_data/load_production_data.go ``` This will: 1. Connect to PostgreSQL at `localhost:5433` 2. Apply migrations up to a configurable point (default: migration 007) 3. Load all production server data 4. Analyze the data and report statistics 5. Show sample servers with NULL status values To test a different migration, edit `maxMigration` in `load_production_data.go` ### 4. Test Migrations After loading the data, you can test migrations against real production data. #### Testing a Single Migration ```bash # Test the separate_official_metadata migration cat internal/database/migrations/009_separate_official_metadata.sql | \ docker exec -i test-postgres psql -U postgres -d registry_test ``` #### Debugging Failed Migrations 1. **Check the error output:** ```bash # Run migration and capture all output cat internal/database/migrations/009_separate_official_metadata.sql | \ docker exec -i test-postgres psql -U postgres -d registry_test 2>&1 | \ grep -E "(ERROR|NOTICE|WARNING)" ``` 2. **Inspect data before migration:** ```bash # Check for NULL values that might cause issues docker exec test-postgres psql -U postgres -d registry_test -c \ "SELECT COUNT(*) FROM servers WHERE value->>'status' IS NULL;" # Find sample problematic records docker exec test-postgres psql -U postgres -d registry_test -c \ "SELECT value->>'name', value->>'version' FROM servers \ WHERE value->>'status' IS NULL LIMIT 5;" ``` 3. **Test partial migrations:** ```bash # Extract and run only part of a migration to isolate issues # For example, run only up to the NOT NULL constraint: docker exec test-postgres psql -U postgres -d registry_test <