brick 1.0.242 → 1.0.243
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/rails/crosstab.brk +0 -0
- data/lib/brick/rails.rb +4 -3
- data/lib/brick/reflect_tables.rb +10 -7
- data/lib/brick/version_number.rb +1 -1
- data/lib/generators/brick/install_generator.rb +1 -1
- data/lib/generators/brick/migrations_builder.rb +15 -11
- data/lib/generators/brick/seeds_builder.rb +57 -20
- 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: 00e544ab1972840fa5a6e9c3261fb65ed0591f677ad1cb9c1992dd7447bc3e06
|
|
4
|
+
data.tar.gz: 54bdcb8c8834736a98b331e494011e798a9d3b5bbd912113a73391a7a8bf3e72
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 51e3caffcc7e19b44ca7dba5ac75454a03a5eba7ee79c862e5288542d6695b47bdbeb1000fcc257e5d251c4b1e84f82420081367ad9b8e06446c699b5fd8bf4f
|
|
7
|
+
data.tar.gz: 8a184a598c46f8162770a5b91b496cb56fc12d1ccfa6598185922a4a038e47ba3168bba24c8e9ccac764c6625a3bf309a9a5ab5022600ec883579630bbb7fd69
|
|
Binary file
|
data/lib/brick/rails.rb
CHANGED
|
@@ -80,7 +80,7 @@ module ::Brick::Rails
|
|
|
80
80
|
end
|
|
81
81
|
end
|
|
82
82
|
|
|
83
|
-
def display_binary(val, max_size = 100_000)
|
|
83
|
+
def display_binary(val, max_size = 100_000, no_escaped_html = nil)
|
|
84
84
|
return unless val
|
|
85
85
|
|
|
86
86
|
@image_signatures ||= { (+"\xFF\xD8\xFF\xEE").force_encoding('ASCII-8BIT') => 'jpeg',
|
|
@@ -111,7 +111,8 @@ module ::Brick::Rails
|
|
|
111
111
|
val.length < max_size
|
|
112
112
|
"<img src=\"data:image/#{signature.last};base64,#{Base64.encode64(val)}\">"
|
|
113
113
|
else
|
|
114
|
-
"
|
|
114
|
+
descrip = "#{signature ? "#{signature} image" : 'Binary'}, #{val.length} bytes"
|
|
115
|
+
no_escaped_html ? "< #{descrip} >" : "< #{descrip} >"
|
|
115
116
|
end
|
|
116
117
|
end
|
|
117
118
|
|
|
@@ -222,7 +223,7 @@ erDiagram
|
|
|
222
223
|
'(hidden)'
|
|
223
224
|
else
|
|
224
225
|
if val.is_a?(String)
|
|
225
|
-
return ::Brick::Rails.display_binary(val) unless (val_utf8 = val.dup.force_encoding('UTF-8')).valid_encoding?
|
|
226
|
+
return ::Brick::Rails.display_binary(val, 100_000, is_xml == false) unless (val_utf8 = val.dup.force_encoding('UTF-8')).valid_encoding?
|
|
226
227
|
|
|
227
228
|
val = val_utf8.strip
|
|
228
229
|
return CGI.escapeHTML(val) if is_xml
|
data/lib/brick/reflect_tables.rb
CHANGED
|
@@ -553,7 +553,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
|
553
553
|
end
|
|
554
554
|
s[rel.first] = perms
|
|
555
555
|
end
|
|
556
|
-
else # or there are specific permissions for each resource, so find the matching indexes
|
|
556
|
+
else # or there are specific permissions for each resource, so find the matching indexes.
|
|
557
557
|
client = Elastic::Transport::Client.new
|
|
558
558
|
::Brick.elasticsearch_existings.each_with_object({}) do |index, s|
|
|
559
559
|
this_access = access.is_a?(String) ? access : access[index.first] || '' # Look up permissions from above
|
|
@@ -625,13 +625,16 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
|
625
625
|
end
|
|
626
626
|
|
|
627
627
|
def ar_tables
|
|
628
|
-
ar_smtn = if ActiveRecord::Base.respond_to?(:schema_migrations_table_name)
|
|
629
|
-
ActiveRecord::Base.schema_migrations_table_name
|
|
630
|
-
else
|
|
631
|
-
'schema_migrations'
|
|
632
|
-
end
|
|
633
628
|
ar_imtn = ActiveRecord.version >= ::Gem::Version.new('5.0') ? ActiveRecord::Base.internal_metadata_table_name : 'ar_internal_metadata'
|
|
634
|
-
[
|
|
629
|
+
[self._schema_migrations_table_name, ar_imtn]
|
|
630
|
+
end
|
|
631
|
+
|
|
632
|
+
def _schema_migrations_table_name
|
|
633
|
+
if ActiveRecord::Base.respond_to?(:schema_migrations_table_name)
|
|
634
|
+
ActiveRecord::Base.schema_migrations_table_name
|
|
635
|
+
else
|
|
636
|
+
'schema_migrations'
|
|
637
|
+
end
|
|
635
638
|
end
|
|
636
639
|
end
|
|
637
640
|
end
|
data/lib/brick/version_number.rb
CHANGED
|
@@ -150,7 +150,7 @@ module Brick
|
|
|
150
150
|
when 1
|
|
151
151
|
".
|
|
152
152
|
# # Here is a possible polymorphic association that has been auto-identified for the #{current_db} database:
|
|
153
|
-
# Brick.polymorphics = { #{
|
|
153
|
+
# Brick.polymorphics = { #{possible_polymorphics.first} }"
|
|
154
154
|
|
|
155
155
|
else
|
|
156
156
|
".
|
|
@@ -248,20 +248,24 @@ module Brick
|
|
|
248
248
|
}:"
|
|
249
249
|
pp stuck_sorted[0..4]
|
|
250
250
|
elsif do_schema_migrations # Successful, and now we can update the schema_migrations table accordingly
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
251
|
+
smtn = ::Brick._schema_migrations_table_name
|
|
252
|
+
if ActiveRecord::Migration.table_exists?(smtn)
|
|
253
|
+
# Remove to_delete - to_create
|
|
254
|
+
if ((versions_to_delete_or_append ||= []) - versions_to_create).present? && is_delete_versions
|
|
255
|
+
ActiveRecord::Base.execute_sql("DELETE FROM #{
|
|
256
|
+
smtn} WHERE version IN (#{
|
|
257
|
+
(versions_to_delete_or_append - versions_to_create).map { |vtd| "'#{vtd}'" }.join(', ')}
|
|
258
|
+
)")
|
|
259
|
+
end
|
|
260
|
+
else
|
|
261
|
+
ActiveRecord::Base.connection.create_table(smtn, primary_key: 'version') do |t|
|
|
262
|
+
t.string :verison
|
|
263
|
+
end
|
|
260
264
|
end
|
|
261
265
|
# Add to_create - to_delete
|
|
262
|
-
if is_insert_versions && ((versions_to_create ||= []) - versions_to_delete_or_append).present?
|
|
266
|
+
if is_insert_versions && (versions_to_delete_or_append ||= []) && ((versions_to_create ||= []) - versions_to_delete_or_append).present?
|
|
263
267
|
ActiveRecord::Base.execute_sql("INSERT INTO #{
|
|
264
|
-
|
|
268
|
+
smtn} (version) VALUES #{
|
|
265
269
|
(versions_to_create - versions_to_delete_or_append).map { |vtc| "('#{vtc}')" }.join(', ')
|
|
266
270
|
}")
|
|
267
271
|
end
|
|
@@ -13,8 +13,8 @@ module Brick
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def generate_seeds(relations = nil)
|
|
16
|
-
if File.exist?(seed_file_path = "#{::Rails.root}/db/
|
|
17
|
-
puts "WARNING: seeds file #{seed_file_path} appears to already be present.\nOverwrite?"
|
|
16
|
+
if File.exist?((seed_file_path = "#{::Rails.root}/db/seed") + 's.rb')
|
|
17
|
+
puts "WARNING: seeds file #{seed_file_path}s.rb appears to already be present.\nOverwrite?"
|
|
18
18
|
return unless gets_list(list: ['No', 'Yes']) == 'Yes'
|
|
19
19
|
|
|
20
20
|
puts "\n"
|
|
@@ -56,11 +56,15 @@ module Brick
|
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
|
-
|
|
59
|
+
batch_num = 1
|
|
60
|
+
seeds_file = File.open("#{seed_file_path}s.rb", 'w')
|
|
61
|
+
seeds_len = lines_len = 0
|
|
62
|
+
seeds_file.write('# Seeds file for ')
|
|
63
|
+
seed_rows = nil
|
|
60
64
|
if (arbc = ActiveRecord::Base.connection).respond_to?(:current_database) # SQLite3 can't do this!
|
|
61
|
-
|
|
65
|
+
seeds_file.write("#{arbc.current_database}:\n")
|
|
62
66
|
elsif (filename = arbc.instance_variable_get(:@connection_parameters)&.fetch(:database, nil))
|
|
63
|
-
|
|
67
|
+
seeds_file.write("#{filename}:\n")
|
|
64
68
|
end
|
|
65
69
|
done = []
|
|
66
70
|
fks = {}
|
|
@@ -93,7 +97,6 @@ module Brick
|
|
|
93
97
|
end
|
|
94
98
|
end
|
|
95
99
|
).present?
|
|
96
|
-
seeds << "\n"
|
|
97
100
|
unless is_airtable
|
|
98
101
|
# Search through the fringe to see if we should bump special dependent classes forward to the next fringe.
|
|
99
102
|
# (Currently only ActiveStorage::Attachment if there's also an ActiveStorage::VariantRecord in the same
|
|
@@ -150,8 +153,11 @@ module Brick
|
|
|
150
153
|
::Brick::AirtableApiCaller.https_get("https://api.airtable.com/v0/#{airtable_table.base_id}/#{airtable_table.id}").fetch('records', nil)
|
|
151
154
|
end
|
|
152
155
|
else
|
|
153
|
-
|
|
156
|
+
# Must convert to a symbol when doing ORDER BY due to this ActiveRecord nuance:
|
|
157
|
+
# https://github.com/rails/rails/issues/2601
|
|
158
|
+
klass.order(*pkey_cols.map(&:to_sym)) unless relation[:pkey].empty?
|
|
154
159
|
end
|
|
160
|
+
seed_rows = +''
|
|
155
161
|
collection&.each do |obj|
|
|
156
162
|
if is_airtable
|
|
157
163
|
fields = obj['fields'].each_with_object({}) do |field, s|
|
|
@@ -177,11 +183,13 @@ module Brick
|
|
|
177
183
|
end
|
|
178
184
|
unless has_rows
|
|
179
185
|
has_rows = true
|
|
180
|
-
|
|
186
|
+
seed_rows << "\n puts 'Seeding: #{klass_name}'\n"
|
|
187
|
+
puts "Preparing: #{klass_name} — #{batch_num}"
|
|
181
188
|
end
|
|
182
189
|
is_empty = false
|
|
183
190
|
# For Airtable, take off the "rec___" prefix
|
|
184
191
|
pk_val = is_airtable ? airtable_id[3..-1] : brick_escape(orig_pk_val = obj.attributes_before_type_cast[pkey_cols.first])
|
|
192
|
+
pk_val = -pk_val if pk_val.is_a?(Numeric) && pk_val < 0
|
|
185
193
|
var_name = "#{tbl.singularize.gsub('.', '__')}_#{pk_val}"
|
|
186
194
|
fk_vals = []
|
|
187
195
|
data = []
|
|
@@ -196,8 +204,12 @@ module Brick
|
|
|
196
204
|
# Used to be: obj.send(col)
|
|
197
205
|
# (and with that it was possible to raise ActiveRecord::Encryption::Errors::Configuration...)
|
|
198
206
|
# %%% should test further and see if that is possible with this code!)
|
|
199
|
-
if (val = obj.attributes_before_type_cast[col])
|
|
200
|
-
val
|
|
207
|
+
if (val = obj.attributes_before_type_cast[col])
|
|
208
|
+
if (val.is_a?(Time) || val.is_a?(Date))
|
|
209
|
+
val = val.to_s
|
|
210
|
+
elsif val.is_a?(Numeric)
|
|
211
|
+
val = -val if val < 0
|
|
212
|
+
end
|
|
201
213
|
end
|
|
202
214
|
if fk
|
|
203
215
|
fk_val = if is_airtable
|
|
@@ -240,12 +252,12 @@ module Brick
|
|
|
240
252
|
record_id = data.find { |d| d.start_with?('record_id: ') }[11..-1]
|
|
241
253
|
data.reject! { |d| d.start_with?('record_id: ') || d.start_with?('created_at: ') || d.start_with?('updated_at: ') }
|
|
242
254
|
data << "record_id: atrt_ids[[#{record_id}, '#{record_class}']]"
|
|
243
|
-
|
|
255
|
+
seed_rows << "#{var_name} = #{klass_name}.find_or_create_by(#{(fk_vals + data).join(', ')}) do |asa|
|
|
244
256
|
asa.created_at = DateTime.parse('#{obj.created_at.inspect}')#{"
|
|
245
257
|
asa.updated_at = DateTime.parse('#{obj.updated_at.inspect}')" if obj.respond_to?(:updated_at)}
|
|
246
258
|
end\n"
|
|
247
259
|
else
|
|
248
|
-
|
|
260
|
+
seed_rows << "#{var_name} = #{klass_name}.create(#{(fk_vals + data).join(', ')})\n"
|
|
249
261
|
unless is_airtable
|
|
250
262
|
klass.attachment_reflections.each do |k, v|
|
|
251
263
|
if (attached = obj.send(k))
|
|
@@ -255,10 +267,24 @@ end\n"
|
|
|
255
267
|
end if klass.respond_to?(:attachment_reflections)
|
|
256
268
|
end
|
|
257
269
|
end
|
|
258
|
-
updates.each { |update|
|
|
270
|
+
updates.each { |update| seed_rows << update } # Anything that needs patching up after-the-fact
|
|
271
|
+
seeds_file.write(seed_rows)
|
|
272
|
+
seeds_len += seed_rows.length
|
|
273
|
+
if (lines_len += 1) > 50000 || # More than 50K rows? ...
|
|
274
|
+
seeds_len > 98000000 # ... or 100 megs total? ...
|
|
275
|
+
# ... then break it into multiple files
|
|
276
|
+
seeds_file.close
|
|
277
|
+
if batch_num == 1 # First one? Then rename file to seedsx_0001.rb
|
|
278
|
+
File.rename("#{seed_file_path}s.rb", "#{seed_file_path}x_0001.rb")
|
|
279
|
+
end
|
|
280
|
+
seeds_file = File.open("#{seed_file_path}x_#{(batch_num += 1).to_s.rjust(4, '0')}.rb", 'w')
|
|
281
|
+
puts "=== File #{batch_num} ===\n"
|
|
282
|
+
seeds_len = lines_len = 0
|
|
283
|
+
end
|
|
284
|
+
seed_rows = +''
|
|
259
285
|
end
|
|
260
286
|
unless has_rows || klass_name.nil?
|
|
261
|
-
|
|
287
|
+
seeds_file.write(" # (Skipping #{klass_name} as it has no rows)\n")
|
|
262
288
|
end
|
|
263
289
|
end
|
|
264
290
|
done.concat(fringe)
|
|
@@ -271,17 +297,28 @@ end\n"
|
|
|
271
297
|
dupe_table != table_name && assoc_pairs.length > 0 && assoc_pairs.length == dupe_pairs.length &&
|
|
272
298
|
dupe_pairs.all? { |pair_name, _v3| assoc_pairs.keys.include?(pair_name) }
|
|
273
299
|
end
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
300
|
+
seed_rows << " if ActiveRecord::Migration.table_exists?('#{table_name}')\n"
|
|
301
|
+
seed_rows << " # Duplicate data found in: #{dupes.keys.join(', ')}\n" unless dupes.empty?
|
|
302
|
+
seed_rows << " puts 'Seeding Airtable associations for #{table_name.camelize.singularize}'\n"
|
|
277
303
|
assoc_pairs.each do |_k2, pair_values|
|
|
278
|
-
|
|
304
|
+
seed_rows << "#{table_name.singularize.camelize}.create(#{pair_values})\n"
|
|
279
305
|
end
|
|
280
|
-
|
|
306
|
+
seed_rows << " end\n"
|
|
281
307
|
airtable_assocs_done[table_name] = assoc_pairs
|
|
282
308
|
end
|
|
309
|
+
seeds_file.write(seed_rows) unless seed_rows.blank?
|
|
310
|
+
|
|
311
|
+
if batch_num > 1
|
|
312
|
+
seeds_file.close
|
|
313
|
+
|
|
314
|
+
# Create a main seeds file in place of the one that was renamed out
|
|
315
|
+
File.open("#{seed_file_path}s.rb", 'w') do |main_seeds_file|
|
|
316
|
+
(1..batch_num).each do |num|
|
|
317
|
+
main_seeds_file.write("load 'db/seedx_#{num.to_s.rjust(4, '0')}.rb'\n")
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
end
|
|
283
321
|
|
|
284
|
-
File.open(seed_file_path, "w") { |f| f.write seeds }
|
|
285
322
|
stuck_counts = Hash.new { |h, k| h[k] = 0 }
|
|
286
323
|
chosen.each do |leftover|
|
|
287
324
|
puts "Can't do #{leftover.klass.name} because:\n #{stuck[leftover.table_name].map do |snag|
|
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.243
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lorin Thwaits
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-04-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|