Class: XxxRename::MigrationClient
- Inherits:
-
Object
- Object
- XxxRename::MigrationClient
- Defined in:
- lib/xxx_rename/migration_client.rb
Constant Summary collapse
- MIGRATION_FORMAT =
/output_(?<version>\d{12})/x.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #apply ⇒ Object
- #datastore ⇒ Object
-
#initialize(config, version) ⇒ MigrationClient
constructor
A new instance of MigrationClient.
- #rollback ⇒ Object
- #version_file! ⇒ Object
Constructor Details
#initialize(config, version) ⇒ MigrationClient
Returns a new instance of MigrationClient.
18 19 20 21 |
# File 'lib/xxx_rename/migration_client.rb', line 18 def initialize(config, version) @version = version @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/xxx_rename/migration_client.rb', line 14 def config @config end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
14 15 16 |
# File 'lib/xxx_rename/migration_client.rb', line 14 def version @version end |
Instance Method Details
#apply ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/xxx_rename/migration_client.rb', line 37 def apply if datastore.migration_status XxxRename.logger.info "[MIGRATION UP]" return end XxxRename.logger.info "[RENAMING #{datastore.length} FILES]" datastore.all.each do |op| process_rename_op(op) rescue SystemCallError => e XxxRename.logger.error "[RENAME FAILURE] #{e.}" datastore.add_failure(op.key, e.) end ensure if datastore.failures.empty? datastore.migration_status = 1 XxxRename.logger.info "[MIGRATION UP]" end end |
#datastore ⇒ Object
33 34 35 |
# File 'lib/xxx_rename/migration_client.rb', line 33 def datastore @datastore ||= Data::FileRenameOpDatastore.new(store, config.mutex) end |
#rollback ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/xxx_rename/migration_client.rb', line 57 def rollback unless datastore.migration_status XxxRename.logger.info "[MIGRATION DOWN]" return end XxxRename.logger.info "[ROLLBACK RENAMING #{datastore.length} FILES]" datastore.all.each do |op| process_reverse_rename_op(op) rescue SystemCallError => e XxxRename.logger.error "[RENAME FAILURE] #{e.}" datastore.add_failure(op.key, e.) end ensure if datastore.failures.empty? datastore.migration_status = 0 XxxRename.logger.info "[MIGRATION DOWN]" end end |
#version_file! ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/xxx_rename/migration_client.rb', line 23 def version_file! Dir.chdir(output_dir) do all_output_files = Dir["output_*.yml"].sort.reverse! raise Errors::FatalError, "[ERR NO MIGRATION FILES FOUND]" if all_output_files.empty? file = match_file!(all_output_files) File.join(Dir.pwd, file) end end |