brick 1.0.217 → 1.0.219
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brick/config.rb +0 -1
- data/lib/brick/extensions.rb +46 -47
- data/lib/brick/frameworks/rails/engine.rb +1 -1
- data/lib/brick/frameworks/rails/form_tags.rb +0 -2
- data/lib/brick/frameworks/rails.rb +3 -2
- data/lib/brick/reflect_tables.rb +2 -1
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +4 -0
- data/lib/generators/brick/migration_builder.rb +8 -3
- metadata +7 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78f81d0e3624f8e2b3e387067bf9239134339bdbff20c3386e21c9751e0658a3
|
4
|
+
data.tar.gz: 301504fb244c153b408addb0651778f1e80d970a19ca1b429e5954fb7deadffe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09d2f69ed9f7d8c7f786ab7910d425ef81a09219b1e9388ed7bf1b9369e389653388498f03142dd4f315e32dcc08680e1dbed133bfab648abd78d837019abce2'
|
7
|
+
data.tar.gz: f3f729e660db050dfa0bf970e62ec2b3be1b77a77759c46f6a11fda10d5623b862a926368237e06d60bf1433b3102a81ff17ef89189fffbed4a8bf637a6f451a
|
data/lib/brick/config.rb
CHANGED
@@ -243,7 +243,6 @@ module Brick
|
|
243
243
|
tables.each_with_object({}) do |v, s|
|
244
244
|
# If it's :constellation, or anything else in a hash, we'll take its value
|
245
245
|
# (and hopefully in this case that would be either a string or nil)
|
246
|
-
# binding.pry
|
247
246
|
dsl = ((v.last.is_a?(Symbol) && v.last) || v.last&.values&.last)
|
248
247
|
unless (dsl ||= '').is_a?(String) || dsl.is_a?(Symbol)
|
249
248
|
puts "Was really expecting #{v.first} / #{v.last.first&.first} / #{dsl} to be a string, " +
|
data/lib/brick/extensions.rb
CHANGED
@@ -691,7 +691,7 @@ module ActiveRecord
|
|
691
691
|
# ActiveRecord::StatementInvalid (TinyTds::Error: DBPROCESS is dead or not enabled)
|
692
692
|
# Relevant info here: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/402
|
693
693
|
is_api = params['_brick_is_api']
|
694
|
-
columns.each do |col|
|
694
|
+
columns[0..450].each do |col|
|
695
695
|
next if (col.type.nil? || col.type == :binary) && is_api
|
696
696
|
|
697
697
|
col_alias = " AS #{col.name}_" if (col_name = col.name) == 'class'
|
@@ -867,15 +867,6 @@ module ActiveRecord
|
|
867
867
|
end
|
868
868
|
v1 << id_for_tables[v.first].compact
|
869
869
|
end
|
870
|
-
# if k1.name == 'ActiveStorage::Attachment'
|
871
|
-
# binding.pry
|
872
|
-
# (@_brick_includes ||= {})[v1.first.first.to_s] = [v1.first[1..-1], 'blob']
|
873
|
-
# # x = 5
|
874
|
-
# # elsif k1.name == 'ActiveStorage::Blob'
|
875
|
-
# # binding.pry
|
876
|
-
# # (@_brick_includes ||= {})[v1.first.first.to_s] = v1[0..1]
|
877
|
-
# # # x = 5
|
878
|
-
# end
|
879
870
|
end
|
880
871
|
end
|
881
872
|
join_array.each do |assoc_name|
|
@@ -917,12 +908,7 @@ module ActiveRecord
|
|
917
908
|
through_sources.push(src_ref) unless src_ref.belongs_to?
|
918
909
|
from_clause = +"#{_br_quoted_name(through_sources.first.table_name)} br_t0"
|
919
910
|
# ActiveStorage will not get the correct count unless we do some extra filtering later
|
920
|
-
if Object.const_defined?('ActiveStorage') && through_sources.first.klass <= ::ActiveStorage::Attachment
|
921
|
-
# binding.pry
|
922
|
-
tbl_nm = 'br_t0'
|
923
|
-
# Need to somehow have this kind of an include in order to avoid an N+1 problem:
|
924
|
-
# .include(images_attachments: [blob: { variant_records: :blob }])
|
925
|
-
end
|
911
|
+
tbl_nm = 'br_t0' if Object.const_defined?('ActiveStorage') && through_sources.first.klass <= ::ActiveStorage::Attachment
|
926
912
|
fk_col = through_sources.shift.foreign_key
|
927
913
|
|
928
914
|
idx = 0
|
@@ -1094,7 +1080,16 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
|
|
1094
1080
|
self.order_values |= final_order_by # Same as: order!(*final_order_by)
|
1095
1081
|
end
|
1096
1082
|
# By default just 1000 rows
|
1097
|
-
|
1083
|
+
default_row_limit = if columns.length > 300
|
1084
|
+
50
|
1085
|
+
elsif columns.length > 200
|
1086
|
+
100
|
1087
|
+
elsif columns.length > 100
|
1088
|
+
250
|
1089
|
+
else
|
1090
|
+
1000
|
1091
|
+
end
|
1092
|
+
row_limit = params['_brick_limit'] || params['_brick_page_size'] || default_row_limit
|
1098
1093
|
offset = if (page = params['_brick_page']&.to_i)
|
1099
1094
|
page = 1 if page < 1
|
1100
1095
|
(page - 1) * row_limit.to_i
|
@@ -1125,12 +1120,8 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
|
|
1125
1120
|
end
|
1126
1121
|
|
1127
1122
|
# ActiveStorage compatibility
|
1128
|
-
if klass.name == 'ActiveStorage::Blob' && ::ActiveStorage::Blob.columns_hash.key?('service_name')
|
1129
|
-
|
1130
|
-
end
|
1131
|
-
if klass.name == 'ActiveStorage::Attachment' && ::ActiveStorage::Attachment.columns_hash.key?('blob_id')
|
1132
|
-
selects << 'blob_id'
|
1133
|
-
end
|
1123
|
+
selects << 'service_name' if klass.name == 'ActiveStorage::Blob' && ::ActiveStorage::Blob.columns_hash.key?('service_name')
|
1124
|
+
selects << 'blob_id' if klass.name == 'ActiveStorage::Attachment' && ::ActiveStorage::Attachment.columns_hash.key?('blob_id')
|
1134
1125
|
# Pay gem compatibility
|
1135
1126
|
selects << 'processor' if klass.name == 'Pay::Customer' && Pay::Customer.columns_hash.key?('processor')
|
1136
1127
|
selects << 'customer_id' if klass.name == 'Pay::Subscription' && Pay::Subscription.columns_hash.key?('customer_id')
|
@@ -1396,29 +1387,30 @@ end
|
|
1396
1387
|
end
|
1397
1388
|
base_module = if self < ActiveRecord::Migration || !self.name
|
1398
1389
|
brick_root || Object
|
1399
|
-
elsif split_self_name&.length&.> 1 # Classic mode
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1390
|
+
# elsif split_self_name&.length&.> 1 # Classic mode
|
1391
|
+
# begin
|
1392
|
+
# base = self
|
1393
|
+
# unless (base_goal = requested.split('::')[0..-2].join('::')).empty?
|
1394
|
+
# base = base.parent while base.name != base_goal && base != Object
|
1395
|
+
# end
|
1396
|
+
# binding.pry
|
1397
|
+
# return base._brick_const_missing(*args)
|
1398
|
+
|
1399
|
+
# rescue NameError # %%% Avoid the error "____ cannot be autoloaded from an anonymous class or module"
|
1400
|
+
# return self.const_get(args.first) if self.const_defined?(args.first)
|
1401
|
+
|
1402
|
+
# # unless self == (prnt = (respond_to?(:parent) ? parent : module_parent))
|
1403
|
+
# unless self == Object
|
1404
|
+
# begin
|
1405
|
+
# return Object._brick_const_missing(*args)
|
1406
|
+
|
1407
|
+
# rescue NameError
|
1408
|
+
# return Object.const_get(args.first) if Object.const_defined?(args.first)
|
1409
|
+
|
1410
|
+
# end
|
1411
|
+
# end
|
1412
|
+
# end
|
1413
|
+
# Object
|
1422
1414
|
else
|
1423
1415
|
sti_base = (::Brick.config.sti_namespace_prefixes&.fetch("::#{name}::#{requested}", nil) ||
|
1424
1416
|
::Brick.config.sti_namespace_prefixes&.fetch("::#{name}::", nil))&.constantize
|
@@ -1685,7 +1677,10 @@ class Object
|
|
1685
1677
|
schema_name = ::Brick.apartment_default_tenant
|
1686
1678
|
end
|
1687
1679
|
# Maybe, just maybe there's a database table that will satisfy this need
|
1688
|
-
matching = ::Brick.table_name_lookup&.fetch(
|
1680
|
+
matching = ::Brick.table_name_lookup&.fetch(
|
1681
|
+
base_module == Object ? class_name : "#{base_name}::#{class_name}",
|
1682
|
+
nil
|
1683
|
+
)
|
1689
1684
|
if (matching ||= [table_name, singular_table_name, plural_class_name, model_name, table_name.titleize].find { |m| relations.key?(schema_name ? "#{schema_name}.#{m}" : m) })
|
1690
1685
|
build_model_worker(schema_name, inheritable_name, model_name, singular_table_name, table_name, relations, matching, is_generator)
|
1691
1686
|
end
|
@@ -2936,6 +2931,10 @@ module Brick
|
|
2936
2931
|
end
|
2937
2932
|
hms = (relation = relations.fetch(primary_table, nil))&.fetch(:fks) { relation[:fks] = {} } unless is_class
|
2938
2933
|
|
2934
|
+
unless fk[4]
|
2935
|
+
puts "WARNING: Foreign key \"#{fk[5]}\" for \"#{"#{fk[0]}." if fk[0]}#{fk[1]}.#{fk[2]}\" does not reference a valid primary key or column(s) configured with a unique constraint."
|
2936
|
+
return
|
2937
|
+
end
|
2939
2938
|
unless (cnstr_name = fk[5])
|
2940
2939
|
# For any appended references (those that come from config), arrive upon a definitely unique constraint name
|
2941
2940
|
pri_tbl = is_class ? fk[4][:class].underscore : pri_tbl
|
@@ -582,7 +582,7 @@ window.addEventListener(\"popstate\", linkSchemas);
|
|
582
582
|
alias :_brick_lookup_context :lookup_context
|
583
583
|
def lookup_context(*args)
|
584
584
|
ret = _brick_lookup_context(*args)
|
585
|
-
@_lookup_context.instance_variable_set(:@_brick_req_params, params) if self.class < AbstractController::Base && params
|
585
|
+
@_lookup_context.instance_variable_set(:@_brick_req_params, params) if self.class < AbstractController::Base && request && params.present?
|
586
586
|
ret
|
587
587
|
end
|
588
588
|
end
|
@@ -93,7 +93,6 @@ module Brick::Rails::FormTags
|
|
93
93
|
# TinyTds::Error: Adaptive Server connection timed out
|
94
94
|
# (After restarting the server it worked fine again.)
|
95
95
|
row_count = 0
|
96
|
-
# binding.pry
|
97
96
|
# if @_brick_join_array&.include?()
|
98
97
|
enumerator = relation.each # Runs the SQL query
|
99
98
|
# Add proxied info for @_brick_includes
|
@@ -118,7 +117,6 @@ module Brick::Rails::FormTags
|
|
118
117
|
(classes ||= []) << 'right' if val.is_a?(Numeric) && !bt
|
119
118
|
out << " class=\"#{classes.join(' ')}\"" if classes&.present?
|
120
119
|
out << '>'
|
121
|
-
# binding.pry if col_name == 'event_image_attachment' && obj.id == 6
|
122
120
|
if bt
|
123
121
|
if bt[2] && obj.respond_to?(poly_id_col = "#{bt.first}_id") # Polymorphic?
|
124
122
|
if (poly_id = obj.send(poly_id_col))
|
@@ -139,9 +139,10 @@ erDiagram
|
|
139
139
|
@_brick_bt_descrip&.each do |bt|
|
140
140
|
bt_class = bt[1].first.first
|
141
141
|
callbacks[bt_name = bt_class.name.split('::').last] = bt_class
|
142
|
-
|
142
|
+
# Used to have: &.inverse_of before &.macro
|
143
|
+
is_has_one = #{model.name}.reflect_on_association(bt.first)&.macro == :has_one ||
|
143
144
|
::Brick.config.has_ones&.fetch('#{model.name}', nil)&.key?(bt.first.to_s)
|
144
|
-
%> <%= \"#{model_short_name} #\{is_has_one ? '
|
145
|
+
%> <%= \"#{model_short_name} #\{is_has_one ? '||--o|' : '}o--||'} #\{bt_name} : \\\"#\{
|
145
146
|
bt_underscored = bt[1].first.first.name.underscore.singularize
|
146
147
|
bt.first unless bt.first.to_s == bt_underscored.split('/').last # Was: bt_underscored.tr('/', '_')
|
147
148
|
}\\\"\".html_safe %>
|
data/lib/brick/reflect_tables.rb
CHANGED
@@ -3,6 +3,7 @@ module Brick
|
|
3
3
|
# This is done separately so that during testing it can be called right after a migration
|
4
4
|
# in order to make sure everything is good.
|
5
5
|
def reflect_tables
|
6
|
+
require 'brick/join_array'
|
6
7
|
return unless ::Brick.config.mode == :on
|
7
8
|
|
8
9
|
# return if ActiveRecord::Base.connection.current_database == 'postgres'
|
@@ -417,7 +418,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
417
418
|
puts "WARNING: #{message_start} already exists.\n Will set up to auto-create model #{v[:class_name]} for table #{k}."
|
418
419
|
end
|
419
420
|
# Track anything that's out-of-the-ordinary
|
420
|
-
table_name_lookup[v[:class_name]] = k unless v[:class_name].underscore.pluralize == k
|
421
|
+
table_name_lookup[v[:class_name]] = k.split('.').last unless v[:class_name].underscore.pluralize == k
|
421
422
|
end
|
422
423
|
::Brick.load_additional_references if ::Brick.initializer_loaded
|
423
424
|
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -189,6 +189,7 @@ module Brick
|
|
189
189
|
has_uppers = name =~ /[A-Z]+/
|
190
190
|
has_lowers = name =~ /[a-z]+/
|
191
191
|
name.downcase! if has_uppers && action == :downcase
|
192
|
+
name = "Z#{name}" if name.start_with?('_') # Entity Framework creates a table named __EFMigrationsHistory
|
192
193
|
if name.include?(' ')
|
193
194
|
# All uppers or all lowers?
|
194
195
|
if !has_uppers || !has_lowers
|
@@ -197,6 +198,9 @@ module Brick
|
|
197
198
|
name.tr(' ', '')
|
198
199
|
end
|
199
200
|
else
|
201
|
+
# .NET has a background job processor called "Hangfire" which creates several tables,
|
202
|
+
# two of which get named the same as core Ruby classes -- "Set" and "Hash".
|
203
|
+
name = "#{name}x" if ['Hash', 'Set', 'hash', 'set'].include?(name)
|
200
204
|
action == :underscore ? name.underscore : name
|
201
205
|
end
|
202
206
|
end
|
@@ -363,8 +363,8 @@ module Brick
|
|
363
363
|
if (idx_name = ActiveRecord::Base.connection.index_name(tbl, {column: col})).length > 63
|
364
364
|
# Try to find a shorter name that hasn't been used yet
|
365
365
|
unless indexes.key?(shorter = idx_name[0..62]) ||
|
366
|
-
|
367
|
-
|
366
|
+
indexes.key?(shorter = idx_name.tr('_', '')[0..62]) ||
|
367
|
+
indexes.key?(shorter = idx_name.tr('aeio', '')[0..62])
|
368
368
|
puts "Unable to easily find unique name for index #{idx_name} that is shorter than 64 characters,"
|
369
369
|
puts "so have resorted to this GUID-based identifier: #{shorter = "#{tbl[0..25]}_#{::SecureRandom.uuid}"}."
|
370
370
|
end
|
@@ -379,7 +379,12 @@ module Brick
|
|
379
379
|
rescue NameError => e
|
380
380
|
primary_key = ::Brick.ar_base.primary_key
|
381
381
|
end
|
382
|
-
|
382
|
+
need_pk_specifics = (primary_key != ::Brick.ar_base.primary_key)
|
383
|
+
fk_stuff = if need_pk_specifics || to_table != ":#{fk[:assoc_name].pluralize}"
|
384
|
+
", foreign_key: { to_table: #{to_table}#{", primary_key: :#{primary_key}" if need_pk_specifics} }"
|
385
|
+
else
|
386
|
+
", foreign_key: true"
|
387
|
+
end
|
383
388
|
mig << " t.references :#{fk[:assoc_name]}#{suffix}#{fk_stuff}\n"
|
384
389
|
end
|
385
390
|
else
|
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.219
|
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-
|
11
|
+
date: 2024-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -126,16 +126,16 @@ dependencies:
|
|
126
126
|
name: rspec-rails
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - "
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: rubocop
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,20 +164,6 @@ dependencies:
|
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: 1.42.0
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: rswag-ui
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - ">="
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '0'
|
174
|
-
type: :development
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - ">="
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: '0'
|
181
167
|
- !ruby/object:Gem::Dependency
|
182
168
|
name: pg
|
183
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -271,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
257
|
- !ruby/object:Gem::Version
|
272
258
|
version: 1.3.6
|
273
259
|
requirements: []
|
274
|
-
rubygems_version: 3.
|
260
|
+
rubygems_version: 3.3.26
|
275
261
|
signing_key:
|
276
262
|
specification_version: 4
|
277
263
|
summary: Create a Rails app from data alone
|