docs/references/gofrcli/migrate/page.md
The migrate create command generates a migration template file with pre-defined structure in your migrations directory. This boilerplate code helps you maintain consistent patterns when writing database schema modifications across your project.
gofr migrate create -name=<migration-name>
gofr migrate create -name=create_employee_table
This command generates a migration directory which has the below files:
20250127152047_create_employee_table.go) containing:package migrations
import (
"gofr.dev/pkg/gofr/migration"
)
func create_employee_table() migration.Migrate {
return migration.Migrate{
UP: func(d migration.Datasource) error {
// write your migrations here
return nil
},
}
}
// This is auto-generated file using 'gofr migrate' tool. DO NOT EDIT.
package migrations
import (
"gofr.dev/pkg/gofr/migration"
)
func All() map[int64]migration.Migrate {
return map[int64]migration.Migrate {
20250127152047: create_employee_table(),
}
}
💡 Best Practice: Learn about organizing migrations by feature to avoid creating one migration per table or operation.
For detailed instructions on handling database migrations, see the handling-data-migrations documentation For more examples, see the using-migrations