class DbSchema::Migrator::BodyYielder::AlterTableYielder
Attributes
alter_table[R]
fkey_operations[R]
Public Class Methods
new(table_name)
click to toggle source
# File lib/db_schema/migrator.rb, line 61 def initialize(table_name) @alter_table = Operations::AlterTable.new(table_name) @fkey_operations = [] end
Public Instance Methods
add_check(name, condition)
click to toggle source
# File lib/db_schema/migrator.rb, line 132 def add_check(name, condition) alter_table.changes << Operations::CreateCheckConstraint.new( Definitions::CheckConstraint.new(name: name, condition: condition) ) end
add_column(name, type, **options)
click to toggle source
# File lib/db_schema/migrator.rb, line 72 def add_column(name, type, **options) alter_table.changes << Operations::CreateColumn.new( Definitions::Field.build(name, type, options) ) end
add_foreign_key(*fkey_fields, **fkey_options)
click to toggle source
# File lib/db_schema/migrator.rb, line 142 def add_foreign_key(*fkey_fields, **fkey_options) fkey_operations << Operations::CreateForeignKey.new( alter_table.table_name, DSL::TableYielder.build_foreign_key( fkey_fields, table_name: alter_table.table_name, **fkey_options ) ) end
add_index(*columns, **index_options)
click to toggle source
# File lib/db_schema/migrator.rb, line 118 def add_index(*columns, **index_options) alter_table.changes << Operations::CreateIndex.new( DSL::TableYielder.build_index( columns, table_name: alter_table.table_name, **index_options ) ) end
add_primary_key(*columns)
click to toggle source
# File lib/db_schema/migrator.rb, line 108 def add_primary_key(*columns) alter_table.changes << Operations::CreateIndex.new( DSL::TableYielder.build_index(columns, table_name: alter_table.table_name, primary: true) ) end
allow_null(name)
click to toggle source
# File lib/db_schema/migrator.rb, line 96 def allow_null(name) alter_table.changes << Operations::AllowNull.new(name) end
alter_column_default(name, new_default)
click to toggle source
# File lib/db_schema/migrator.rb, line 104 def alter_column_default(name, new_default) alter_table.changes << Operations::AlterColumnDefault.new(name, new_default: new_default) end
alter_column_type(name, new_type, using: nil, **new_attributes)
click to toggle source
# File lib/db_schema/migrator.rb, line 86 def alter_column_type(name, new_type, using: nil, **new_attributes) alter_table.changes << Operations::AlterColumnType.new( name, old_type: nil, new_type: new_type, using: using, **new_attributes ) end
disallow_null(name)
click to toggle source
# File lib/db_schema/migrator.rb, line 100 def disallow_null(name) alter_table.changes << Operations::DisallowNull.new(name) end
drop_check(name)
click to toggle source
# File lib/db_schema/migrator.rb, line 138 def drop_check(name) alter_table.changes << Operations::DropCheckConstraint.new(name) end
drop_column(name)
click to toggle source
# File lib/db_schema/migrator.rb, line 78 def drop_column(name) alter_table.changes << Operations::DropColumn.new(name) end
drop_foreign_key(fkey_name)
click to toggle source
# File lib/db_schema/migrator.rb, line 153 def drop_foreign_key(fkey_name) fkey_operations << Operations::DropForeignKey.new( alter_table.table_name, fkey_name ) end
drop_index(name)
click to toggle source
# File lib/db_schema/migrator.rb, line 128 def drop_index(name) alter_table.changes << Operations::DropIndex.new(name, false) end
drop_primary_key()
click to toggle source
# File lib/db_schema/migrator.rb, line 114 def drop_primary_key alter_table.changes << Operations::DropIndex.new(:"#{alter_table.table_name}_pkey", true) end
rename_column(from, to:)
click to toggle source
# File lib/db_schema/migrator.rb, line 82 def rename_column(from, to:) alter_table.changes << Operations::RenameColumn.new(old_name: from, new_name: to) end
run(block)
click to toggle source
# File lib/db_schema/migrator.rb, line 66 def run(block) block.call(self) [alter_table, *fkey_operations] end