Class: Cassie::Schema::Migrator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ Migrator



13
14
15
16
17
18
19
20
# File 'lib/cassie/schema/migrator.rb', line 13

def initialize(target)
  @target_version   = build_target_version(target)
  @current_version  = Cassie::Schema.version
  @direction        = build_direction
  @before_each      = Proc.new{}
  @after_each       = Proc.new{}
  @commands         = send("build_#{direction}_commands")
end

Instance Attribute Details

#after_eachObject

Returns the value of attribute after_each.



10
11
12
# File 'lib/cassie/schema/migrator.rb', line 10

def after_each
  @after_each
end

#before_eachObject

Returns the value of attribute before_each.



10
11
12
# File 'lib/cassie/schema/migrator.rb', line 10

def before_each
  @before_each
end

#commandsObject (readonly)

Returns the value of attribute commands.



9
10
11
# File 'lib/cassie/schema/migrator.rb', line 9

def commands
  @commands
end

#current_versionObject (readonly)

Returns the value of attribute current_version.



8
9
10
# File 'lib/cassie/schema/migrator.rb', line 8

def current_version
  @current_version
end

#directionObject (readonly)

Returns the value of attribute direction.



8
9
10
# File 'lib/cassie/schema/migrator.rb', line 8

def direction
  @direction
end

#target_versionObject (readonly)

Returns the value of attribute target_version.



8
9
10
# File 'lib/cassie/schema/migrator.rb', line 8

def target_version
  @target_version
end

Instance Method Details

#applied_versionsObject

versions applied to the database enumerated in most recent first order



30
31
32
# File 'lib/cassie/schema/migrator.rb', line 30

def applied_versions
  @applied_versions ||= Cassie::Schema.applied_versions.to_a
end

#migrateObject



22
23
24
25
26
# File 'lib/cassie/schema/migrator.rb', line 22

def migrate
  commands_with_callbacks do |command|
    command.execute
  end
end