brick 1.0.231 → 1.0.232

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b36099e75ec27d9fa4522da84f319af2fb1c98997c629a5246c88a1e6ddcbe3
4
- data.tar.gz: '089a28701ee39956f0447801c70f9f044aefd06638ab575f3a6307690746eca4'
3
+ metadata.gz: ec8b0390d538c25946d68d51b1394875a02203694bc2d28928df1fd63987f40f
4
+ data.tar.gz: de49f7332e2a08a21a22e92cbac5c9668079551de6ba36ff45fd02dcac9102db
5
5
  SHA512:
6
- metadata.gz: 0b8ed54764ce53a403f47d0a42ff578445e9a4d03e60f973264bbafb07a8c6a7af8daf15736ceb172472d2919817d14673163b40fdfffbdd87d4511e759c3747
7
- data.tar.gz: '0326081b5c6e69ab4f7a6fe94784c73996117db6c715e3b158bc0cde744245e213e53a50e5b5d01bcd44b6cb24d55022548c2a1c83a53de5ccbca04f23c66b65'
6
+ metadata.gz: 7e77492d4d72836a829f9e073eaa14cb1f2c676aefbd053b0466e43b0d0f79141ec661bb38a377391d96711338f9bab5535ee52d51fc90964013ea042219cddc
7
+ data.tar.gz: '099332256ecadb0948c329dc8a3b06c1b460da5de41e8f183fc5dd937651edd57895b2d3c57399455af5732bab7172e6e88435560cd2d6b1d2e6f42eafefe71d'
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 231
8
+ TINY = 232
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
@@ -15,6 +15,7 @@ You need only #{usage == :migrations ? 'this scope:' : "these three scopes:
15
15
 
16
16
  Please provide your Airtable PAT:"
17
17
  pat = gets_password
18
+ pat = ENV['AIRTABLE_PAT'] if pat.blank?
18
19
  require 'net/http'
19
20
  # Generate a list of bases that can be chosen
20
21
  bases = https_get('https://api.airtable.com/v0/meta/bases', pat)
@@ -52,12 +53,12 @@ Please provide your Airtable PAT:"
52
53
  # Queue up to build associative table with two foreign keys
53
54
  camelized = (assoc_name = "#{tbl_name}_#{col_name}_#{frn_tbl}").camelize
54
55
  if associatives.keys.any? { |a| a.camelize == camelized }
55
- puts "Strangely have found two columns in \"#{table.name}\" with a name similar to \"#{col_name}\". Skipping this to avoid a conflict."
56
+ puts "Strangely have found two columns in \"#{table.name}\" with a name similar to \"#{col_name}\". Skipping one to avoid a conflict."
56
57
  next
57
58
 
58
59
  end
59
60
  associatives[assoc_name] = [col_name, frn_tbl, tbl_name]
60
- fks << [assoc_name, frn_tbl, frn_tbl, col_name.underscore, tbl_name]
61
+ fks << [assoc_name, frn_tbl, tbl_name, col_name.underscore, tbl_name]
61
62
  end
62
63
  end
63
64
  else
@@ -94,18 +95,15 @@ Please provide your Airtable PAT:"
94
95
  }
95
96
  end
96
97
  associatives.each do |k, v|
97
- pri_pk_col = relations[v[1]][:pkey]&.first&.last&.first
98
- frn_pk_col = relations[v[2]][:pkey]&.first&.last&.first
99
98
  pri_fk_name = "#{v[1]}_id"
100
- frn_fk_name = (frn_fk_name == pri_fk_name) ?
101
- "#{v[2]}_2_id" # Self-referencing N:M
102
- : "#{v[2]}_id" # Standard N:M
99
+ frn_fk_base = (v[1] == v[2]) ? "#{v[2]}_2" : v[2] # Accommodates self-referencing N:Ms
100
+ frn_fk_name = "#{frn_fk_base}_id"
103
101
  relations[k] = {
104
102
  pkey: { "#{k}_pkey" => ['id'] },
105
103
  cols: { 'id' => ['integer', nil, false, false] }
106
104
  }
107
- fks << [v[1], pri_fk_name, k, pri_fk_name.underscore]
108
- fks << [v[2], frn_fk_name, k, frn_fk_name.underscore]
105
+ fks << [v[1], pri_fk_name, k, v[0].underscore]
106
+ fks << [v[2], frn_fk_name, k, frn_fk_base.underscore]
109
107
  end
110
108
  fk_idx = 0
111
109
  fks.each do |pri_tbl, fk_col, frn_tbl, airtable_col, assoc_tbl|
@@ -161,14 +161,15 @@ module Brick
161
161
  if relation[:cols].keys.include?(col_name = ::Brick::AirtableApiCaller.sane_name(field.first))
162
162
  s[col_name] = obj['fields'][field.first]
163
163
  else # Consider N:M fks
164
- nm_fk = relation[:fks].find do |_k, fk1|
165
- relations[fk1[:assoc_tbl]]&.fetch(:fks, nil)&.find { |_k, fk2| fk2[:assoc_name] == col_name }
166
- end&.last
167
- if (t_table = nm_fk&.fetch(:inverse_table, nil))
164
+ hm_fk = relation[:fks].find { |_k, fk1| !fk1[:is_bt] && fk1[:assoc_name] == ::Brick::AirtableApiCaller.sane_name(field.first) }&.last
165
+ if (t_table = hm_fk&.fetch(:inverse_table, nil))
166
+ associative_fks = relations[hm_fk&.fetch(:inverse_table, nil)][:fks]
167
+ # near_side_fk = associative_fks.find { |_k, fk1| fk1[:is_bt] && fk1[:assoc_name] == ::Brick::AirtableApiCaller.sane_name(field.first) }&.last
168
+ far_side_fk = associative_fks.find { |_k, fk1| fk1[:is_bt] && fk1[:assoc_name] != ::Brick::AirtableApiCaller.sane_name(field.first) }&.last
168
169
  field.last.each do |nm_rec|
169
- nm_fk_col = nm_fk[:assoc_tbl]
170
- airtable_assoc_recids[t_table] << "#{nm_fk[:fk]}: #{nm_fk[:fk].singularize}_#{obj['id'][3..-1]}, " \
171
- "#{nm_fk_col}: #{nm_fk_col.singularize}_#{nm_rec[3..-1]}"
170
+ # Can trade out: hm_fk[:fk] for: near_side_fk[:inverse_table]
171
+ airtable_assoc_recids[t_table] << "#{hm_fk[:fk]}: #{hm_fk[:fk].singularize}_#{nm_rec[3..-1]}, " \
172
+ "#{far_side_fk[:assoc_name]}: #{far_side_fk[:inverse_table].singularize}_#{obj['id'][3..-1]}"
172
173
  end
173
174
  end
174
175
  end
@@ -183,7 +184,7 @@ module Brick
183
184
  is_empty = false
184
185
  # For Airtable, take off the "rec___" prefix
185
186
  pk_val = is_airtable ? airtable_id[3..-1] : brick_escape(obj.attributes_before_type_cast[pkey_cols.first])
186
- var_name = "#{tbl.gsub('.', '__')}_#{pk_val}"
187
+ var_name = "#{tbl.singularize.gsub('.', '__')}_#{pk_val}"
187
188
  fk_vals = []
188
189
  data = []
189
190
  updates = []
@@ -203,6 +204,7 @@ module Brick
203
204
  if fk
204
205
  inv_tbl = fk[:inverse_table].gsub('.', '__')
205
206
  fk_val = if is_airtable
207
+ inv_tbl = inv_tbl.singularize
206
208
  # Used to be: fk[:airtable_col]
207
209
  # Take off the "rec___" prefix
208
210
  obj.attributes_before_type_cast[fk[:assoc_name]]&.first&.[](3..-1)
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.231
4
+ version: 1.0.232
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-12 00:00:00.000000000 Z
11
+ date: 2025-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord