class Avram::Migrator::AlterTableStatement
Included Modules
Defined in:
avram/migrator/alter_table_statement.crConstructors
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, index = true)
Adds a references column and index given a model class and references option.
-
allow_nulls_for(column_name)
Change the column's nullability from whatever it is currently to true.
DEPRECATED Use make_optional instead
-
change_default(type_declaration, default)
Change the columns' default value to
default
alter table_for(Post) do change_default published_at : Time, default: :now end
-
change_type(type_declaration, **type_options)
Change the column's type from whatever it is currently to
type_declaration.type
. -
forbid_nulls_for(column_name)
Change the column's nullability from whatever it is currently to false.
DEPRECATED Use make_required instead
- 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 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. - #build_nullability_statement(column_name, nullability)
- #change_default_statements : Array(String)
- #change_nullability_statements : Array(String)
- #change_type_statements : Array(String)
- #dropped_rows : Array(String)
- #fill_existing_with_statements : Array(String)
- #if_exists_statement
- #renamed_rows : Array(String)
- #rows : Array(String)
- #statements
Macros inherited from module Avram::Migrator::MissingOnDeleteWithBelongsToError
add_belongs_to(type_declaration, references = nil)
add_belongs_to
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
Macro Detail
Adds a references column and index given a model class and references option.
Change the column's nullability from whatever it is currently to true.
alter table_for(User) do
allow_nulls_for :email
end
DEPRECATED Use make_optional instead
Change the columns' default value to default
alter table_for(Post) do
change_default published_at : Time, 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
Change the column's nullability from whatever it is currently to false.
alter table_for(User) do
forbid_nulls_for :email
end
DEPRECATED Use make_required instead
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"
]