Class: BazaMigrations::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/baza_migrations/migration.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Migration

Returns a new instance of Migration.



2
3
4
5
6
# File 'lib/baza_migrations/migration.rb', line 2

def initialize(args = {})
  @db = args.fetch(:db)
  raise "No database was given" unless @db
  @changes = []
end

Instance Method Details

#changeObject



8
9
10
# File 'lib/baza_migrations/migration.rb', line 8

def change
  raise BazaMigrations::Errors::NotImplementedError
end

#downObject



16
17
18
# File 'lib/baza_migrations/migration.rb', line 16

def down
  raise BazaMigrations::Errors::NotImplementedError
end

#migrate(direction) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/baza_migrations/migration.rb', line 20

def migrate(direction)
  if direction == :up
    begin
      up
      execute_changes
    rescue BazaMigrations::Errors::NotImplementedError
      change
      execute_changes
    end
  elsif direction == :down
    begin
      down
      execute_changes
    rescue BazaMigrations::Errors::NotImplementedError
      change
      rollback_changed_changes
    end
  else
    raise "Invalid direction: #{direction}"
  end

  @changes = []
end

#upObject



12
13
14
# File 'lib/baza_migrations/migration.rb', line 12

def up
  raise BazaMigrations::Errors::NotImplementedError
end