class

Avram::Migrator::AlterTableStatement

Inherits Avram::Migrator::MissingOnDeleteWithBelongsToError < Avram::Migrator::IndexStatementHelpers < Reference < Object

Constructors

new(table_name : TableName, *, if_exists : Bool = false)
Source

Instance methods

add_change_default_statement(column : Avram::Migrator::Columns::Base)
Source
add_change_type_statement(column : Avram::Migrator::Columns::Base)
Source
add_fill_existing_with_statements(column : Symbol | String, type, value, nilable)
Source
alter_statements
Source
build

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"
]
Source
build_nullability_statement(column_name, nullability)
Source
change_default_statements
Source
change_nullability_statements
Source
change_type_statements
Source
dropped_rows
Source
fill_existing_with_statements
Source
if_exists_statement
Source
renamed_rows
Source
rows
Source
statements
Source

Macros

add(type_declaration, index = false, using = :btree, unique = false, default = nil, fill_existing_with = nil, **type_options)
Source
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.

Source
allow_nulls_for(column_name)

Change the column's nullability from whatever it is currently to true.

alter table_for(User) do
  allow_nulls_for :email
end
Source
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
Source
change_type(type_declaration, **type_options)

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
Source
forbid_nulls_for(column_name)

Change the column's nullability from whatever it is currently to false.

alter table_for(User) do
  forbid_nulls_for :email
end
Source
remove(name)
Source
remove_belongs_to(association_name)
Source
rename(old_name, new_name)
Source
rename_belongs_to(old_association_name, new_association_name)
Source
symbol_expected_error(action, name)
Source