class MyMigration1
include Clear::Migration
def change(direction)
direction.up do
execute("CREATE TABLE my_models...")
end
direction.down do
execute("DROP TABLE my_models")
end
end
end
create_table(:users) do |t|
t.column :first_name, :string, index: true
t.column :last_name, :string, unique: true
# Will create a "user_info_id" field of type longint with a foreign key constraint
# This reference can be null, and if the user_info is deleted then the user is deleted too.
t.references to: "user_infos", name: "user_info_id", on_delete: "cascade", null: true
# Example of creating index on full name
t.index "lower(first_name || ' ' || last_name)", using: :btree
t.timestamps
end
class Migration1
include Clear::Migration
def change(dir)
#...
end
end
1234_migration.cr
class Migration1
include Clear::Migration
def uid
123_i64 #Number must be a signed 64bits integer !
end
def change(dir)
#...
end
end
# Activate all the migrations. Will call change with up direction for each down migrations
Clear::Migration::Manager.instance.apply_all
# Go to a specific migration. All migration with a number above than the version number will be downed if not yet down.
# All migrations with a version number below will be activated if not yet up.
Clear::Migration::Manager.instance.apply_to(version_number)