Call migration script
Call migration script
Clear offers a migration system. Migration allow you to handle state update of your database.
Migration is a list of change going through a direction, up (commit changes) or down (rollback changes).
In clear, a migration is defined like this:
class MyMigration1
include Clear::Migration
def change(direction)
direction.up do
#do something on commit
end
direction.down do
#do something on rollback
end
end
endExecuting custom SQL
The basic usage is to execute your own SQL (e.g. CREATE TABLE, ALTER, GRANT etc...).
To do it, just call execute into your direction block.
Example
Built-in helpers
Clear offers helpers for simplify declaring your migration
Creating a table
Clear provides DSL looking like ActiveRecord for creating a table.
Migration ordering
Migration should be ordered by a number. This number can be written in different way:
In case of mixing multiple classes into the same file, you can append the number at the end of the class name:
If you're using one file per migration, you can prepend the ordering number at the start of the file name:
Finally, if you feel more rock'n'roll and build a complex dynamic migration system on top of Clear, you can override the uid method:
Calling your migration
Clear will offers soon a CLI; meanwhile, you can call migration update using methods in the Migration Manager:
Last updated