Class: JIJI::Migration::Migrator
- Inherits:
-
Object
- Object
- JIJI::Migration::Migrator
- Defined in:
- lib/jiji/migration/migrator.rb
Overview
サーバー起動時にデータ移行を行うクラス。
Instance Attribute Summary collapse
-
#migrators ⇒ Object
Returns the value of attribute migrators.
-
#registry ⇒ Object
Returns the value of attribute registry.
-
#server_logger ⇒ Object
Returns the value of attribute server_logger.
-
#version_file ⇒ Object
Returns the value of attribute version_file.
Instance Method Summary collapse
-
#migrate ⇒ Object
データを移行する。.
-
#version ⇒ Object
現在のデータバージョンを取得する。.
Instance Attribute Details
#migrators ⇒ Object
Returns the value of attribute migrators.
43 44 45 |
# File 'lib/jiji/migration/migrator.rb', line 43 def migrators @migrators end |
#registry ⇒ Object
Returns the value of attribute registry.
46 47 48 |
# File 'lib/jiji/migration/migrator.rb', line 46 def registry @registry end |
#server_logger ⇒ Object
Returns the value of attribute server_logger.
44 45 46 |
# File 'lib/jiji/migration/migrator.rb', line 44 def server_logger @server_logger end |
#version_file ⇒ Object
Returns the value of attribute version_file.
45 46 47 |
# File 'lib/jiji/migration/migrator.rb', line 45 def version_file @version_file end |
Instance Method Details
#migrate ⇒ Object
データを移行する。
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jiji/migration/migrator.rb', line 14 def migrate logger = server_logger begin data_version = version new_version = data_version tmp = nil @migrators.sort_by {|item| item[:version] }.each {|d| tmp = d[:version] if ( data_version < d[:version] ) d[:migrator].migrate(registry) new_version = d[:version] logger.info "data migration succesful! new_version=#{new_version.to_s}." end } rescue Exception logger.error "data migration failed. current=#{data_version.to_s} new_version=#{tmp.to_s}" logger.error $! ensure FileLock.new( version_file ).writelock {|f| f << new_version.to_s } end end |