Class: MendixBridge::Migration::Builder
- Inherits:
-
Object
- Object
- MendixBridge::Migration::Builder
- Defined in:
- lib/mendix_bridge/migration.rb
Constant Summary collapse
- RENAMABLE_TYPES =
%i[ entity microflow nanoflow page enumeration association constant module ].freeze
- DROPPABLE_TYPES =
%i[ entity microflow nanoflow page enumeration association constant ].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#alter_association(name, from:, to:, type:, owner: "Default") ⇒ Object
Re-declares an existing association in place (UUID preserved by mxcli's CREATE OR MODIFY).
- #alter_module_role(role, description:) ⇒ Object
- #alter_user_role(name, module_roles:, manage_all_roles: false) ⇒ Object
- #create_module(name) ⇒ Object
- #drop(type, name) ⇒ Object
- #drop_attribute(entity, name) ⇒ Object
- #drop_enumeration_value(enumeration, name) ⇒ Object
-
#initialize(name) ⇒ Builder
constructor
A new instance of Builder.
- #rename(type, name, to:) ⇒ Object
- #rename_attribute(entity, name, to:) ⇒ Object
- #rename_enumeration_value(enumeration, name, to:) ⇒ Object
- #result ⇒ Object
-
#retype_attribute(entity, name, to:) ⇒ Object
Changing an attribute's type has no in-place ALTER in MDL: it is an explicit DROP + ADD, which discards the column's data.
- #revoke_access(entity, role:) ⇒ Object
Constructor Details
#initialize(name) ⇒ Builder
Returns a new instance of Builder.
31 32 33 34 |
# File 'lib/mendix_bridge/migration.rb', line 31 def initialize(name) @name = name.to_s @operations = [] end |
Class Method Details
.build(name, &block) ⇒ Object
25 26 27 28 29 |
# File 'lib/mendix_bridge/migration.rb', line 25 def self.build(name, &block) builder = new(name) builder.instance_eval(&block) builder.result end |
Instance Method Details
#alter_association(name, from:, to:, type:, owner: "Default") ⇒ Object
Re-declares an existing association in place (UUID preserved by mxcli's CREATE OR MODIFY). Requires the full desired shape, not a delta.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/mendix_bridge/migration.rb', line 115 def alter_association(name, from:, to:, type:, owner: "Default") type = type.to_s raise ArgumentError, "association type must be Reference or ReferenceSet" unless %w[Reference ReferenceSet].include?(type) owner = owner.to_s raise ArgumentError, "association owner must be Default or Both" unless %w[Default Both].include?(owner) add( "alter_association", "association", qualified!(name), "from" => qualified!(from), "to" => qualified!(to), "type" => type, "owner" => owner ) end |
#alter_module_role(role, description:) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/mendix_bridge/migration.rb', line 153 def alter_module_role(role, description:) raise ArgumentError, "module role description cannot be empty" if description.nil? || description.to_s.empty? add( "alter_module_role", "modulerole", qualified!(role), "description" => description.to_s ) end |
#alter_user_role(name, module_roles:, manage_all_roles: false) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/mendix_bridge/migration.rb', line 165 def alter_user_role(name, module_roles:, manage_all_roles: false) roles = Array(module_roles).map { |role| qualified!(role) } raise ArgumentError, "user role requires at least one module role" if roles.empty? add( "alter_user_role", "userrole", identifier!(name), "module_roles" => roles, "manage_all_roles" => manage_all_roles ? true : false ) end |
#create_module(name) ⇒ Object
109 110 111 |
# File 'lib/mendix_bridge/migration.rb', line 109 def create_module(name) add("create_module", "module", identifier!(name)) end |
#drop(type, name) ⇒ Object
42 43 44 45 |
# File 'lib/mendix_bridge/migration.rb', line 42 def drop(type, name) type = checked_type(type, DROPPABLE_TYPES, "drop") add("drop", type, qualified!(name)) end |
#drop_attribute(entity, name) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mendix_bridge/migration.rb', line 60 def drop_attribute(entity, name) entity = qualified!(entity) name = identifier!(name) add( "drop_attribute", "attribute", "#{entity}.#{name}", "entity" => entity, "attribute" => name ) end |
#drop_enumeration_value(enumeration, name) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/mendix_bridge/migration.rb', line 85 def drop_enumeration_value(enumeration, name) enumeration = qualified!(enumeration) name = identifier!(name) add( "drop_enumeration_value", "enumeration_value", "#{enumeration}.#{name}", "enumeration" => enumeration, "value" => name ) end |
#rename(type, name, to:) ⇒ Object
36 37 38 39 40 |
# File 'lib/mendix_bridge/migration.rb', line 36 def rename(type, name, to:) type = checked_type(type, RENAMABLE_TYPES, "rename") name = type == "module" ? identifier!(name) : qualified!(name) add("rename", type, name, "to" => identifier!(to)) end |
#rename_attribute(entity, name, to:) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mendix_bridge/migration.rb', line 47 def rename_attribute(entity, name, to:) entity = qualified!(entity) name = identifier!(name) add( "rename_attribute", "attribute", "#{entity}.#{name}", "entity" => entity, "attribute" => name, "to" => identifier!(to) ) end |
#rename_enumeration_value(enumeration, name, to:) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mendix_bridge/migration.rb', line 72 def rename_enumeration_value(enumeration, name, to:) enumeration = qualified!(enumeration) name = identifier!(name) add( "rename_enumeration_value", "enumeration_value", "#{enumeration}.#{name}", "enumeration" => enumeration, "value" => name, "to" => identifier!(to) ) end |
#result ⇒ Object
178 179 180 181 182 183 |
# File 'lib/mendix_bridge/migration.rb', line 178 def result raise ArgumentError, "migration #{@name} requires at least one operation" if @operations.empty? Plan.new(name: @name, operations: @operations) end |
#retype_attribute(entity, name, to:) ⇒ Object
Changing an attribute's type has no in-place ALTER in MDL: it is an explicit DROP + ADD, which discards the column's data. That is why it lives here and not in the declarative apply.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/mendix_bridge/migration.rb', line 137 def retype_attribute(entity, name, to:) entity = qualified!(entity) name = identifier!(name) type = to.to_s.strip raise ArgumentError, "retype target type cannot be empty" if type.empty? add( "retype_attribute", "attribute", "#{entity}.#{name}", "entity" => entity, "attribute" => name, "type" => type ) end |
#revoke_access(entity, role:) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/mendix_bridge/migration.rb', line 97 def revoke_access(entity, role:) entity = qualified!(entity) role = qualified!(role) add( "revoke_access", "entity_access", "#{entity}:#{role}", "entity" => entity, "role" => role ) end |