Class: MendixBridge::MigrationExecutor
- Inherits:
-
Object
- Object
- MendixBridge::MigrationExecutor
- Defined in:
- lib/mendix_bridge/migration_executor.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
- #apply(plan, project_file:, confirmation:, studio_closed:) ⇒ Object
-
#initialize(mxcli:) ⇒ MigrationExecutor
constructor
A new instance of MigrationExecutor.
- #restore(backup_dir, project_file:, confirmation:, studio_closed:) ⇒ Object
Constructor Details
#initialize(mxcli:) ⇒ MigrationExecutor
Returns a new instance of MigrationExecutor.
16 17 18 |
# File 'lib/mendix_bridge/migration_executor.rb', line 16 def initialize(mxcli:) @mxcli = File.(mxcli) end |
Instance Method Details
#apply(plan, project_file:, confirmation:, studio_closed:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mendix_bridge/migration_executor.rb', line 20 def apply(plan, project_file:, confirmation:, studio_closed:) project_file = File.(project_file) validate!(plan, project_file, confirmation, studio_closed) project_dir = File.dirname(project_file) ensure_clean_git!(project_dir) validate_operations!(plan, project_file) backup_dir = create_backup(plan, project_file) begin apply_renames!(plan, project_file) apply_mdl!(plan, project_file) check_project!(project_file) rescue StandardError => error begin restore_backup!(backup_dir, project_file) check_project!(project_file) rescue StandardError => restore_error raise MigrationError, "migration failed and automatic restore also failed; " \ "backup is #{backup_dir}: #{restore_error.}" end raise MigrationError, "migration failed and backup was restored: #{error.}" end Result.new(backup_dir:, operations: plan.operations.length) end |
#restore(backup_dir, project_file:, confirmation:, studio_closed:) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mendix_bridge/migration_executor.rb', line 48 def restore(backup_dir, project_file:, confirmation:, studio_closed:) backup_dir = File.(backup_dir) project_file = File.(project_file) manifest = read_manifest(backup_dir) expected = File.basename(backup_dir) raise MigrationError, "confirmation must exactly match #{expected}" unless confirmation == expected raise MigrationError, "--studio-closed is required" unless studio_closed unless File.(manifest.fetch("project_file")) == project_file raise MigrationError, "backup belongs to another Mendix project" end restore_backup!(backup_dir, project_file) check_project!(project_file) true end |