class DbSchema::Migrator::BodyYielder
Attributes
connection[R]
Public Class Methods
new(connection)
click to toggle source
# File lib/db_schema/migrator.rb, line 24 def initialize(connection) @connection = connection end
Public Instance Methods
alter_table(name, &block)
click to toggle source
# File lib/db_schema/migrator.rb, line 54 def alter_table(name, &block) run AlterTableYielder.new(name).run(block) end
create_enum(name, values)
click to toggle source
# File lib/db_schema/migrator.rb, line 161 def create_enum(name, values) run Operations::CreateEnum.new(Definitions::Enum.new(name, values)) end
create_extension(name)
click to toggle source
# File lib/db_schema/migrator.rb, line 173 def create_extension(name) run Operations::CreateExtension.new(Definitions::Extension.new(name)) end
create_table(name, &block)
click to toggle source
# File lib/db_schema/migrator.rb, line 28 def create_table(name, &block) table_yielder = DSL::TableYielder.new(name, block) table = Definitions::Table.new( name, fields: table_yielder.fields, indexes: table_yielder.indexes, checks: table_yielder.checks, foreign_keys: table_yielder.foreign_keys ) run Operations::CreateTable.new(table) table.foreign_keys.each do |fkey| run Operations::CreateForeignKey.new(table.name, fkey) end end
drop_enum(name)
click to toggle source
# File lib/db_schema/migrator.rb, line 165 def drop_enum(name) run Operations::DropEnum.new(name) end
drop_extension(name)
click to toggle source
# File lib/db_schema/migrator.rb, line 177 def drop_extension(name) run Operations::DropExtension.new(name) end
drop_table(name)
click to toggle source
# File lib/db_schema/migrator.rb, line 46 def drop_table(name) run Operations::DropTable.new(name) end
execute(query)
click to toggle source
# File lib/db_schema/migrator.rb, line 181 def execute(query) run Operations::ExecuteQuery.new(query) end
rename_enum(from, to:)
click to toggle source
# File lib/db_schema/migrator.rb, line 169 def rename_enum(from, to:) run Operations::RenameEnum.new(old_name: from, new_name: to) end
rename_table(from, to:)
click to toggle source
# File lib/db_schema/migrator.rb, line 50 def rename_table(from, to:) run Operations::RenameTable.new(old_name: from, new_name: to) end
Private Instance Methods
run(operation)
click to toggle source
# File lib/db_schema/migrator.rb, line 186 def run(operation) Runner.new(Array(operation), connection).run! end