Class: Themigrator::Migrator
- Inherits:
-
Object
- Object
- Themigrator::Migrator
- Includes:
- Logger
- Defined in:
- lib/themigrator/migrator.rb
Constant Summary
Constants included from Logger
Instance Attribute Summary collapse
-
#run_id ⇒ Object
readonly
Returns the value of attribute run_id.
Instance Method Summary collapse
-
#initialize(dir, options = {}) ⇒ Migrator
constructor
A new instance of Migrator.
- #migrate! ⇒ Object
Methods included from Logger
#close_logger, #init_logger, #log, #log_dir, #log_path, #logger, #main_log_path
Constructor Details
#initialize(dir, options = {}) ⇒ Migrator
Returns a new instance of Migrator.
11 12 13 14 15 16 17 |
# File 'lib/themigrator/migrator.rb', line 11 def initialize(dir, = {}) @options = @dir = dir @runned_roles = [] @start_time = Time.now @run_id = @start_time.strftime('%Y-%m-%d-%H:%M:%S') end |
Instance Attribute Details
#run_id ⇒ Object (readonly)
Returns the value of attribute run_id.
9 10 11 |
# File 'lib/themigrator/migrator.rb', line 9 def run_id @run_id end |
Instance Method Details
#migrate! ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/themigrator/migrator.rb', line 19 def migrate! @migration = Migration.new(@dir, roles: @options[:roles]) @migration.analyze_project! init_logger(main_log_path(@dir, run_id)) unless @options[:log_stdout] log "start PID=#{$$}" log "roles: #{@migration.roles.join(' ')}" did_it_work = true each_action do |action| next if run_action_and_wait(action) did_it_work = false run_action_and_wait('rollback') return -1 end did_it_work ensure @end_time = Time.now msg = did_it_work ? 'done' : 'fail' log "end => #{msg} (#{run_time * 1000} ms)" close_logger end |