brick 1.0.155 → 1.0.156

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: fceffbcf863eb9c03b64a0cb4420a33ded5eb7f3908b40b263a345ae9bf5c164
4
- data.tar.gz: 81f9f96bd1463b8b7e7736ed4716bcf78609bae27485af4de15cb23ae12e27ee
3
+ metadata.gz: e001ce24602c8fef817c24a0eb88e014e990d98828474acd66d868b50dd68692
4
+ data.tar.gz: 8378593754641ffc86059672fe6148ba767d91a867361b21ec8377a82903af6b
5
5
  SHA512:
6
- metadata.gz: c41a59ca62c80012166225b0cf80505b81fe57ccdfeb92c4add7f227d6d4a9cc0c664aaf5209c31dabd54c3e471fe140fd3dc75bf1441bbed0fca67e9801ffd9
7
- data.tar.gz: 83c874515b230b0b607da32e41366284b15e830ebd7f7022fb318db412fef94a0339495de54c9ab0277425af2635cc8ab235675074cbb50f703082979ebd28b5
6
+ metadata.gz: 84fa7d9831dfca26b9b08ef46bd852c3d4f96e1f8420ff086526f97964090b3f95d71b5d66d9ff7ba47ec5f74e50938c9714731d21d0c59ac2365305ab8826bc
7
+ data.tar.gz: cf790bbb66852142fe07cb1619517043dc3ef8c47b0f020b22bc635cd902fface9b52631507b2fdd9520b604c98eae00b58a1bad29ace185c8d342e79e99a062
@@ -1464,7 +1464,6 @@ class Object
1464
1464
  rescue StandardError => ex
1465
1465
  ::ActiveRecord::Base
1466
1466
  end))
1467
-
1468
1467
  end
1469
1468
  hmts = nil
1470
1469
  code = +"class #{full_name} < #{base_model.name}\n"
@@ -1489,6 +1488,10 @@ class Object
1489
1488
  end
1490
1489
  # Accommodate singular or camel-cased table names such as "order_detail" or "OrderDetails"
1491
1490
  code << " self.table_name = '#{self.table_name = matching}'\n" if inheritable_name || self.table_name != matching
1491
+ if (inh_col = ::Brick.config.sti_type_column.find { |_k, v| v.include?(matching) }&.first)
1492
+ self.inheritance_column = inh_col
1493
+ code << " self.inheritance_column = '#{inh_col}'\n"
1494
+ end
1492
1495
 
1493
1496
  # Override models backed by a view so they return true for #is_view?
1494
1497
  # (Dynamically-created controllers and view templates for such models will then act in a read-only way)
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 155
8
+ TINY = 156
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
data/lib/brick.rb CHANGED
@@ -1159,8 +1159,7 @@ ActiveSupport.on_load(:active_record) do
1159
1159
  # :singleton-method:
1160
1160
  # Determines whether to use Time.utc (using :utc) or Time.local (using :local) when pulling
1161
1161
  # dates and times from the database. This is set to :utc by default.
1162
- unless respond_to?(:default_timezone)
1163
- puts "ADDING!!! 4.w"
1162
+ unless ::ActiveRecord.respond_to?(:default_timezone) || respond_to?(:default_timezone)
1164
1163
  mattr_accessor :default_timezone, instance_writer: false
1165
1164
  self.default_timezone = :utc
1166
1165
  end
@@ -23,7 +23,8 @@ module Brick
23
23
  'time with time zone' => 'time',
24
24
  'double precision' => 'float',
25
25
  'smallint' => 'integer', # %%% Need to put in "limit: 2"
26
- # # Oracle data types
26
+ 'ARRAY' => 'string', # Note that we'll also add ", array: true"
27
+ # Oracle data types
27
28
  'VARCHAR2' => 'string',
28
29
  'CHAR' => 'string',
29
30
  ['NUMBER', 22] => 'integer',
@@ -176,7 +177,7 @@ module Brick
176
177
  # Support missing primary key (by adding: , id: false)
177
178
  id_option = if pk_is_also_fk || !pkey_cols&.present?
178
179
  needs_serial_col = true
179
- ', id: false'
180
+ +', id: false'
180
181
  elsif ((pkey_col_first = (col_def = relation[:cols][pkey_cols&.first])&.first) &&
181
182
  (pkey_col_first = SQL_TYPES[pkey_col_first] || SQL_TYPES[col_def&.[](0..1)] ||
182
183
  SQL_TYPES.find { |r| r.first.is_a?(Regexp) && pkey_col_first =~ r.first }&.last ||
@@ -185,16 +186,16 @@ module Brick
185
186
  )
186
187
  case pkey_col_first
187
188
  when 'integer'
188
- ', id: :serial'
189
+ +', id: :serial'
189
190
  when 'bigint'
190
- ', id: :bigserial'
191
+ +', id: :bigserial'
191
192
  else
192
- ", id: :#{pkey_col_first}" # Something like: id: :integer, primary_key: :businessentityid
193
+ +", id: :#{pkey_col_first}" # Something like: id: :integer, primary_key: :businessentityid
193
194
  end +
194
195
  (pkey_cols.first ? ", primary_key: :#{pkey_cols.first}" : '')
195
196
  end
196
197
  if !id_option && pkey_cols.sort != arpk
197
- id_option = ", primary_key: :#{pkey_cols.first}"
198
+ id_option = +", primary_key: :#{pkey_cols.first}"
198
199
  end
199
200
  if !is_4x_rails && (comment = relation&.fetch(:description, nil))&.present?
200
201
  (id_option ||= +'') << ", comment: #{comment.inspect}"
@@ -223,6 +224,7 @@ module Brick
223
224
  SQL_TYPES.find { |r| r.first.is_a?(Regexp) && col_type.first =~ r.first }&.last ||
224
225
  col_type.first
225
226
  suffix = col_type[3] || pkey_cols&.include?(col) ? +', null: false' : +''
227
+ suffix << ', array: true' if (col_type.first == 'ARRAY')
226
228
  if !is_4x_rails && klass && (comment = klass.columns_hash.fetch(col, nil)&.comment)&.present?
227
229
  suffix << ", comment: #{comment.inspect}"
228
230
  end
@@ -31,7 +31,7 @@ module Brick
31
31
  s[v_parts.first] = nil unless [::Brick.default_schema, 'public'].include?(v_parts.first)
32
32
  end
33
33
  end
34
- seeds = +"# Seeds file for #{ActiveRecord::Base.connection.current_database}:"
34
+ seeds = +"# Seeds file for #{ActiveRecord::Base.connection.current_database}:\n"
35
35
  done = []
36
36
  fks = {}
37
37
  stuck = {}
@@ -82,10 +82,14 @@ module Brick
82
82
  fkeys = relation[:fks].values.select { |assoc| assoc[:is_bt] && !assoc[:polymorphic] }
83
83
  # Refer to this table name as a symbol or dotted string as appropriate
84
84
  # tbl_code = tbl_parts.length == 1 ? ":#{tbl_parts.first}" : "'#{tbl}'"
85
- seeds << " # #{class_name}\n"
86
85
 
86
+ has_rows = false
87
87
  is_empty = true
88
88
  klass.order(*pkey_cols).each do |obj|
89
+ unless has_rows
90
+ has_rows = true
91
+ seeds << " puts 'Seeding: #{class_name}'\n"
92
+ end
89
93
  is_empty = false
90
94
  pk_val = obj.send(pkey_cols.first)
91
95
  fk_vals = []
@@ -98,19 +102,55 @@ module Brick
98
102
  val = val.to_s
99
103
  end
100
104
  if fk
101
- fk_vals << "#{fk[:assoc_name]}: #{fk[:inverse_table]}_#{val.inspect}" if val
105
+ inv_tbl = fk[:inverse_table].gsub('.', '__')
106
+ fk_vals << "#{fk[:assoc_name]}: #{inv_tbl}_#{brick_escape(val)}" if val
102
107
  else
103
108
  data << "#{col}: #{val.inspect}"
104
109
  end
105
110
  end
106
- seeds << "#{tbl}_#{pk_val} = #{class_name}.create(#{(fk_vals + data).join(', ')})\n"
111
+ seeds << "#{tbl.gsub('.', '__')}_#{brick_escape(pk_val)} = #{class_name}.create(#{(fk_vals + data).join(', ')})\n"
107
112
  end
113
+ seeds << " # (Skipping #{class_name} as it has no rows)\n" unless has_rows
108
114
  File.open(seed_file_path, "w") { |f| f.write seeds }
109
115
  end
110
116
  done.concat(fringe)
111
117
  chosen -= done
112
118
  end
119
+ stuck_counts = Hash.new { |h, k| h[k] = 0 }
120
+ chosen.each do |leftover|
121
+ puts "Can't do #{leftover} because:\n #{stuck[leftover].map do |snag|
122
+ stuck_counts[snag.last[:inverse_table]] += 1
123
+ snag.last[:assoc_name]
124
+ end.join(', ')}"
125
+ end
113
126
  puts "\n*** Created seeds for #{done.length} models in db/seeds.rb ***"
127
+ if (stuck_sorted = stuck_counts.to_a.sort { |a, b| b.last <=> a.last }).length.positive?
128
+ puts "-----------------------------------------"
129
+ puts "Unable to create migrations for #{stuck_sorted.length} tables#{
130
+ ". Here's the top 5 blockers" if stuck_sorted.length > 5
131
+ }:"
132
+ pp stuck_sorted[0..4]
133
+ end
134
+ end
135
+
136
+ private
137
+
138
+ def brick_escape(val)
139
+ val = val.to_s if val.is_a?(Date) || val.is_a?(Time) # Accommodate when for whatever reason a primary key is a date or time
140
+ case val
141
+ when String
142
+ ret = +''
143
+ val.each_char do |ch|
144
+ if ch < '0' || (ch > '9' && ch < 'A') || ch > 'Z'
145
+ ret << (ch == '_' ? ch : "x#{'K'.unpack('H*')[0]}")
146
+ else
147
+ ret << ch
148
+ end
149
+ end
150
+ ret
151
+ else
152
+ val
153
+ end
114
154
  end
115
155
  end
116
156
  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.155
4
+ version: 1.0.156
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-09 00:00:00.000000000 Z
11
+ date: 2023-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord