Transfer feature flag configurations between different FlagFlow environments
FlagFlow's migration system enables you to transfer feature flag configurations between different environments, such as promoting flags from development to staging or from staging to production. The system intelligently compares flag configurations and generates specific migration steps to synchronize environments safely.
Smart Migration: The system analyzes differences between source and target environments and generates only the necessary steps to bring them into sync, preserving existing configurations where appropriate.
Upload an export file from another environment
Direct connection to another FlagFlow instance
FlagFlow analyzes the differences between source and target environments and generates specific migration steps:
| Step Type | Purpose | When Generated |
|---|---|---|
| CREATE_DEFAULTVALUE | Create new flag with default value | Flag exists in source but not target |
| UPDATE_SCHEMA_DEFAULTVALUE | Update flag schema, reset to default | Flag type or schema changed |
| SET_VALUE | Set specific value for existing flag | Flag value differs between environments |
| DELETE | Remove flag that doesn't exist in source | Flag exists in target but not source |
First, create an export from your source environment (e.g., development or staging):
# Export from source environment curl -O http://staging.flagflow.com/migration/export # This creates a file like: # flagflow_migration_staging_20240810-143025.json
In your target environment's FlagFlow interface:
The migration executor will show you all the changes that will be made:
Default Behavior: Migrations exclude SET_VALUE steps by default, meaning only schemas are migrated. You can optionally include value migrations using the "Add value steps" button.
To enable remote migration, configure the source environment URL in your target environment:
# Environment variables for target environment MIGRATION_SOURCE_URL=http://staging.flagflow.com MIGRATION_SOURCE_ENVIRONMENT=staging # Other standard configuration ENVIRONMENT=production LOGLEVEL=info
When properly configured, remote migration provides a streamlined experience:
Real-time Sync: Remote migration always fetches the latest configuration from the source, ensuring you're migrating the most current flag states.
FlagFlow performs comprehensive validation before allowing migration:
Some migration steps depend on others and are automatically ordered:
Example migration with dependencies:
1. DELETE old_feature_flag
└── 2. CREATE_DEFAULTVALUE new_feature_flag (depends on #1)
└── 3. SET_VALUE new_feature_flag = true (depends on #2)
4. UPDATE_SCHEMA_DEFAULTVALUE max_connections
└── 5. SET_VALUE max_connections = 100 (depends on #4)Important: FlagFlow migrations are not automatically reversible. Always create a backup of your target environment before performing migrations, especially in production.
The default migration approach transfers only flag schemas and structures, not values:
Use the "Add value steps" option to include value migrations:
Choose which migration steps to execute:
# Scenario: Promote new feature flags to staging # Steps typically generated: 1. CREATE_DEFAULTVALUE new_feature_toggle (BOOLEAN) 2. CREATE_DEFAULTVALUE feature_rollout_percent (INTEGER) 3. CREATE_DEFAULTVALUE supported_regions (TAG) # Values are NOT migrated by default # Staging team can set appropriate values for their environment
# Scenario: Promote tested features to production # More careful approach with schema-only migration 1. UPDATE_SCHEMA_DEFAULTVALUE existing_feature (new enum values) 2. CREATE_DEFAULTVALUE production_ready_feature (BOOLEAN) 3. DELETE experimental_flag (removed in staging) # Production values remain unchanged # Operations team sets production-appropriate values
# Scenario: Emergency flag changes across environments # Include values for immediate effect 1. CREATE_DEFAULTVALUE emergency_circuit_breaker (BOOLEAN) 2. SET_VALUE emergency_circuit_breaker = true # Execute immediately with values to enable circuit breaker
#!/bin/bash
# automated-migration.sh
# Automate flag migrations in CI/CD pipelines
SOURCE_ENV="staging"
TARGET_ENV="production"
BACKUP_DIR="/tmp/flagflow-backups"
echo "🚀 Starting automated migration: $SOURCE_ENV → $TARGET_ENV"
# Step 1: Create backup of target environment
echo "📦 Creating backup of $TARGET_ENV..."
mkdir -p "$BACKUP_DIR"
BACKUP_FILE="$BACKUP_DIR/pre-migration-backup-$(date +%Y%m%d-%H%M%S).json"
curl -s "http://$TARGET_ENV.flagflow.com/migration/export" -o "$BACKUP_FILE"
if [ ! -f "$BACKUP_FILE" ]; then
echo "❌ Failed to create backup"
exit 1
fi
echo "✅ Backup created: $BACKUP_FILE"
# Step 2: Fetch source configuration
echo "📥 Fetching source configuration from $SOURCE_ENV..."
SOURCE_FILE="$BACKUP_DIR/source-config-$(date +%Y%m%d-%H%M%S).json"
curl -s "http://$SOURCE_ENV.flagflow.com/migration/export" -o "$SOURCE_FILE"
if [ ! -f "$SOURCE_FILE" ]; then
echo "❌ Failed to fetch source configuration"
exit 1
fi
echo "✅ Source configuration fetched: $SOURCE_FILE"
# Step 3: Validate files
echo "🔍 Validating configuration files..."
jq empty "$BACKUP_FILE" && jq empty "$SOURCE_FILE"
if [ $? -ne 0 ]; then
echo "❌ Invalid JSON in configuration files"
exit 1
fi
echo "✅ Configuration files validated"
echo "🎯 Migration ready. Upload $SOURCE_FILE to $TARGET_ENV manually or via API"
echo "🔄 Backup available at: $BACKUP_FILE"# GitHub Actions example
name: Deploy Feature Flags
on:
push:
branches: [main]
jobs:
migrate-flags:
runs-on: ubuntu-latest
steps:
- name: Backup Production Flags
run: |
curl -o prod-backup-$(date +%Y%m%d).json \
{{ secrets.PROD_FLAGFLOW_URL }}/migration/export
- name: Export Staging Flags
run: |
curl -o staging-export.json \
{{ secrets.STAGING_FLAGFLOW_URL }}/migration/export
- name: Upload Migration Artifacts
uses: actions/upload-artifact@v2
with:
name: migration-files
path: |
prod-backup-*.json
staging-export.json
# Manual approval step before production migration
- name: Wait for Approval
uses: trstringer/manual-approval@v1
with:
secret: {{ github.TOKEN }}
approvers: production-team
# Note: Actual migration execution should be done manually
# or through a separate secure processAfter completing a migration, consider these follow-up actions:
For restoring from backups within the same environment, see the Restore documentation. For creating backups, see the Export and Backup documentation.