brick 1.0.67 → 1.0.68

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: 60ed6bcfecfc09b579a605a6141e06b958d0e274c010432be8b97980833be6fc
4
- data.tar.gz: 4ce18cf47d569f61e58cf25d3bd26577fea4932e7171cbcf5cb7756f9d4a8cc5
3
+ metadata.gz: 977737d8dec8900c82e2a973060dca56ae7897e281557e43e1c0696012521270
4
+ data.tar.gz: 8a005ecab292cbfdaf94b29476d4db56e9f5b71a46a5f71ca6fd049550ed4cff
5
5
  SHA512:
6
- metadata.gz: 7691f14a41dad2cea3fcc73f60fc88a57e24ecd8ab1d69575be6b716e43f9ae15eddc6e0e1bd089ba8b3daf7cef2e78ecdaf12a0a86e249ec8f609d00b0a473d
7
- data.tar.gz: 237aa7e873db35c6dad6c89c3641c7b9d81016520ddbbc0d1ddfc94576e067adc162c3e8a5f15c983df624e4e3d185d1e1e695a505f7b3a66bda6dd036d91e8c
6
+ metadata.gz: c3cfaf5cdcdf67038ba5969306f49b73c09977b9e1dec078ad3ca3d6f6e7d16b5b0d18eb16a982568966ac91cabdcb96e82362cce4906485581b36ce2e2410da
7
+ data.tar.gz: 50f38455e43528478fe694f08bfcc50a8968536c9e4e6d8ab0c1713ff621e2153454a541d8e5940f584f2bd9e06549c4d3db047ac11fbdedaf5bc536d0ac7cd1
@@ -1358,14 +1358,12 @@ module ActiveRecord::ConnectionHandling
1358
1358
  when 'Mysql2'
1359
1359
  ::Brick.default_schema = schema = ActiveRecord::Base.connection.current_database
1360
1360
  when 'SQLite'
1361
- # %%% Retrieve internal ActiveRecord table names like this:
1362
- # ActiveRecord::Base.internal_metadata_table_name, ActiveRecord::Base.schema_migrations_table_name
1363
1361
  sql = "SELECT m.name AS relation_name, UPPER(m.type) AS table_type,
1364
1362
  p.name AS column_name, p.type AS data_type,
1365
1363
  CASE p.pk WHEN 1 THEN 'PRIMARY KEY' END AS const
1366
1364
  FROM sqlite_master AS m
1367
1365
  INNER JOIN pragma_table_info(m.name) AS p
1368
- WHERE m.name NOT IN (?, ?)
1366
+ WHERE m.name NOT IN ('sqlite_sequence', ?, ?)
1369
1367
  ORDER BY m.name, p.cid"
1370
1368
  else
1371
1369
  puts "Unfamiliar with connection adapter #{ActiveRecord::Base.connection.adapter_name}"
@@ -96,17 +96,15 @@ module Brick
96
96
 
97
97
  alias :_brick_find_template :find_template
98
98
  def find_template(*args, **options)
99
- unless (is_status = ::Brick.config.add_status && args[0..1] == ['status', ['brick_gem']]) ||
99
+ unless (model_name = @_brick_model&.name) ||
100
+ (is_status = ::Brick.config.add_status && args[0..1] == ['status', ['brick_gem']]) ||
100
101
  (is_orphans = ::Brick.config.add_orphans && args[0..1] == ['orphans', ['brick_gem']]) ||
101
- (model_name = (
102
- @_brick_model ||
103
- # Used to also have: ActionView.version < ::Gem::Version.new('5.0') &&
104
- (args[1].is_a?(Array) ? set_brick_model(args) : nil)
105
- )&.name)
102
+ # Used to also have: ActionView.version < ::Gem::Version.new('5.0') &&
103
+ (model_name = (args[1].is_a?(Array) ? set_brick_model(args) : nil)&.name)
106
104
  return _brick_find_template(*args, **options)
107
105
  end
108
106
 
109
- unless is_status || is_orphans
107
+ if @_brick_model
110
108
  pk = @_brick_model._brick_primary_key(::Brick.relations.fetch(model_name, nil))
111
109
  obj_name = model_name.split('::').last.underscore
112
110
  path_obj_name = model_name.underscore.tr('/', '_')
@@ -180,7 +178,7 @@ module Brick
180
178
  end.keys.sort.each_with_object(+'') do |v, s|
181
179
  s << "<option value=\"#{v.underscore.gsub('.', '/').pluralize}\">#{v}</option>"
182
180
  end.html_safe
183
- table_options << '<option value="brick_status">(Status)</option>'.html_safe
181
+ table_options << '<option value="brick_status">(Status)</option>'.html_safe if ::Brick.config.add_status
184
182
  table_options << '<option value="brick_orphans">(Orphans)</option>'.html_safe if is_orphans
185
183
  css = +"<style>
186
184
  h1, h3 {
@@ -277,7 +275,7 @@ tr th, tr td {
277
275
  color: #80B8D2;
278
276
  }
279
277
 
280
- table.shadow tbody tr {
278
+ table.shadow > tbody > tr {
281
279
  border-bottom: thin solid #dddddd;
282
280
  }
283
281
 
@@ -285,7 +283,7 @@ table tbody tr:nth-of-type(even) {
285
283
  background-color: #f3f3f3;
286
284
  }
287
285
 
288
- table.shadow tbody tr:last-of-type {
286
+ table.shadow > tbody > tr:last-of-type {
289
287
  border-bottom: 2px solid #009879;
290
288
  }
291
289
 
@@ -302,14 +300,6 @@ a.big-arrow {
302
300
  font-size: 2.5em;
303
301
  text-decoration: none;
304
302
  }
305
- .wide-input {
306
- display: block;
307
- overflow: hidden;
308
- }
309
- .wide-input input[type=text] {
310
- display: inline-block;
311
- width: 90%;
312
- }
313
303
  .dimmed {
314
304
  background-color: #C0C0C0;
315
305
  text-align: center;
@@ -326,9 +316,6 @@ svg.revert {
326
316
  display: none;
327
317
  margin-left: 0.25em;
328
318
  }
329
- .wide-input > svg.revert {
330
- float: right;
331
- }
332
319
  input+svg.revert {
333
320
  top: 0.5em;
334
321
  }
@@ -550,7 +537,8 @@ erDiagram
550
537
  is_has_one = #{@_brick_model.name}.reflect_on_association(bt.first).inverse_of&.macro == :has_one ||
551
538
  ::Brick.config.has_ones&.fetch('#{@_brick_model.name}', nil)&.key?(bt.first.to_s)
552
539
  %> <%= \"#\{model_short_name} #\{is_has_one ? '||' : '}o'}--|| #\{bt_name} : \\\"#\{
553
- bt.first unless bt.first.to_s == bt[1].first.first.name.underscore.singularize.tr('/', '_')
540
+ bt_underscored = bt[1].first.first.name.underscore.singularize
541
+ bt.first unless bt.first.to_s == bt_underscored.split('/').last # Was: bt_underscored.tr('/', '_')
554
542
  }\\\"\".html_safe %>
555
543
  <% end
556
544
  last_through = nil
@@ -560,14 +548,15 @@ erDiagram
560
548
 
561
549
  callbacks[hm_name = hm_class.name.split('::').last] = hm_class
562
550
  if (through = hm.last.options[:through]&.to_s) # has_many :through (HMT)
563
- callbacks[through.singularize.camelize] = (through_assoc = hm.last.source_reflection).active_record
551
+ through_name = (through_assoc = hm.last.source_reflection).active_record.name.split('::').last
552
+ callbacks[through_name] = through_assoc.active_record
564
553
  if last_through == through # Same HM, so no need to build it again, and for clarity just put in a blank line
565
554
  %><%= \"\n\"
566
555
  %><% else
567
- %> <%= \"#\{model_short_name} ||--o{ #\{through_assoc.active_record.name}\".html_safe %> : \"\"
556
+ %> <%= \"#\{model_short_name} ||--o{ #\{through_name}\".html_safe %> : \"\"
568
557
  <% last_through = through
569
558
  end
570
- %> <%= \"#\{through_assoc.active_record.name} }o--|| #\{hm_name}\".html_safe %> : \"\"
559
+ %> <%= \"#\{through_name} }o--|| #\{hm_name}\".html_safe %> : \"\"
571
560
  <%= \"#\{model_short_name} }o..o{ #\{hm_name} : \\\"#\{hm.first}\\\"\".html_safe %><%
572
561
  else # has_many
573
562
  %> <%= \"#\{model_short_name} ||--o{ #\{hm_name} : \\\"#\{
@@ -575,21 +564,25 @@ erDiagram
575
564
  }\\\"\".html_safe %><%
576
565
  end %>
577
566
  <% end
567
+ def dt_lookup(dt)
568
+ { 'integer' => 'int', }[dt] || dt.tr(' ', '_')
569
+ end
578
570
  callbacks.merge({model_short_name => #{@_brick_model.name}}).each do |cb_k, cb_class|
579
571
  cb_relation = ::Brick.relations[cb_class.table_name]
580
572
  pkeys = cb_relation[:pkey]&.first&.last
581
573
  fkeys = cb_relation[:fks]&.values&.each_with_object([]) { |fk, s| s << fk[:fk] if fk.fetch(:is_bt, nil) }
574
+ cols = cb_relation[:cols]
582
575
  %> <%= cb_k %> {<%
583
576
  pkeys&.each do |pk| %>
584
- <%= \"int #\{pk} \\\"PK#\{' fk' if fkeys&.include?(pk)}\\\"\".html_safe %><%
577
+ <%= \"#\{dt_lookup(cols[pk].first)} #\{pk} \\\"PK#\{' fk' if fkeys&.include?(pk)}\\\"\".html_safe %><%
585
578
  end %><%
586
579
  fkeys&.each do |fk|
587
580
  if fk.is_a?(Array)
588
581
  fk.each do |fk_part| %>
589
- <%= \"int #\{fk_part} \\\"&nbsp;&nbsp;&nbsp;&nbsp;fk\\\"\".html_safe unless pkeys&.include?(fk_part) %><%
582
+ <%= \"#\{dt_lookup(cols[fk_part].first)} #\{fk_part} \\\"&nbsp;&nbsp;&nbsp;&nbsp;fk\\\"\".html_safe unless pkeys&.include?(fk_part) %><%
590
583
  end
591
584
  else %>
592
- <%= \"int #\{fk} \\\"&nbsp;&nbsp;&nbsp;&nbsp;fk\\\"\".html_safe unless pkeys&.include?(fk) %><%
585
+ <%= \"#\{dt_lookup(cols[fk].first)} #\{fk} \\\"&nbsp;&nbsp;&nbsp;&nbsp;fk\\\"\".html_safe unless pkeys&.include?(fk) %><%
593
586
  end
594
587
  end %>
595
588
  }
@@ -694,7 +687,7 @@ erDiagram
694
687
  </script>
695
688
  <script async defer src=\"https://apis.google.com/js/api.js\" onload=\"gapiLoaded()\"></script>
696
689
  "
697
- end
690
+ end # DutyFree data export and import
698
691
  # %%% Instead of our current "for Janet Leverling (Employee)" kind of link we previously had this code that did a "where x = 123" thing:
699
692
  # (where <%= @_brick_params.each_with_object([]) { |v, s| s << \"#\{v.first\} = #\{v.last.inspect\}\" }.join(', ') %>)
700
693
  +"#{css}
@@ -833,6 +826,7 @@ erDiagram
833
826
  #{script}"
834
827
 
835
828
  when 'status'
829
+ if is_status
836
830
  # Status page - list of all resources and 5 things they do or don't have present, and what is turned on and off
837
831
  # Must load all models, and then find what table names are represented
838
832
  # Easily could be multiple files involved (STI for instance)
@@ -856,7 +850,7 @@ erDiagram
856
850
  @resources.each do |r|
857
851
  %>
858
852
  <tr>
859
- <td><%= link_to(r[0], \"/#\{r[0].tr('.', '/')}\") %></td>
853
+ <td><%= link_to(r[0], \"/#\{r[0].underscore.tr('.', '/')}\") %></td>
860
854
  <td<%= if r[1]
861
855
  ' class=\"orphan\"' unless ::Brick.relations.key?(r[1])
862
856
  else
@@ -877,6 +871,7 @@ erDiagram
877
871
  <% end %>
878
872
  </tbody></table>
879
873
  #{script}"
874
+ end
880
875
 
881
876
  when 'orphans'
882
877
  if is_orphans
@@ -962,38 +957,41 @@ end
962
957
  <% end %>
963
958
  </th>
964
959
  <td>
960
+ <table><tr><td>
965
961
  <% dt_pickers = { datetime: 'datetimepicker', timestamp: 'datetimepicker', time: 'timepicker', date: 'datepicker' }
962
+ html_options = {}
963
+ html_options[:class] = 'dimmed' unless val
964
+ is_revert = true
966
965
  if bt
967
- html_options = { prompt: \"Select #\{bt_name\}\" }
968
- html_options[:class] = 'dimmed' unless val %>
966
+ html_options[:prompt] = \"Select #\{bt_name\}\" %>
969
967
  <%= f.select k.to_sym, bt[3], { value: val || '^^^brick_NULL^^^' }, html_options %>
970
968
  <%= if (bt_obj = bt_class&.find_by(bt_pair[1] => val))
971
969
  link_to('⇛', send(\"#\{bt_class.base_class.name.underscore.tr('/', '_')\}_path\".to_sym, bt_obj.send(bt_class.primary_key.to_sym)), { class: 'show-arrow' })
972
970
  elsif val
973
971
  \"<span class=\\\"orphan\\\">Orphaned ID: #\{val}</span>\".html_safe
974
- end %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
972
+ end %>
975
973
  <% else
976
- html_options = {}
977
- html_options[:class] = 'dimmed' unless val
978
- case (col_type = col.type || col.sql_type)
974
+ case (col_type = col.type || col.sql_type)
979
975
  when :string, :text %>
980
- <% if is_bcrypt?(val) # || .readonly? %>
976
+ <% if is_bcrypt?(val) # || .readonly?
977
+ is_revert = false %>
981
978
  <%= hide_bcrypt(val, 1000) %>
982
979
  <% else %>
983
- <div class=\"wide-input\"><%= f.text_field(k.to_sym, html_options) %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg></div>
980
+ <%= f.text_field(k.to_sym, html_options) %>
984
981
  <% end %>
985
982
  <% when :boolean %>
986
- <%= f.check_box k.to_sym %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
983
+ <%= f.check_box k.to_sym %>
987
984
  <% when :integer, :decimal, :float %>
988
985
  <%= if col_type == :integer
989
986
  f.text_field k.to_sym, { pattern: '\\d*', class: 'check-validity' }
990
987
  else
991
988
  f.number_field k.to_sym
992
- end %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
989
+ end %>
993
990
  <% when *dt_pickers.keys
994
991
  is_includes_dates = true %>
995
- <%= f.text_field k.to_sym, { class: dt_pickers[col_type] } %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
996
- <% when :uuid %>
992
+ <%= f.text_field k.to_sym, { class: dt_pickers[col_type] } %>
993
+ <% when :uuid
994
+ is_revert = false %>
997
995
  <%=
998
996
  # Postgres naturally uses the +uuid_generate_v4()+ function from the uuid-ossp extension
999
997
  # If it's not yet enabled then: create extension \"uuid-ossp\";
@@ -1004,11 +1002,18 @@ end
1004
1002
  # In Postgres labels of data stored in a hierarchical tree-like structure
1005
1003
  # If it's not yet enabled then: create extension ltree;
1006
1004
  val %>
1007
- <% when :binary, :primary_key %>
1005
+ <% when :binary, :primary_key
1006
+ is_revert = false %>
1008
1007
  <% else %>
1009
- <%= display_value(col_type, val) %>
1008
+ <%= display_value(col_type, val)
1009
+ is_revert = false %>
1010
+ <% end
1011
+ end
1012
+ if is_revert
1013
+ %></td>
1014
+ <td><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
1010
1015
  <% end %>
1011
- <% end %>
1016
+ </td></tr></table>
1012
1017
  </td>
1013
1018
  </tr>
1014
1019
  <% end
@@ -1070,7 +1075,7 @@ flatpickr(\".timepicker\", {enableTime: true, noCalendar: true});
1070
1075
  var mermaidErd = document.getElementById(\"mermaidErd\");
1071
1076
  var mermaidCode;
1072
1077
  var cbs = {<%= callbacks.map { |k, v| \"#\{k}: \\\"#\{v.name.underscore.pluralize}\\\"\" }.join(', ').html_safe %>};
1073
- imgErd.addEventListener(\"click\", showErd);
1078
+ if (imgErd) imgErd.addEventListener(\"click\", showErd);
1074
1079
  function showErd() {
1075
1080
  imgErd.style.display = \"none\";
1076
1081
  mermaidErd.style.display = \"inline-block\";
@@ -1131,9 +1136,12 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1131
1136
  var origVal = getInpVal(),
1132
1137
  prevVal = origVal;
1133
1138
  var revert;
1134
- if ((revert = ((inp.tagName === \"SELECT\" && inp.nextElementSibling.nextElementSibling) ||
1135
- inp.nextElementSibling ||
1136
- inp.parentElement.nextElementSibling)) && revert.tagName.toLowerCase() === \"svg\")
1139
+ if (inp.getAttribute(\"type\") == \"hidden\" || inp.getAttribute(\"type\") == \"submit\") return;
1140
+
1141
+ var svgTd = null;
1142
+ if ((revert = ((inp.tagName === \"SELECT\" && (svgTd = inp.parentElement.nextElementSibling) && svgTd.firstElementChild) ||
1143
+ ((svgTd = inp.parentElement.nextElementSibling) && svgTd.firstElementChild))
1144
+ ) && revert.tagName.toLowerCase() === \"svg\")
1137
1145
  revert.addEventListener(\"click\", function (e) {
1138
1146
  if (inp.type === \"checkbox\")
1139
1147
  inp.checked = origVal;
@@ -1164,7 +1172,7 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1164
1172
  prevVal = getInpVal();
1165
1173
  }
1166
1174
  // Show or hide the revert button
1167
- if (revert) revert.style.display = getInpVal() === origVal ? \"none\" : \"inline-block\";
1175
+ if (revert) revert.style.display = getInpVal() === origVal ? \"none\" : \"block\";
1168
1176
  });
1169
1177
  function getInpVal() {
1170
1178
  return inp.type === \"checkbox\" ? inp.checked : inp.value;
@@ -1184,6 +1192,13 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1184
1192
  # In order to defer auto-creation of any routes that already exist, calculate Brick routes only after having loaded all others
1185
1193
  prepend ::Brick::RouteSet
1186
1194
  end
1195
+ # Do the root route before the Rails Welcome one would otherwise take precedence
1196
+ unless (route = ::Brick.config.default_route_fallback).blank? ||
1197
+ ::Rails.application.routes.named_routes.send(:routes)[:root]
1198
+ ::Rails.application.routes.append do
1199
+ send(:root, "#{route}#{'#index' unless route.index('#')}")
1200
+ end
1201
+ end
1187
1202
  end
1188
1203
 
1189
1204
  # Just in case it hadn't been done previously when we tried to load the brick initialiser,
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 67
8
+ TINY = 68
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
@@ -123,7 +123,7 @@ module Brick
123
123
  end
124
124
 
125
125
  class << self
126
- attr_accessor :default_schema, :db_schemas
126
+ attr_accessor :default_schema, :db_schemas, :routes_done
127
127
 
128
128
  def set_db_schema(params)
129
129
  schema = params['_brick_schema'] || 'public'
@@ -461,11 +461,11 @@ In config/initializers/brick.rb appropriate entries would look something like:
461
461
 
462
462
  module RouteSet
463
463
  def finalize!
464
+ return super if ::Brick.routes_done
465
+
466
+ ::Brick.routes_done = true
464
467
  existing_controllers = routes.each_with_object({}) { |r, s| c = r.defaults[:controller]; s[c] = nil if c }
465
468
  ::Rails.application.routes.append do
466
- unless ::Brick.config.default_route_fallback.blank? || ::Rails.application.routes.named_routes.send(:routes)[:root]
467
- send(:root, "#{::Brick.config.default_route_fallback}#index")
468
- end
469
469
  # %%% TODO: If no auto-controllers then enumerate the controllers folder in order to build matching routes
470
470
  # If auto-controllers and auto-models are both enabled then this makes sense:
471
471
  ::Brick.relations.each do |rel_name, v|
@@ -279,8 +279,8 @@ module Brick
279
279
  # # route to go to the :index action for what would be a controller for that table. You can specify any controller
280
280
  # # name and action you wish in order to override this and have that be the default route when none other has been
281
281
  # # specified in routes.rb or elsewhere. (Or just use an empty string in order to disable this behaviour.)
282
- # Brick.default_route_fallback = 'customers' # This defaults to \"customers/index\"
283
- # Brick.default_route_fallback = 'orders/outstanding' # Example of a non-RESTful route
282
+ # Brick.default_route_fallback = 'customers' # This defaults to \"customers#index\"
283
+ # Brick.default_route_fallback = 'orders#outstanding' # Example of a non-RESTful route
284
284
  # Brick.default_route_fallback = '' # Omits setting a default route in the absence of any other
285
285
  ")
286
286
  end
@@ -22,7 +22,16 @@ module Brick
22
22
  'time without time zone' => 'time',
23
23
  'time with time zone' => 'time',
24
24
  'double precision' => 'float',
25
- 'smallint' => 'integer' } # %%% Need to put in "limit: 2"
25
+ 'smallint' => 'integer', # %%% Need to put in "limit: 2"
26
+ # Sqlite data types
27
+ 'TEXT' => 'text',
28
+ '' => 'string',
29
+ 'INTEGER' => 'integer',
30
+ 'REAL' => 'float',
31
+ 'BLOB' => 'binary',
32
+ 'TIMESTAMP' => 'timestamp',
33
+ 'DATETIME' => 'timestamp'
34
+ }
26
35
  # (Still need to find what "inet" and "json" data types map to.)
27
36
 
28
37
  desc 'Auto-generates migration files for an existing database.'
@@ -38,7 +47,8 @@ module Brick
38
47
  return
39
48
  end
40
49
 
41
- key_type = (ActiveRecord.version < ::Gem::Version.new('5.1') ? 'integer' : 'bigint')
50
+ is_sqlite = ActiveRecord::Base.connection.adapter_name == 'SQLite'
51
+ key_type = ((is_sqlite || ActiveRecord.version < ::Gem::Version.new('5.1')) ? 'integer' : 'bigint')
42
52
  is_4x_rails = ActiveRecord.version < ::Gem::Version.new('5.0')
43
53
  ar_version = "[#{ActiveRecord.version.segments[0..1].join('.')}]" unless is_4x_rails
44
54
  is_insert_versions = true
@@ -142,21 +152,20 @@ module Brick
142
152
  # if this one has come in as bigint or integer.
143
153
  pk_is_also_fk = fkey_cols.any? { |assoc| pkey_cols&.first == assoc[:fk] } ? pkey_cols&.first : nil
144
154
  # Support missing primary key (by adding: ,id: false)
145
- id_option = if pk_is_also_fk || (pkey_col_first = relation[:cols][pkey_cols&.first]&.first) != key_type
146
- if pk_is_also_fk || !pkey_cols&.present?
147
- ', id: false'
155
+ id_option = if pk_is_also_fk || !pkey_cols&.present?
156
+ ', id: false'
157
+ elsif ((pkey_col_first = relation[:cols][pkey_cols&.first]&.first) &&
158
+ (pkey_col_first = SQL_TYPES[pkey_col_first] || pkey_col_first) != key_type)
159
+ case pkey_col_first
160
+ when 'integer'
161
+ ', id: :serial'
162
+ when 'bigint'
163
+ ', id: :bigserial'
148
164
  else
149
- case pkey_col_first
150
- when 'integer'
151
- ', id: :serial'
152
- when 'bigint'
153
- ', id: :bigserial'
154
- else
155
- ", id: :#{SQL_TYPES[pkey_col_first] || pkey_col_first}" # Something like: id: :integer, primary_key: :businessentityid
156
- end +
157
- (pkey_cols.first ? ", primary_key: :#{pkey_cols.first}" : '') +
158
- (!is_4x_rails && (comment = relation&.fetch(:description, nil))&.present? ? ", comment: #{comment.inspect}" : '')
159
- end
165
+ ", id: :#{pkey_col_first}" # Something like: id: :integer, primary_key: :businessentityid
166
+ end +
167
+ (pkey_cols.first ? ", primary_key: :#{pkey_cols.first}" : '') +
168
+ (!is_4x_rails && (comment = relation&.fetch(:description, nil))&.present? ? ", comment: #{comment.inspect}" : '')
160
169
  end
161
170
  # Find the ActiveRecord class in order to see if the columns have comments
162
171
  unless is_4x_rails
@@ -208,7 +217,7 @@ module Brick
208
217
  mig << " t.references :#{fk[:assoc_name]}#{suffix}, foreign_key: { to_table: #{to_table} }\n"
209
218
  end
210
219
  else
211
- next if !id_option&.end_with?('id: false') && pkey_cols.include?(col)
220
+ next if !id_option&.end_with?('id: false') && pkey_cols&.include?(col)
212
221
 
213
222
  # See if there are generic timestamps
214
223
  if sql_type == 'timestamp' && ['created_at','updated_at'].include?(col)
@@ -244,7 +253,7 @@ module Brick
244
253
  mig << " #{'# ' if is_commented}add_foreign_key #{tbl_code}, #{add_fk[0]}, column: :#{add_fk[1]}, primary_key: :#{pk}\n"
245
254
  end
246
255
  mig << " end\n"
247
- versions_to_create << migration_file_write(mig_path, "create_#{tbl_parts.join('_')}", current_mig_time += 1.minute, ar_version, mig)
256
+ versions_to_create << migration_file_write(mig_path, "create_#{tbl_parts.map(&:underscore).join('_')}", current_mig_time += 1.minute, ar_version, mig)
248
257
  end
249
258
  done.concat(fringe)
250
259
  chosen -= done
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.67
4
+ version: 1.0.68
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-01 00:00:00.000000000 Z
11
+ date: 2022-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord