brick 1.0.233 → 1.0.235
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/brick/extensions.rb +2 -0
- data/lib/brick/rails/engine.rb +3 -1
- data/lib/brick/version_number.rb +1 -1
- data/lib/generators/brick/seeds_builder.rb +30 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbee410a881406dbcec60714bf2688d0cbc4aef0c89a68888ce9f2401e0005dd
|
4
|
+
data.tar.gz: b1a06757052b4130080b6a8762b1d7f8522f551956850bb8c2fe6655260380eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eca4cb00874a367159483ac23a6a03d273d5b5bd54913272f99a7ffefc26e2bbaced2a52b9df624320912e9b70445a432dd4694e5ccc673cb60187633e87d91
|
7
|
+
data.tar.gz: 381d498e42a473cf92cd556b843c59eb08618b0c8f2e61808689a4f1b4c2d5a0e0078d171d64b055cedca78d81bf5fbcfa73eff5268ca3d9d56076ec1c505299
|
data/lib/brick/extensions.rb
CHANGED
@@ -2521,6 +2521,7 @@ class Object
|
|
2521
2521
|
end
|
2522
2522
|
ar_select = ar_relation.respond_to?(:_select!) ? ar_relation.dup._select!(*selects, *counts) : ar_relation.select(selects + counts)
|
2523
2523
|
instance_variable_set("@#{plural_table_name}".to_sym, ar_select)
|
2524
|
+
@_lookup_context.instance_variable_set(:@_brick_is_postgres, true) if is_postgres
|
2524
2525
|
table_name_no_schema = singular_table_name.pluralize
|
2525
2526
|
if namespace && (idx = lookup_context.prefixes.index(table_name_no_schema))
|
2526
2527
|
lookup_context.prefixes[idx] = "#{namespace.name.underscore}/#{lookup_context.prefixes[idx]}"
|
@@ -2665,6 +2666,7 @@ class Object
|
|
2665
2666
|
@_lookup_context.instance_variable_set(:@_brick_model, real_model)
|
2666
2667
|
if created_obj.errors.empty?
|
2667
2668
|
instance_variable_set("@#{singular_table_name}".to_sym, created_obj)
|
2669
|
+
@_lookup_context.instance_variable_set(:@_brick_is_postgres, true) if is_postgres
|
2668
2670
|
index
|
2669
2671
|
render :index
|
2670
2672
|
else # Surface errors to the user in a flash message
|
data/lib/brick/rails/engine.rb
CHANGED
@@ -745,8 +745,10 @@ window.addEventListener(\"popstate\", linkSchemas);
|
|
745
745
|
hm_entry << if hm_assoc.macro == :has_one
|
746
746
|
'nil'
|
747
747
|
else # :has_many or :has_and_belongs_to_many
|
748
|
+
b_r_name = "b_r_#{assoc_name}_ct"
|
748
749
|
# Postgres column names are limited to 63 characters
|
749
|
-
|
750
|
+
b_r_name = b_r_name[0..62] if @_brick_is_postgres
|
751
|
+
"'#{b_r_name}'"
|
750
752
|
end
|
751
753
|
hm_entry << ", #{path_keys(hm_assoc, hm_fk_name, pk).inspect}]"
|
752
754
|
hms_columns << hm_entry
|
data/lib/brick/version_number.rb
CHANGED
@@ -70,7 +70,7 @@ module Brick
|
|
70
70
|
indexes = {} # Track index names to make sure things are unique
|
71
71
|
ar_base = Object.const_defined?(:ApplicationRecord) ? ApplicationRecord : Class.new(ActiveRecord::Base)
|
72
72
|
atrt_idx = 0 # ActionText::RichText unique index number
|
73
|
-
airtable_assoc_recids = Hash.new { |h, k| h[k] =
|
73
|
+
airtable_assoc_recids = Hash.new { |h, k| h[k] = {} }
|
74
74
|
@has_atrts = nil # Any ActionText::RichText present?
|
75
75
|
# Start by making entries for fringe models (those with no foreign keys).
|
76
76
|
# Continue layer by layer, creating entries for models that reference ones already done, until
|
@@ -168,8 +168,9 @@ module Brick
|
|
168
168
|
far_side_fk = associative_fks.find { |_k, fk1| fk1[:is_bt] && fk1[:assoc_name] != ::Brick::AirtableApiCaller.sane_name(field.first) }&.last
|
169
169
|
field.last.each do |nm_rec|
|
170
170
|
# Can trade out: hm_fk[:fk] for: near_side_fk[:inverse_table]
|
171
|
-
airtable_assoc_recids[assoc_table]
|
172
|
-
|
171
|
+
airtable_assoc_recids[assoc_table][[nm_rec[3..-1], obj['id'][3..-1]].sort.join] =
|
172
|
+
"#{hm_fk[:fk]}: #{hm_fk[:fk].singularize}_#{nm_rec[3..-1]}, " \
|
173
|
+
"#{far_side_fk[:assoc_name]}: #{far_side_fk[:inverse_table].singularize}_#{obj['id'][3..-1]}"
|
173
174
|
end
|
174
175
|
end
|
175
176
|
end
|
@@ -183,7 +184,7 @@ module Brick
|
|
183
184
|
end
|
184
185
|
is_empty = false
|
185
186
|
# For Airtable, take off the "rec___" prefix
|
186
|
-
pk_val = is_airtable ? airtable_id[3..-1] : brick_escape(obj.attributes_before_type_cast[pkey_cols.first])
|
187
|
+
pk_val = is_airtable ? airtable_id[3..-1] : brick_escape(orig_pk_val = obj.attributes_before_type_cast[pkey_cols.first])
|
187
188
|
var_name = "#{tbl.singularize.gsub('.', '__')}_#{pk_val}"
|
188
189
|
fk_vals = []
|
189
190
|
data = []
|
@@ -192,8 +193,8 @@ module Brick
|
|
192
193
|
# Skip primary key columns, unless they are part of a foreign key.
|
193
194
|
# (But always add all columns if it's Airtable!)
|
194
195
|
next if !(fk = fkeys.find { |assoc| col == assoc[:fk] }) &&
|
195
|
-
|
196
|
-
|
196
|
+
!is_airtable &&
|
197
|
+
pkey_cols.include?(col) && orig_pk_val.is_a?(Integer)
|
197
198
|
|
198
199
|
# Used to be: obj.send(col)
|
199
200
|
# (and with that it was possible to raise ActiveRecord::Encryption::Errors::Configuration...)
|
@@ -202,16 +203,13 @@ module Brick
|
|
202
203
|
val = val.to_s
|
203
204
|
end
|
204
205
|
if fk
|
205
|
-
inv_tbl = fk[:inverse_table].gsub('.', '__')
|
206
206
|
fk_val = if is_airtable
|
207
|
-
|
208
|
-
|
209
|
-
# Take off the "rec___" prefix
|
210
|
-
obj.attributes_before_type_cast[fk[:assoc_name]]&.first&.[](3..-1)
|
207
|
+
# The (3..-1) is to take off the "rec___" prefix
|
208
|
+
obj.attributes_before_type_cast[fk[:assoc_name]]&.first&.[](3..-1) if is_airtable
|
211
209
|
else
|
212
210
|
brick_escape(val)
|
213
211
|
end
|
214
|
-
fk_vals << "#{fk[:assoc_name]}: #{
|
212
|
+
fk_vals << "#{fk[:assoc_name]}: #{fk[:inverse_table].singularize.gsub('.', '__')}_#{fk_val}" if fk_val
|
215
213
|
else
|
216
214
|
val = case val.class.name
|
217
215
|
when 'ActiveStorage::Filename'
|
@@ -262,21 +260,34 @@ end\n"
|
|
262
260
|
end
|
263
261
|
updates.each { |update| seeds << update } # Anything that needs patching up after-the-fact
|
264
262
|
end
|
265
|
-
|
263
|
+
unless has_rows || klass_name.nil?
|
264
|
+
seeds << " # (Skipping #{klass_name} as it has no rows)\n"
|
265
|
+
end
|
266
266
|
end
|
267
267
|
done.concat(fringe)
|
268
268
|
chosen -= done
|
269
269
|
end
|
270
|
-
|
271
|
-
|
272
|
-
|
270
|
+
airtable_assocs_done = {}
|
271
|
+
airtable_assoc_recids.each do |table_name, assoc_pairs| # N:M links
|
272
|
+
# Make note of any other tables which have exactly duplicated data
|
273
|
+
dupes = airtable_assocs_done.select do |dupe_table, dupe_pairs|
|
274
|
+
dupe_table != table_name && assoc_pairs.length > 0 && assoc_pairs.length == dupe_pairs.length &&
|
275
|
+
dupe_pairs.all? { |pair_name, _v3| assoc_pairs.keys.include?(pair_name) }
|
276
|
+
end
|
277
|
+
seeds << " if ActiveRecord::Migration.table_exists?('#{table_name}')\n"
|
278
|
+
seeds << " # Duplicate data found in: #{dupes.keys.join(', ')}\n" unless dupes.empty?
|
279
|
+
seeds << " puts 'Seeding Airtable associations for #{table_name.camelize.singularize}'\n"
|
280
|
+
assoc_pairs.each do |_k2, pair_values|
|
281
|
+
seeds << "#{table_name.singularize.camelize}.create(#{pair_values})\n"
|
273
282
|
end
|
283
|
+
seeds << " end\n"
|
284
|
+
airtable_assocs_done[table_name] = assoc_pairs
|
274
285
|
end
|
275
286
|
|
276
287
|
File.open(seed_file_path, "w") { |f| f.write seeds }
|
277
288
|
stuck_counts = Hash.new { |h, k| h[k] = 0 }
|
278
289
|
chosen.each do |leftover|
|
279
|
-
puts "Can't do #{leftover.
|
290
|
+
puts "Can't do #{leftover.klass.name} because:\n #{stuck[leftover.table_name].map do |snag|
|
280
291
|
stuck_counts[snag.last[:inverse_table]] += 1
|
281
292
|
snag.last[:assoc_name]
|
282
293
|
end.join(', ')}"
|
@@ -299,8 +310,8 @@ end\n"
|
|
299
310
|
when String
|
300
311
|
ret = +''
|
301
312
|
val.each_char do |ch|
|
302
|
-
if ch < '0' || (ch > '9' && ch < 'A') || ch > 'Z'
|
303
|
-
ret << (ch == '_' ? ch : "x#{
|
313
|
+
if ch < '0' || (ch > '9' && ch < 'A') || (ch > 'Z' && ch < 'a') || ch == 'x' || ch > 'z'
|
314
|
+
ret << (ch == '_' ? ch : "x#{ch.unpack('H*')[0]}")
|
304
315
|
else
|
305
316
|
ret << ch
|
306
317
|
end
|
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.
|
4
|
+
version: 1.0.235
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lorin Thwaits
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|