module Clear::Migration::Helper
Included Modules
Direct including types
Defined in:
clear/extensions/enum/migration.crclear/extensions/full_text_searchable/full_text_searchable.cr
clear/migration/migration.cr
clear/migration/operation/columns.cr
clear/migration/operation/indexes.cr
clear/migration/operation/table.cr
Constant Summary
-
TYPE_MAPPING =
{"string" => "text", "int32" => "int", "int64" => "bigint", "long" => "bigint", "bigdecimal" => "numeric", "datetime" => "timestamp without time zone"}
Class Method Summary
-
.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 Method Summary
-
#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)
-
#apply(dir : Direction = Clear::Migration::Direction::Up)
This will apply the migration in a given direction (up or down)
- #change(dir)
- #change_column_type(table, column, from, to)
- #create_enum(name, arr : Enumerable(T)) forall T
- #create_enum(name, e)
- #create_index(table, columns : Array(String), name = nil, using = nil, unique = false)
-
#create_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.
- #drop_column(table, column, type)
- #drop_enum(name, arr : Enumerable(T) | Nil = nil) forall T
- #execute(sql : String)
- #irreversible!
- #rename_column(table, from, to)
Instance methods inherited from module Clear::Migration::FullTextSearchableHelpers
add_full_text_searchable(table, on : Array(Tuple(String, Char)), column_name = "full_text_vector", catalog = "pg_catalog.english", trigger_name = nil, function_name = nil)
add_full_text_searchable
Class Method Detail
def self.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 Method Detail
def add_column(table, column, datatype, nullable = false, constraint = nil, default = nil, with_values = false)
#
Add a column to a specific table
This will apply the migration in a given direction (up or down)
Add a column to a specific table
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