brick 1.0.197 → 1.0.198

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: 9de3c9df6786000fb662d7aa133a5c53b2ed5d06a114edd3165dfd0acd3ebe7c
4
+ data.tar.gz: 7750790ca7698e8291ebd2843692009ef29795aab60c5691911698a835808bda
5
5
  SHA512:
6
- metadata.gz: 8848e2c6a93a75f454b0b9ebd4712769c39868583fc6d6659548c6eb3818eec12bfb7968580a4c684eab67095fca754553a42bc4b71729b223f79882731ebfd3
7
- data.tar.gz: b764da2f667e22e5d02e6f5354e3b4b30164827c5b40647b7fca672038f7435ebe14f32dc22d05c54375a29e94c68d82b61dc590099f9e26f2b4843092861bed
6
+ metadata.gz: dcb14263731745917eba2172d838b7eeb11910a1bab8c93dbe5d27b8923f98e16b24c08b74c52c550f75bc900cb61af1d1783d010ae9ed3000e03043749f47d8
7
+ data.tar.gz: ec2111be292b26489b972782478151f1468c2d02c6c84dc144c09bd4a8c0e34104fcb392c0ebdc9758eda6061ed62db982e4751e2e885edd282c4ba42c144bed
@@ -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,7 +3470,7 @@ 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) ? tbl_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
3475
  if (aps = relation&.fetch(:auto_prefixed_schema, nil)) && res_parts.last.start_with?(aps)
3476
3476
  last_part = res_parts.last[aps.length..-1]
@@ -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 = 198
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
@@ -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'
@@ -141,7 +144,7 @@ module Brick
141
144
  mig = gen_migration_columns(relations, tbl, (tbl_parts = tbl.split('.')), (add_fks = []),
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
@@ -153,43 +156,59 @@ module Brick
153
156
  mig = gen_migration_columns(relations, tbl, (tbl_parts = tbl.split('.')), (add_fks = []),
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 column to_table
208
+ puts " [#{add_fk[3].to_s.inspect}, #{add_fk[1].inspect}, #{add_fk[0].to_s.inspect}]"
209
+ end
210
+ puts ' ]'
211
+ end
193
212
  end
194
213
 
195
214
  stuck_counts = Hash.new { |h, k| h[k] = 0 }
@@ -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.198
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-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord