Reference
< Object
Migrations are used to manage changes to the database schema over time. Each migration is a subclass of Migration
and must implement the up
and down
methods.
The up
method is used to apply the migration, while the down
method is used to rollback the migration. Migrations are executed in their version order defined. The Migrator
class is used to manage migrations and provides methods to apply, rollback, and redo migrations. The Migrator
class also provides methods to list applied and pending migrations.
Example Creating a new migration
Example Applying migrations
Example Rolling back migrations
Example Redoing migrations
Example Rolling back to a specific version
Example Applying to a specific version
Example Listing applied migrations
Example Listing pending migrations
Example Listing rolled back migrations
Example Listing the last migration
(schema : Schema)
DB::Mappable
< DB::Serializable
< Reference
< Object
Represents a migration record. @field id [Int64] the migration record id @field name [String] the migration name @field version [Int64] the migration version @field created_at [Time] the creation time @field updated_at [Time] the update time Example Creating a migration record
DB::Mappable
, DB::Serializable
(id : Int64, name : String, version : Int64, created_at : Time = Time.local, updated_at : Time = Time.local)
(rs : DB::ResultSet)
(rs : DB::ResultSet)
Reference
< Object
The Migrator
class is used to manage migrations and provides methods to apply, rollback, and redo migrations. The Migrator
class also provides methods to list applied and pending migrations. Example Creating a new migrator
Example Applying migrations
(schema : Schema)
(migrations : Array(Migration.class))
Returns the applied migrations.
@return [Array(MigrationRecord)] Example Listing applied migrations
(steps : Int32 = Migrator.migrations.size)
Rolls back the last migration.
@param steps [Int32] the number of migrations to roll back (default: 1) Example Rolling back migrations
(version : Int64)
Rolls back to a specific migration version.
@param version [Int64] the version to roll back to Example Rolling back to a specific version
Returns the last migration. Example Listing the last migration
@return [Migration.class | Nil]
Returns the pending migrations.
@return [Array(MigrationRecord)] Example Listing pending migrations
Prints the applied migrations. Example Listing applied migrations
Prints the pending migrations. Example Listing pending migrations
(m : Array(Migration.class))
Prints the rolled back migrations.
@param m [Array(Migration.class)] the migrations to print
@return [Nil] Example Listing rolled back migrations
Redoes the last migration. Example Redoing migrations
(steps : Int32 = 1)
Rolls back the last migration.
@param steps [Int32] the number of migrations to roll back (default: 1) Example Rolling back migrations
(steps : Int32 = Migrator.migrations.size)
Applies the pending migrations.
@param steps [Int32] the number of migrations to apply (default: all) Example Applying migrations
(version : Int64)
Applies migrations up to a specific version.
@param version [Int64] the version to apply up to Example Applying to a specific version