class Avram::Migrator::AlterTableStatement

Included Modules

Defined in:

avram/migrator/alter_table_statement.cr

Constructors

Instance Method Summary

Macro Summary

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

def self.new(table_name : Symbol) #

[View source]

Instance Method Detail

def add_change_type_statement(column : Avram::Migrator::Columns::Base) #

[View source]
def add_fill_existing_with_statements(column : Symbol | String, type, value) #

[View source]
def alter_statements : Array(String) #

[View source]
def 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"
]

[View source]
def change_type_statements : Array(String) #

[View source]
def dropped_rows : Array(String) #

[View source]
def fill_existing_with_statements : Array(String) #

[View source]
def remove(name : Symbol) #

[View source]
def rows : Array(String) #

[View source]
def statements #

[View source]

Macro Detail

macro add(type_declaration, index = false, using = :btree, unique = false, default = nil, fill_existing_with = nil, **type_options) #

[View source]
macro add_belongs_to(type_declaration, on_delete, references = nil, foreign_key_type = Int64) #

Adds a references column and index given a model class and references option.


[View source]
macro change_type(type_declaration, **type_options) #

[View source]
macro remove_belongs_to(association_name) #

[View source]