Migrator Config Example

A detailed demonstration of CQL's advanced migrator configuration system, showing how to customize migration behavior, create environment-specific configurations, and integrate with complex migration workflows.

🎯 What You'll Learn

This example teaches you how to:

  • Create custom migrator configurations with specific settings

  • Override default configuration for specialized use cases

  • Generate environment-specific migrator configurations

  • Integrate migrator configs with schema definitions

  • Use configuration helpers for migrator setup

  • Manage multiple migration workflows in complex applications

  • Customize schema file generation and synchronization

  • Implement advanced migration patterns for production use

🚀 Quick Start

# Run the migrator configuration example
crystal examples/migrator_config_example.cr

📁 Code Structure

🔧 Key Features

1. Basic MigratorConfig Creation

2. Custom MigratorConfig Overrides

3. Environment-Specific MigratorConfig

🏗️ Migrator Configuration Architecture

📊 MigratorConfig Examples

Using MigratorConfig with Schema

ConfigHelpers for MigratorConfig

Complete Workflow with MigratorConfig

🔧 MigratorConfig Options

Core Configuration Options

Option
Type
Default
Description

schema_file_path

String

Auto-generated

Path to schema file

schema_name

Symbol

Auto-generated

Schema constant name

schema_symbol

Symbol

Auto-generated

Schema symbol for internal use

auto_sync

Bool

true

Auto schema synchronization

migration_table_name

Symbol

:cql_schema_migrations

Migration tracking table

Environment-Specific Defaults

Environment
Schema File
Schema Name
Auto Sync
Migration Table

Development

app_schema.cr

AppSchema

true

cql_schema_migrations

Test

test_schema.cr

TestSchema

true

test_schema_migrations

Production

production_schema.cr

ProductionSchema

false

cql_schema_migrations

🎯 Advanced Configuration Patterns

Multi-Environment Configuration

Custom Schema Naming

Workflow-Specific Configurations

🔧 Configuration Helpers

Available Helper Methods

Helper Integration Examples

🎯 Use Cases

Microservices Architecture

Multi-Tenant Applications

Feature Branch Development

📊 Configuration Comparison

Default vs Custom Configurations

Environment Comparison

🎯 Best Practices

1. Environment-Specific Configuration

2. Schema File Organization

3. Configuration Validation

📚 Next Steps

Advanced Topics

Production Considerations

  • Environment Isolation - Separate configurations for different environments

  • Schema File Management - Organize schema files by environment or service

  • Configuration Validation - Validate migrator configurations before use

  • Team Coordination - Coordinate configuration changes across team

  • CI/CD Integration - Use appropriate configurations in automated workflows

🔧 Troubleshooting

Common Issues

  1. Schema file path issues - Ensure directory exists and is writable

  2. Environment detection problems - Check CRYSTAL_ENV environment variable

  3. Configuration conflicts - Avoid conflicting schema names across environments

  4. Auto sync issues - Verify auto_sync setting matches environment needs

Debug Configuration


🏁 Summary

This migrator configuration example demonstrates:

  • Advanced migrator configuration with custom settings and overrides

  • Environment-specific configurations for different deployment stages

  • Configuration helpers for common migrator setup patterns

  • Multi-environment support with automatic defaults

  • Custom schema naming for complex applications

  • Workflow-specific configurations for specialized use cases

  • Production-ready patterns for enterprise applications

Ready to implement advanced migrator configurations in your CQL application? Start with basic configurations and gradually add customizations as needed! 🚀

Last updated

Was this helpful?