| outline | deep |
|---|
morm supports schema-driven migration through generated Table metadata plus an engine migration hook.
@morm.auto_migrate(engine, [
Class::table(),
Student::table(),
Teacher::table(),
])This is the public API entry point for schema synchronization.
auto_migrate is intentionally thin.
It:
- receives an engine
- receives an array of
Table - serializes each table as JSON
- calls the engine migration method
It does not implement a universal SQL diff algorithm in the ORM layer.
DDL behavior varies substantially across databases:
- column type syntax
- default handling
- index changes
- foreign key syntax
- table alter capabilities
Because of that, morm keeps migration decisions engine-specific.
auto_migrate is a good fit for:
- local development setup
- test database bootstrapping
- straightforward schema alignment
For more complex production changes, explicit migration scripts are still the safer option.
Migration depends entirely on generated metadata from Type::table().
That means when entity definitions change:
- regenerate the
.g.mbtfile - rebuild
- run migration
If you forget regeneration, migration will use stale schema metadata.
Even if you do not run real migrations in unit tests, you can still assert on generated schema shape:
let table = Class::table()
assert_eq(table.columns[3].name, "created_at")
assert_eq(table.columns[3].column_type, DateTime)This is often enough to catch unintended schema changes before runtime.