Migration Configuration Example
A comprehensive demonstration of CQL's integrated migration system with automatic schema synchronization, showing how to maintain up-to-date schema files through version-controlled migrations.
π― What You'll Learn
This example teaches you how to:
Integrate configuration with migration workflows
Create automatic schema synchronization between migrations and schema files
Manage environment-specific migration configurations
Define and execute migrations with automatic schema updates
Verify schema consistency between database and schema files
Handle migration rollbacks with schema synchronization
Use generated schema files in Active Record models
Implement team collaboration patterns for schema management
π Quick Start
# Run the migration configuration example
crystal examples/configure_migration_example.crπ Code Structure
π§ Key Features
1. Basic Migration Configuration
2. Schema Creation with Configuration
3. Migration Definition
ποΈ Migration Workflow Architecture
π Migration Examples
Complete Migration Workflow
Environment-Specific Migration Configurations
π§ Migration Configuration Options
Core Migration Settings
migration_table_name
Symbol
:cql_schema_migrations
Migration tracking table
schema_path
String
"src/schemas"
Path where schema files are stored
schema_file_name
String
"app_schema.cr"
Default schema file name
schema_constant_name
Symbol
:AppSchema
Schema constant name
enable_auto_schema_sync
Bool
true
Auto schema synchronization
verify_schema_on_startup
Bool
false
Verify schema on startup
Environment-Specific Defaults
Development
true
app_schema.cr
true
false
Test
true
test_schema.cr
false
false
Production
false
production_schema.cr
true
false
π― Migration Workflow Patterns
Basic Migration Workflow
Migration Rollback with Schema Sync
Schema Verification
π§ Configuration Helpers
Using Configuration Helpers
Environment-Specific Helpers
π― Team Workflow Scenarios
New Team Member Setup
Resolving Schema Conflicts
Production Deployment
π Generated Schema Files
Schema File Structure
Using Generated Schema in Models
π§ Advanced Migration Patterns
Complex Migration with Foreign Keys
Adding Columns to Existing Tables
Index Management
π― Best Practices
1. Environment-Specific Configuration
2. Migration Naming Conventions
3. Schema File Management
π Next Steps
Related Examples
Schema Migration Workflow - Detailed migration workflow
PostgreSQL Migration Workflow - PostgreSQL-specific patterns
Blog Engine - See migrations in a complete application
Advanced Topics
Migration Guide - Complete migration documentation
Integrated Migration Workflow - Advanced workflow patterns
Schema Management - Schema definition and management
Production Considerations
Migration Safety - Always test migrations in staging
Schema Consistency - Verify schema files match database
Rollback Strategy - Ensure migrations can be safely rolled back
Team Coordination - Coordinate schema changes across team
CI/CD Integration - Automate migration and schema verification
π§ Troubleshooting
Common Issues
Schema file not generated - Check
enable_auto_schema_syncsettingMigration conflicts - Ensure migration versions are sequential
Schema inconsistency - Run
CQL.verify_schema(AppDB)to checkRollback issues - Ensure all migrations have proper
downmethods
Debug Migration Issues
π Summary
This migration configuration example demonstrates:
β Integrated migration workflow with automatic schema synchronization
β Environment-specific configurations for different deployment stages
β Automatic schema file generation from database migrations
β Schema consistency verification between database and files
β Team collaboration patterns for schema management
β Production-ready deployment with proper migration handling
β Configuration helpers for common migration operations
Ready to implement migration workflows in your CQL application? Start with basic migrations and gradually add advanced features like schema synchronization! π
Last updated
Was this helpful?