class Avram::Migrator::AlterTableStatement
Included Modules
Defined in:
avram/migrator/alter_table_statement.crConstructors
Instance Method Summary
- #add_change_default_statement(column : Avram::Migrator::Columns::Base)
- #add_change_type_statement(column : Avram::Migrator::Columns::Base)
- #add_fill_existing_with_statements(column : Symbol | String, type, value, nilable)
- #alter_statements : Array(String)
-
#build(&)
Accepts a block to alter a table using the
add
method. - #change_default_statements : Array(String)
- #change_type_statements : Array(String)
- #dropped_rows : Array(String)
- #fill_existing_with_statements : Array(String)
- #renamed_rows : Array(String)
- #rows : Array(String)
- #statements
Macro Summary
- add(type_declaration, index = false, using = :btree, unique = false, default = nil, fill_existing_with = nil, **type_options)
-
add_belongs_to(type_declaration, on_delete, references = nil, foreign_key_type = Int64, fill_existing_with = nil, unique = false)
Adds a references column and index given a model class and references option.
-
change_default(type_declaration, default)
Change the columns' default value to
default
alter table_for(Post) do change_default published_at, default: :now end
-
change_type(type_declaration, **type_options)
Change the column's type from whatever it is currently to
type_declaration.type
. - remove(name)
- remove_belongs_to(association_name)
- rename(old_name, new_name)
- rename_belongs_to(old_association_name, new_association_name)
- symbol_expected_error(action, name)
Instance methods inherited from module Avram::Migrator::IndexStatementHelpers
add_index(column : Symbol, unique = false, using : Symbol = :btree)
add_index,
index_added?(index : String, column : Symbol)
index_added?
Instance methods inherited from class Object
blank_for_validates_required? : Bool
blank_for_validates_required?
Constructor Detail
Instance Method Detail
Accepts a block to alter a table using the add
method. The generated sql
statements are aggregated in the #statements
getter.
Usage
built = Avram::Migrator::AlterTableStatement.new(:users).build do
add name : String
add age : Int32
remove old_field
end
built.statements
# => [
"ALTER TABLE users
ADD name text NOT NULL,
ADD age int NOT NULL,
DROP old_field"
]
Macro Detail
Adds a references column and index given a model class and references option.
Change the columns' default value to default
alter table_for(Post) do
change_default published_at, default: :now
end
Change the column's type from whatever it is currently to
type_declaration.type
. The only exceptions are when changing
from text
to citext
with String
using case_sensitive
, or changing to
a Float64
column which requires setting the precision
, and scale
.
alter table_for(User) do
change_type email : String, case_sensitive: false
end