Class: SimpleMigrator::Migrator

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_migrator/migrator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Migrator

Returns a new instance of Migrator.



3
4
5
6
# File 'lib/simple_migrator/migrator.rb', line 3

def initialize(connection)
  @connection = connection
  ensure_migration_table!
end

Class Method Details

.table_nameObject



25
26
27
# File 'lib/simple_migrator/migrator.rb', line 25

def self.table_name
  :schema_migrations
end

Instance Method Details

#migrate(name, &block) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/simple_migrator/migrator.rb', line 8

def migrate(name, &block)
  connection.transaction do
    unless migrated?(name)
      execute(block)
      was_migrated(name)
    end
  end
end

#migrated?(migration_name) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/simple_migrator/migrator.rb', line 17

def migrated? migration_name
  migrations_table.where(migration_name: migration_name).any?
end

#migrations_tableObject



21
22
23
# File 'lib/simple_migrator/migrator.rb', line 21

def migrations_table
  connection[table_name]
end

#table_nameObject



29
30
31
# File 'lib/simple_migrator/migrator.rb', line 29

def table_name
  self.class.table_name
end