abstract class
CQL::Migration(V)
- CQL::Migration(V)
- CQL::BaseMigration
- Reference
- Object
Overview
Migrations are used to manage changes to the database schema over time.
Each migration is a subclass of Migration(V), where V is its version, and implements up and down.
The up method applies the migration, while the down method rolls it back.
Migrations run in version order. Defining the class registers it with Migrator, which applies,
rolls back and redoes migrations and lists the applied and pending ones.
Example Creating a new migration
class AddPhoneToUsers < CQL::Migration(1)
def up
schema.alter :users do
add_column :phone, String, null: true
end
end
def down
schema.alter :users do
drop_column :phone
end
end
end
Example Applying and rolling back migrations
migrator = CQL::Migrator.new(schema)
migrator.up
migrator.rollback
Defined in:
migrations.crConstructors
-
.new(schema : CQL::Schema)
Migratorcalls.new(schema)on every registered class, which must resolve even when no migration class exists.
Instance methods inherited from class CQL::BaseMigration
down
down,
schema : CQL::Schema
schema,
up
up
Constructor methods inherited from class CQL::BaseMigration
new(schema : CQL::Schema)
new
Class methods inherited from class CQL::BaseMigration
version : Int64
version
Constructor Detail
def self.new(schema : CQL::Schema)
#
Migrator calls .new(schema) on every registered class, which must resolve even when no
migration class exists.