Clear::Migration::Helper
Constants
TYPE_MAPPING = {"string" => "text", "int32" => "int", "int64" => "bigint", "long" => "bigint", "bigdecimal" => "numeric", "datetime" => "timestamp without time zone"}
Class methods
datatype(type : String)
Replace some common type to their equivalent in postgresql if the type is not found in the correspondance table, then return itself
Instance methods
add_column(table, column, datatype, nullable = false, constraint = nil, default = nil, with_values = false)
Add a column to a specific table
add_operation(op : Operation)
Sourceapply(dir : Direction = Clear::Migration::Direction::Up)
This will apply the migration in a given direction (up or down)
change(dir)
Sourcechange_column_type(table, column, to, from = nil)
Sourcechange_type_column(table, from, to)
Sourcecreate_index(table, column, name = nil, using = nil, unique = false)
Add a column to a specific table
create_table(name, id : Symbol | Bool = true, schema = "public", &)
Helper used in migration to create a new table.
Usage:
create_table(:users) do |t|
t.column :first_name, :string
t.column :last_name, :string
t.column :email, :string, unique: true
t.timestamps
end
By default, a column id of type integer will be created as primary key of the table.
This can be prevented using primary: false
create_table(:users, id: false) do |t|
t.column :user_id, :integer, primary: true # Use custom name for the primary key
t.column :first_name, :string
t.column :last_name, :string
t.column :email, :string, unique: true
t.timestamps
end
drop_column(table, column, type)
Sourceexecute(sql : String)
Sourceirreversible!
Sourcerename_column(table, from, to)
Source