-
-
Notifications
You must be signed in to change notification settings - Fork 94
Description
Describe the feature
Add a migration file generation tool to GORM that can automatically create SQL migration files (.up.sql / .down.sql) by diffing the current database schema with the schema defined in GORM models.
The tool would:
• Parse struct definitions and tags to determine the “desired schema”
• Inspect the connected database to read the “current schema”
• Generate migration files containing the SQL statements to transition from current → desired schema (and optionally reverse for rollbacks)
• Support multiple dialects (MySQL, Postgres, SQLite, SQL Server) using GORM’s existing migrator infrastructure
• Provide safe mode, dry-run, and optional destructive change detection
Motivation
GORM currently provides AutoMigrate for applying schema changes, but:
• It applies changes directly to the database without producing migration scripts
• This makes schema changes non-reviewable and non-reproducible across environments
• Teams that follow GitOps or CI/CD best practices need migrations stored in source control
• Other ecosystems (Rails, Django, Laravel, Ent) have built-in migration generators, but the Go ecosystem lacks a standard solution for GORM
• A built-in tool would:
• Prevent manual SQL writing for common changes
• Increase collaboration by letting teams review migration files before execution
• Make database state reproducible across dev, staging, and prod
• Reduce risk of drift between environments