Avram::Migrator::AlterTableStatement
Inherits Avram::Migrator::MissingOnDeleteWithBelongsToError < Avram::Migrator::IndexStatementHelpers < Reference < Object
Constructors
Instance methods
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"
]
Macros
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
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