Schema Synchronization
ModelsHandler keeps your database schema in sync with your Go model definitions.
When schema synchronization is enabled, the system compares your model definitions against the existing database structure and applies necessary changes.
This allows you to evolve your database schema alongside your code without maintaining manual migration scripts during development.
Auto Migration
Auto migration is an opt-in process that updates the database schema based on your model definitions.
When enabled, ModelsHandler can:
- Create tables that do not exist
- Add new columns defined in models
- Update column types and constraints
- Synchronize indexes and keys
Auto migration runs only when explicitly requested and is never performed silently in production.
Migration Flags
Schema synchronization is triggered using a command-line flag when running your application.
--migrate-model
Runs schema synchronization for all defined models.
go run . --migrate-model
-mm
Shorthand alias for --migrate-model.
go run . -mm
Without these flags, no schema changes are applied.
Environment Guidelines
Auto migration is intended primarily for development and controlled environments.
- Development: Use migration flags to evolve schema rapidly while iterating on models.
- Staging: Review schema changes before applying them.
- Production: Disable auto migration and apply changes deliberately.
Always review schema changes before applying them to production databases.