brick 1.0.197 → 1.0.199

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfd8798f339e1bb363ca73f7b3285cdb32471cbae2c6ff5a500b43db6536840a
4
- data.tar.gz: be5744fd98d6323ecb33be2b77f50e9ee5b872bc8356ef4d08372cddab4d9920
3
+ metadata.gz: 45f0082e1fac37af74b7ee802123ba84b8f670596fbd6f47c704ce6e660a6a2e
4
+ data.tar.gz: aad9255dbb59fda237d733508268f817666158984633b5e2965ed2fcfa909d9b
5
5
  SHA512:
6
- metadata.gz: 8848e2c6a93a75f454b0b9ebd4712769c39868583fc6d6659548c6eb3818eec12bfb7968580a4c684eab67095fca754553a42bc4b71729b223f79882731ebfd3
7
- data.tar.gz: b764da2f667e22e5d02e6f5354e3b4b30164827c5b40647b7fca672038f7435ebe14f32dc22d05c54375a29e94c68d82b61dc590099f9e26f2b4843092861bed
6
+ metadata.gz: f1ec256df47b3091bf23ad128ae74e3e3baef71052fc6353fa24fefe2744bf8d28bf8ba1aea595c583049745c7addf26a5cbd992b91406a5b457a4e6e6a4e2e7
7
+ data.tar.gz: e6c9cc621f4cd184be0da3c924b3e529f2964b1125c518aeb93f9c1fd1a7e55c94ab278d1573522a01f5b9f5969c044685659f2ffb4656dce0fd001df759990d
@@ -438,7 +438,7 @@ module ActiveRecord
438
438
  when String
439
439
  ord_expr = _br_quoted_name(ord_part.gsub('^^^', table_name))
440
440
  s << Arel.sql(ord_expr)
441
- order_by_txt&.<<(ord_expr.index('.') ? "Arel.sql(#{ord_expr.inspect})" : ord_expr)
441
+ order_by_txt&.<<(ord_expr.index('.') ? "Arel.sql(#{ord_expr.inspect})" : ord_part.inspect)
442
442
  else # Expecting only Symbol
443
443
  ord_part = ord_part.to_s
444
444
  if ord_part[0] == '-' # First char '-' means descending order
@@ -3050,8 +3050,8 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
3050
3050
  colliding_thing ||= klass
3051
3051
  end
3052
3052
  v[:class_name] = proposed_name_parts.join('::')
3053
- # Was: v[:resource] = v[:class_name].underscore.tr('/', '.').pluralize
3054
- v[:resource] = proposed_name_parts.last.underscore.pluralize
3053
+ # Was: v[:resource] = v[:class_name].underscore.tr('/', '.')
3054
+ v[:resource] = proposed_name_parts.last.underscore
3055
3055
  if colliding_thing
3056
3056
  message_start = if colliding_thing.is_a?(Module) && Object.const_defined?(:Rails) &&
3057
3057
  colliding_thing.constants.find { |c| colliding_thing.const_get(c) < Rails::Application }
@@ -3470,11 +3470,11 @@ module Brick
3470
3470
  res_name << '.' if res_name
3471
3471
  (res_name ||= +'') << (relation ||= ::Brick.relations.fetch(tbl_name, nil))&.fetch(:resource, nil) || tbl_name_parts.last
3472
3472
 
3473
- res_parts = ((mode == :singular) ? tbl_name.singularize : tbl_name).split('.')
3473
+ res_parts = ((mode == :singular) ? res_name.singularize : res_name).split('.')
3474
3474
  res_parts.shift if ::Brick.apartment_multitenant && res_parts.length > 1 && res_parts.first == ::Brick.apartment_default_tenant
3475
- if (aps = relation&.fetch(:auto_prefixed_schema, nil)) && res_parts.last.start_with?(aps)
3476
- last_part = res_parts.last[aps.length..-1]
3475
+ if (aps = relation&.fetch(:auto_prefixed_schema, nil)) # && res_parts.last.start_with?(aps)
3477
3476
  aps = aps[0..-2] if aps[-1] == '_'
3477
+ last_part = res_parts.last # [aps.length..-1]
3478
3478
  res_parts[-1] = aps
3479
3479
  res_parts << last_part
3480
3480
  end
@@ -788,13 +788,6 @@ window.addEventListener(\"popstate\", linkSchemas);
788
788
  next if rel.first.blank? || rel.last[:cols].empty? ||
789
789
  ::Brick.config.exclude_tables.include?(rel.first)
790
790
 
791
- tbl_parts = rel.first.split('.')
792
- if (aps = rel.last.fetch(:auto_prefixed_schema, nil))
793
- tbl_parts << tbl_parts.last[aps.length..-1]
794
- aps = aps[0..-2] if aps[-1] == '_'
795
- tbl_parts[-2] = aps
796
- end
797
- tbl_parts.shift if tbl_parts.first == apartment_default_schema
798
791
  # %%% When table_name_prefixes are use then during rendering empty non-TNP
799
792
  # entries get added at some point when an attempt is made to find the table.
800
793
  # Will have to hunt that down at some point.
@@ -1623,7 +1616,7 @@ end %>#{"
1623
1616
  <td><%= link_to_brick(
1624
1617
  ::Brick::Rails::AA_PNG.html_safe,
1625
1618
  { show_proc: Proc.new do |aa_model, relation|
1626
- path_helper = \"#\{ns}_#\{relation.fetch(:auto_prefixed_schema, nil)}#\{rk = aa_model.model_name.singular_route_key}_path\".to_sym
1619
+ path_helper = \"#\{ns}_#\{relation.fetch(:auto_prefixed_schema, nil)}#\{aa_model.model_name.singular_route_key}_path\".to_sym
1627
1620
  send(path_helper, obj) if respond_to?(path_helper)
1628
1621
  end,
1629
1622
  title: \"#\{page_title} in ActiveAdmin\" }
@@ -73,7 +73,7 @@ module Brick::Rails::FormTags
73
73
  <td>#{link_to_brick(
74
74
  ::Brick::Rails::AA_PNG.html_safe,
75
75
  { index_proc: Proc.new do |aa_model, relation|
76
- path_helper = "#{ns}_#{relation.fetch(:auto_prefixed_schema, nil)}#{rk = aa_model.model_name.route_key}_path".to_sym
76
+ path_helper = "#{ns}_#{relation.fetch(:auto_prefixed_schema, nil)}#{aa_model.model_name.route_key}_path".to_sym
77
77
  send(path_helper) if respond_to?(path_helper)
78
78
  end,
79
79
  title: "#{klass.name} in ActiveAdmin" }
@@ -137,7 +137,7 @@ module Brick::Rails::FormTags
137
137
  options[col[1].inheritance_column] = col[1].name unless col[1] == col[1].base_class
138
138
  x_order = " x-order=\"#{col_name}\"" if true
139
139
  s << "#{x_order}>#{col[2]} "
140
- s << (col.first ? "#{col[3]}" : "#{link_to(col[3], send("#{col[1]._brick_index}_path", options))}")
140
+ s << (col.first ? col[3].to_s : "#{link_to(col[3], send("#{col[1]._brick_index}_path", options))}")
141
141
  elsif cust_cols.key?(col_name) # Custom column
142
142
  x_order = " x-order=\"#{col_name}\"" if true
143
143
  s << "#{x_order}>#{col_name}"
@@ -77,7 +77,7 @@ module Brick
77
77
  resource_name = v.fetch(:resource, nil) || k
78
78
  next if !resource_name ||
79
79
  existing_controllers.key?(
80
- controller_prefix + (resource_name = "#{schema_prefix&.tr('.', '/')}#{resource_name}".pluralize)
80
+ "#{controller_prefix}#{schema_prefix&.tr('.', '/')}#{resource_name}".pluralize
81
81
  )
82
82
 
83
83
  object_name = k.split('.').last # Take off any first schema part
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 197
8
+ TINY = 199
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
data/lib/brick.rb CHANGED
@@ -224,7 +224,7 @@ module Brick
224
224
  if !a.polymorphic? && (a.belongs_to? || (through && (thr = a.through_reflection))) &&
225
225
  !((kls = thr&.klass || a.klass) && ::Brick.config.exclude_tables.exclude?(kls.table_name) &&
226
226
  (!a.belongs_to? ||
227
- ((fk_type = a.foreign_key.is_a?(Array) ? a.foreign_key.map { |fk_part| model_cols[fk_part.to_s].type } : model_cols[a.foreign_key.to_s].type) &&
227
+ ((fk_type = a.foreign_key.is_a?(Array) ? a.foreign_key.map { |fk_part| model_cols[fk_part.to_s].type } : model_cols[a.foreign_key.to_s]&.type) &&
228
228
  (primary_cols = primary_klass.columns_hash) &&
229
229
  (pk_type = a_pk.is_a?(Array) ? a_pk.map { |pk_part| primary_cols[pk_part.to_s].type } : primary_cols[a_pk].type) &&
230
230
  (same_type = (pk_type == fk_type))
@@ -93,7 +93,10 @@ module Brick
93
93
  relations = ::Brick.relations, do_fks_last: nil, do_schema_migrations: true)
94
94
  if do_fks_last.nil?
95
95
  puts 'Would you like for the foreign keys to be built inline inside of each migration file, or as a final migration?'
96
- do_fks_last = (gets_list(list: ['Inline', 'Separate final migration for all FKs']).start_with?('Separate'))
96
+ options = ['Inline', 'Separate final migration for all FKs']
97
+ options << 'Create "additional_references" entries in brick.rb that emulate foreign keys'
98
+ do_fks = gets_list(list: options).split(' ').first
99
+ do_fks_last = do_fks unless do_fks == 'Inline'
97
100
  end
98
101
 
99
102
  is_sqlite = ActiveRecord::Base.connection.adapter_name == 'SQLite'
@@ -138,10 +141,10 @@ module Brick
138
141
  end
139
142
  end).present?
140
143
  fringe.each do |tbl|
141
- mig = gen_migration_columns(relations, tbl, (tbl_parts = tbl.split('.')), (add_fks = []),
144
+ mig = gen_migration_columns(relations, tbl, (tbl_parts = tbl.split('.')), (add_fks = []), built_schemas, mig_path, current_mig_time,
142
145
  key_type, is_4x_rails, ar_version, do_fks_last)
143
146
  after_fks.concat(add_fks) if do_fks_last
144
- versions_to_create << migration_file_write(mig_path, ::Brick._brick_index("create_#{tbl}", nil, 'x'), current_mig_time += 1.minute, ar_version, mig)
147
+ versions_to_create << migration_file_write(mig_path, "create_#{::Brick._brick_index(tbl, nil, 'x')}", current_mig_time += 1.minute, ar_version, mig)
145
148
  end
146
149
  done.concat(fringe)
147
150
  chosen -= done
@@ -150,46 +153,65 @@ module Brick
150
153
  if do_fks_last
151
154
  # Write out any more tables that haven't been done yet
152
155
  chosen.each do |tbl|
153
- mig = gen_migration_columns(relations, tbl, (tbl_parts = tbl.split('.')), (add_fks = []),
156
+ mig = gen_migration_columns(relations, tbl, (tbl_parts = tbl.split('.')), (add_fks = []), built_schemas, mig_path, current_mig_time,
154
157
  key_type, is_4x_rails, ar_version, do_fks_last)
155
158
  after_fks.concat(add_fks)
156
- migration_file_write(mig_path, ::Brick._brick_index("create_#{tbl}", nil, 'x'), current_mig_time += 1.minute, ar_version, mig)
159
+ migration_file_write(mig_path, "create_#{::Brick._brick_index(tbl, nil, 'x')}", current_mig_time += 1.minute, ar_version, mig)
157
160
  end
158
161
  done.concat(chosen)
159
162
  chosen.clear
160
163
 
161
- # Add a final migration to create all the foreign keys
162
- mig = +" def change\n"
163
- after_fks.each do |add_fk|
164
- next unless add_fk[2] # add_fk[2] holds the inverse relation
164
+ case do_fks_last
165
+ when 'Separate' # Add a final migration to create all the foreign keys
166
+ mig = +" def change\n"
167
+ after_fks.each do |add_fk|
168
+ next unless add_fk[2] # add_fk[2] holds the inverse relation
165
169
 
166
- unless (pk = add_fk[2][:pkey].values.flatten&.first)
167
- # No official PK, but if coincidentally there's a column of the same name, take a chance on it
168
- pk = (add_fk[2][:cols].key?(add_fk[1]) && add_fk[1]) || '???'
170
+ unless (pk = add_fk[2][:pkey].values.flatten&.first)
171
+ # No official PK, but if coincidentally there's a column of the same name, take a chance on it
172
+ pk = (add_fk[2][:cols].key?(add_fk[1]) && add_fk[1]) || '???'
173
+ end
174
+ mig << " add_foreign_key #{add_fk[3]}, " # The tbl_code
175
+ # to_table column
176
+ mig << "#{add_fk[0]}, column: :#{add_fk[1]}, primary_key: :#{pk}\n"
169
177
  end
170
- mig << " add_foreign_key #{add_fk[3]}, " # The tbl_code
171
- # to_table column
172
- mig << "#{add_fk[0]}, column: :#{add_fk[1]}, primary_key: :#{pk}\n"
173
- end
174
- if after_fks.length > 500
175
- minutes = (after_fks.length + 1000) / 1500
176
- mig << " if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'\n"
177
- mig << " puts 'NOTE: It could take around #{minutes} #{'minute'.pluralize(minutes)} on a FAST machine for Postgres to do all the final processing for these foreign keys. Please be patient!'\n"
178
+ if after_fks.length > 500
179
+ minutes = (after_fks.length + 1000) / 1500
180
+ mig << " if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'\n"
181
+ mig << " puts 'NOTE: It could take around #{minutes} #{'minute'.pluralize(minutes)} on a FAST machine for Postgres to do all the final processing for these foreign keys. Please be patient!'\n"
178
182
 
179
- mig << " # Vacuum takes only about ten seconds when all the tables are empty,
183
+ mig << " # Vacuum takes only about ten seconds when all the tables are empty,
180
184
  # and about 2 minutes when the tables are fairly full.
181
185
  execute('COMMIT')
182
186
  execute('VACUUM FULL')
183
187
  execute('BEGIN TRANSACTION')
184
188
  end\n"
185
- end
186
-
187
- mig << +" end\n"
188
- migration_file_write(mig_path, 'create_brick_fks.rbx', current_mig_time += 1.minute, ar_version, mig)
189
- puts "Have written out a final migration called 'create_brick_fks.rbx' which creates #{after_fks.length} foreign keys.
189
+ end
190
+ mig << +" end\n"
191
+ migration_file_write(mig_path, 'create_brick_fks.rbx', current_mig_time += 1.minute, ar_version, mig)
192
+ puts "Have written out a final migration called 'create_brick_fks.rbx' which creates #{after_fks.length} foreign keys.
190
193
  This file extension (.rbx) will cause it not to run yet when you do a 'rails db:migrate'.
191
194
  The idea here is to do all data loading first, and then rename that migration file back
192
195
  into having a .rb extension, and run a final db:migrate to put the foreign keys in place."
196
+
197
+ when 'Create' # Show additional_references entries that can be added into brick.rb
198
+ puts 'Place this block into your brick.rb file:'
199
+ puts ' ::Brick.additional_references = ['
200
+ after_fks.each do |add_fk|
201
+ next unless add_fk[2] # add_fk[2] holds the inverse relation
202
+
203
+ unless (pk = add_fk[2][:pkey].values.flatten&.first)
204
+ # No official PK, but if coincidentally there's a column of the same name, take a chance on it
205
+ pk = (add_fk[2][:cols].key?(add_fk[1]) && add_fk[1]) || '???'
206
+ end
207
+ from_table = add_fk[3]
208
+ from_table = "'#{from_table[1..-1]}'" if from_table[0] == ':'
209
+ to_table = add_fk[0]
210
+ to_table = "'#{to_table[1..-1]}'" if to_table[0] == ':'
211
+ puts " [#{from_table}, #{add_fk[1].inspect}, #{to_table}],"
212
+ end
213
+ puts ' ]'
214
+ end
193
215
  end
194
216
 
195
217
  stuck_counts = Hash.new { |h, k| h[k] = 0 }
@@ -232,7 +254,7 @@ module Brick
232
254
 
233
255
  private
234
256
 
235
- def gen_migration_columns(relations, tbl, tbl_parts, add_fks,
257
+ def gen_migration_columns(relations, tbl, tbl_parts, add_fks, built_schemas, mig_path, current_mig_time,
236
258
  key_type, is_4x_rails, ar_version, do_fks_last)
237
259
  return unless (relation = relations.fetch(tbl, nil))&.fetch(:cols, nil)&.present?
238
260
 
@@ -74,7 +74,7 @@ module Brick
74
74
  end
75
75
  # Build but do not have foreign keys established yet, and do not put version entries info the schema_migrations table
76
76
  ::Brick::MigrationBuilder.generate_migrations(chosen, mig_path, is_insert_versions, is_delete_versions, relations,
77
- do_fks_last: true, do_schema_migrations: false)
77
+ do_fks_last: 'Separate', do_schema_migrations: false)
78
78
  end
79
79
  parser = Nokogiri::XML::SAX::Parser.new(::Brick::SalesforceSchema.new(end_document_proc))
80
80
  # The WSDL file must have a .xml extension, and can be in any folder in the project
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.197
4
+ version: 1.0.199
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-02 00:00:00.000000000 Z
11
+ date: 2024-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord