brick 1.0.69 → 1.0.70
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/extensions.rb +53 -36
- data/lib/brick/frameworks/rails/engine.rb +8 -5
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +21 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af28a866a39817e9daa3a54b8f091c790d9280571cec94f9a3a317606e239fd9
|
4
|
+
data.tar.gz: a2cfe0b823c8b364c8f842852e631a48efe7f9dde8d506a27fbc85ebb74e58eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cc18926c7c449e7dfba8d919d41b2490cb4d4a14692073f98f96903da075a31ff029f7a5f5931a845c7caf8f00b51cdba9ab0711dfa626d9e445d9122350b2b
|
7
|
+
data.tar.gz: 84373ca68edb9ebb88b8ccf2963bbf2e416c35c41840df1c1cd6922ef757cac204453aeb1e15881316681558a53ce17e32692e16320bb1b53c608bc41401920d
|
data/lib/brick/extensions.rb
CHANGED
@@ -384,6 +384,7 @@ module ActiveRecord
|
|
384
384
|
def brick_select(params, selects = nil, order_by = nil, translations = {}, join_array = ::Brick::JoinArray.new)
|
385
385
|
is_postgres = ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
386
386
|
is_mysql = ActiveRecord::Base.connection.adapter_name == 'Mysql2'
|
387
|
+
is_mssql = ActiveRecord::Base.connection.adapter_name == 'SQLServer'
|
387
388
|
is_distinct = nil
|
388
389
|
wheres = {}
|
389
390
|
params.each do |k, v|
|
@@ -408,10 +409,10 @@ module ActiveRecord
|
|
408
409
|
if selects&.empty? # Default to all columns
|
409
410
|
tbl_no_schema = table.name.split('.').last
|
410
411
|
columns.each do |col|
|
411
|
-
col_alias = " AS
|
412
|
+
col_alias = " AS #{col.name}_" if (col_name = col.name) == 'class'
|
412
413
|
selects << if is_mysql
|
413
414
|
"`#{tbl_no_schema}`.`#{col_name}`#{col_alias}"
|
414
|
-
elsif is_postgres
|
415
|
+
elsif is_postgres || is_mssql
|
415
416
|
# Postgres can not use DISTINCT with any columns that are XML, so for any of those just convert to text
|
416
417
|
cast_as_text = '::text' if is_distinct && Brick.relations[klass.table_name]&.[](:cols)&.[](col.name)&.first&.start_with?('xml')
|
417
418
|
"\"#{tbl_no_schema}\".\"#{col_name}\"#{cast_as_text}#{col_alias}"
|
@@ -449,6 +450,8 @@ module ActiveRecord
|
|
449
450
|
"`#{field_tbl_name}`.`#{sel_col.last}` AS `#{col_alias}`"
|
450
451
|
elsif is_postgres
|
451
452
|
"\"#{field_tbl_name}\".\"#{sel_col.last}\"#{'::text' if is_xml} AS \"#{col_alias}\""
|
453
|
+
elsif is_mssql
|
454
|
+
"\"#{field_tbl_name}\".\"#{sel_col.last}\" AS \"#{col_alias}\""
|
452
455
|
else
|
453
456
|
"#{field_tbl_name}.#{sel_col.last} AS \"#{col_alias}\""
|
454
457
|
end
|
@@ -462,7 +465,7 @@ module ActiveRecord
|
|
462
465
|
id_for_tables[v.first] << if id_part
|
463
466
|
selects << if is_mysql
|
464
467
|
"#{"`#{tbl_name}`.`#{id_part}`"} AS `#{(id_alias = "br_fk_#{v.first}__#{id_part}")}`"
|
465
|
-
elsif is_postgres
|
468
|
+
elsif is_postgres || is_mssql
|
466
469
|
"#{"\"#{tbl_name}\".\"#{id_part}\""} AS \"#{(id_alias = "br_fk_#{v.first}__#{id_part}")}\""
|
467
470
|
else
|
468
471
|
"#{"#{tbl_name}.#{id_part}"} AS \"#{(id_alias = "br_fk_#{v.first}__#{id_part}")}\""
|
@@ -506,7 +509,7 @@ module ActiveRecord
|
|
506
509
|
pri_tbl_name = is_mysql ? "`#{pri_tbl.table_name}`" : "\"#{pri_tbl.table_name.gsub('.', '"."')}\""
|
507
510
|
pri_tbl_name = if is_mysql
|
508
511
|
"`#{pri_tbl.table_name}`"
|
509
|
-
elsif is_postgres
|
512
|
+
elsif is_postgres || is_mssql
|
510
513
|
"\"#{pri_tbl.table_name.gsub('.', '"."')}\""
|
511
514
|
else
|
512
515
|
pri_tbl.table_name
|
@@ -525,12 +528,12 @@ module ActiveRecord
|
|
525
528
|
end
|
526
529
|
hm_table_name = if is_mysql
|
527
530
|
"`#{associative&.table_name || hm.klass.table_name}`"
|
528
|
-
elsif is_postgres
|
531
|
+
elsif is_postgres || is_mssql
|
529
532
|
"\"#{(associative&.table_name || hm.klass.table_name).gsub('.', '"."')}\""
|
530
533
|
else
|
531
534
|
associative&.table_name || hm.klass.table_name
|
532
535
|
end
|
533
|
-
group_bys = ::Brick.is_oracle ? selects : (1..selects.length).to_a
|
536
|
+
group_bys = ::Brick.is_oracle || is_mssql ? selects : (1..selects.length).to_a
|
534
537
|
join_clause = "LEFT OUTER
|
535
538
|
JOIN (SELECT #{selects.join(', ')}, COUNT(#{'DISTINCT ' if hm.options[:through]}#{count_column
|
536
539
|
}) AS c_t_ FROM #{hm_table_name} GROUP BY #{group_bys.join(', ')}) #{tbl_alias}"
|
@@ -661,7 +664,7 @@ Module.class_exec do
|
|
661
664
|
)
|
662
665
|
return possible
|
663
666
|
end
|
664
|
-
class_name = args.first.to_s
|
667
|
+
class_name = ::Brick.namify(args.first.to_s)
|
665
668
|
# self.name is nil when a model name is requested in an .erb file
|
666
669
|
base_module = (self < ActiveRecord::Migration || !self.name) ? Object : self
|
667
670
|
# See if a file is there in the same way that ActiveSupport::Dependencies#load_missing_constant
|
@@ -773,7 +776,7 @@ class Object
|
|
773
776
|
schema_name = Apartment.default_schema
|
774
777
|
end
|
775
778
|
# Maybe, just maybe there's a database table that will satisfy this need
|
776
|
-
if (matching = [table_name, singular_table_name, plural_class_name, model_name].find { |m| relations.key?(schema_name ? "#{schema_name}.#{m}" : m) })
|
779
|
+
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) })
|
777
780
|
build_model_worker(schema_name, inheritable_name, model_name, singular_table_name, table_name, relations, matching)
|
778
781
|
end
|
779
782
|
end
|
@@ -1340,7 +1343,7 @@ class Object
|
|
1340
1343
|
# hm_assoc[:assoc_name] = new_alt_name
|
1341
1344
|
[new_alt_name, true]
|
1342
1345
|
else
|
1343
|
-
assoc_name = hm_assoc[:inverse_table].pluralize
|
1346
|
+
assoc_name = ::Brick.namify(hm_assoc[:inverse_table]).pluralize
|
1344
1347
|
# hm_assoc[:assoc_name] = assoc_name
|
1345
1348
|
[assoc_name, assoc_name.include?('.')]
|
1346
1349
|
end
|
@@ -1383,12 +1386,20 @@ module ActiveRecord::ConnectionHandling
|
|
1383
1386
|
# puts ActiveRecord::Base.execute_sql("SELECT current_setting('SEARCH_PATH')").to_a.inspect
|
1384
1387
|
|
1385
1388
|
is_postgres = nil
|
1389
|
+
is_mssql = ActiveRecord::Base.connection.adapter_name == 'SQLServer'
|
1386
1390
|
case ActiveRecord::Base.connection.adapter_name
|
1387
|
-
when 'PostgreSQL'
|
1388
|
-
is_postgres =
|
1391
|
+
when 'PostgreSQL', 'SQLServer'
|
1392
|
+
is_postgres = !is_mssql
|
1389
1393
|
db_schemas = ActiveRecord::Base.execute_sql('SELECT DISTINCT table_schema FROM INFORMATION_SCHEMA.tables;')
|
1390
1394
|
::Brick.db_schemas = db_schemas.each_with_object({}) do |row, s|
|
1391
|
-
row =
|
1395
|
+
row = case row
|
1396
|
+
when String
|
1397
|
+
row
|
1398
|
+
when Array
|
1399
|
+
row.first
|
1400
|
+
else
|
1401
|
+
row['table_schema']
|
1402
|
+
end
|
1392
1403
|
# Remove any system schemas
|
1393
1404
|
s[row] = nil unless ['information_schema', 'pg_catalog'].include?(row)
|
1394
1405
|
end
|
@@ -1437,7 +1448,7 @@ module ActiveRecord::ConnectionHandling
|
|
1437
1448
|
case ActiveRecord::Base.connection.adapter_name
|
1438
1449
|
when 'PostgreSQL', 'SQLite' # These bring back a hash for each row because the query uses column aliases
|
1439
1450
|
# schema ||= 'public' if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
1440
|
-
ActiveRecord::Base.retrieve_schema_and_tables(sql, is_postgres, schema).each do |r|
|
1451
|
+
ActiveRecord::Base.retrieve_schema_and_tables(sql, is_postgres, is_mssql, schema).each do |r|
|
1441
1452
|
# If Apartment gem lists the table as being associated with a non-tenanted model then use whatever it thinks
|
1442
1453
|
# is the default schema, usually 'public'.
|
1443
1454
|
schema_name = if ::Brick.config.schema_behavior[:multitenant]
|
@@ -1464,7 +1475,8 @@ module ActiveRecord::ConnectionHandling
|
|
1464
1475
|
# puts "KEY! #{r['relation_name']}.#{col_name} #{r['key']} #{r['const']}" if r['key']
|
1465
1476
|
end
|
1466
1477
|
else # MySQL2 and OracleEnhanced act a little differently, bringing back an array for each row
|
1467
|
-
schema_and_tables =
|
1478
|
+
schema_and_tables = case ActiveRecord::Base.connection.adapter_name
|
1479
|
+
when 'OracleEnhanced'
|
1468
1480
|
sql =
|
1469
1481
|
"SELECT c.owner AS schema, c.table_name AS relation_name, 'BASE_TABLE' AS table_type,
|
1470
1482
|
LOWER(c.column_name) AS column_name, c.data_type,
|
@@ -1527,9 +1539,9 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
1527
1539
|
# end
|
1528
1540
|
# schema = ::Brick.default_schema # Reset back for this next round of fun
|
1529
1541
|
case ActiveRecord::Base.connection.adapter_name
|
1530
|
-
when 'PostgreSQL', 'Mysql2'
|
1542
|
+
when 'PostgreSQL', 'Mysql2', 'SQLServer'
|
1531
1543
|
sql = "SELECT kcu1.CONSTRAINT_SCHEMA, kcu1.TABLE_NAME, kcu1.COLUMN_NAME,
|
1532
|
-
|
1544
|
+
kcu2.CONSTRAINT_SCHEMA AS primary_schema, kcu2.TABLE_NAME AS primary_table, kcu1.CONSTRAINT_NAME AS CONSTRAINT_SCHEMA_FK
|
1533
1545
|
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS rc
|
1534
1546
|
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS kcu1
|
1535
1547
|
ON kcu1.CONSTRAINT_CATALOG = rc.CONSTRAINT_CATALOG
|
@@ -1540,7 +1552,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
1540
1552
|
AND kcu2.CONSTRAINT_SCHEMA = rc.UNIQUE_CONSTRAINT_SCHEMA
|
1541
1553
|
AND kcu2.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME#{"
|
1542
1554
|
AND kcu2.TABLE_NAME = kcu1.REFERENCED_TABLE_NAME
|
1543
|
-
AND kcu2.COLUMN_NAME = kcu1.REFERENCED_COLUMN_NAME" unless is_postgres }
|
1555
|
+
AND kcu2.COLUMN_NAME = kcu1.REFERENCED_COLUMN_NAME" unless is_postgres || is_mssql }
|
1544
1556
|
AND kcu2.ORDINAL_POSITION = kcu1.ORDINAL_POSITION#{"
|
1545
1557
|
WHERE kcu1.CONSTRAINT_SCHEMA = COALESCE(current_setting('SEARCH_PATH'), 'public')" if is_postgres && schema }"
|
1546
1558
|
# AND kcu2.TABLE_NAME = ?;", Apartment::Tenant.current, table_name
|
@@ -1568,15 +1580,13 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
1568
1580
|
AND ac.owner IN (#{schemas})
|
1569
1581
|
AND ac.r_owner IN (#{schemas})"
|
1570
1582
|
fk_references = ActiveRecord::Base.execute_oracle(sql)
|
1571
|
-
else
|
1572
|
-
binding.pry
|
1573
1583
|
end
|
1574
1584
|
::Brick.is_oracle = true if ActiveRecord::Base.connection.adapter_name == 'OracleEnhanced'
|
1575
1585
|
# ::Brick.default_schema ||= schema ||= 'public' if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
1576
1586
|
fk_references&.each do |fk|
|
1577
1587
|
fk = fk.values unless fk.is_a?(Array)
|
1578
1588
|
# Multitenancy makes things a little more general overall, except for non-tenanted tables
|
1579
|
-
if apartment_excluded&.include?(fk[1].singularize.camelize)
|
1589
|
+
if apartment_excluded&.include?(::Brick.namify(fk[1]).singularize.camelize)
|
1580
1590
|
fk[0] = Apartment.default_schema
|
1581
1591
|
elsif is_postgres && (fk[0] == 'public' || (is_multitenant && fk[0] == schema)) ||
|
1582
1592
|
!is_postgres && ['mysql', 'performance_schema', 'sys'].exclude?(fk[0])
|
@@ -1621,29 +1631,35 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
1621
1631
|
::Brick.load_additional_references if initializer_loaded
|
1622
1632
|
end
|
1623
1633
|
|
1624
|
-
def retrieve_schema_and_tables(sql = nil, is_postgres = nil, schema = nil)
|
1634
|
+
def retrieve_schema_and_tables(sql = nil, is_postgres = nil, is_mssql = nil, schema = nil)
|
1635
|
+
is_mssql = ActiveRecord::Base.connection.adapter_name == 'SQLServer' if is_mssql.nil?
|
1625
1636
|
sql ||= "SELECT t.table_schema AS \"schema\", t.table_name AS relation_name, t.table_type,#{"
|
1626
1637
|
pg_catalog.obj_description(
|
1627
1638
|
('\"' || t.table_schema || '\".\"' || t.table_name || '\"')::regclass, 'pg_class'
|
1628
1639
|
) AS table_description," if is_postgres}
|
1629
1640
|
c.column_name, c.data_type,
|
1630
1641
|
COALESCE(c.character_maximum_length, c.numeric_precision) AS max_length,
|
1631
|
-
|
1642
|
+
kcu.constraint_type AS const, kcu.constraint_name AS \"key\",
|
1632
1643
|
c.is_nullable
|
1633
1644
|
FROM INFORMATION_SCHEMA.tables AS t
|
1634
1645
|
LEFT OUTER JOIN INFORMATION_SCHEMA.columns AS c ON t.table_schema = c.table_schema
|
1635
1646
|
AND t.table_name = c.table_name
|
1636
|
-
|
1637
|
-
|
1647
|
+
LEFT OUTER JOIN
|
1648
|
+
(SELECT kcu1.constraint_schema, kcu1.table_name, kcu1.ordinal_position,
|
1649
|
+
tc.constraint_type, kcu1.constraint_name
|
1650
|
+
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS kcu1
|
1651
|
+
INNER JOIN INFORMATION_SCHEMA.table_constraints AS tc
|
1652
|
+
ON kcu1.CONSTRAINT_SCHEMA = tc.CONSTRAINT_SCHEMA
|
1653
|
+
AND kcu1.TABLE_NAME = tc.TABLE_NAME
|
1654
|
+
AND kcu1.CONSTRAINT_NAME = tc.constraint_name
|
1655
|
+
AND tc.constraint_type != 'FOREIGN KEY' -- For MSSQL
|
1656
|
+
) AS kcu ON
|
1657
|
+
-- kcu.CONSTRAINT_CATALOG = t.table_catalog AND
|
1638
1658
|
kcu.CONSTRAINT_SCHEMA = c.table_schema
|
1639
|
-
AND kcu.TABLE_NAME = c.table_name
|
1640
|
-
|
1659
|
+
AND kcu.TABLE_NAME = c.table_name#{"
|
1660
|
+
-- AND kcu.position_in_unique_constraint IS NULL" unless is_mssql}
|
1641
1661
|
AND kcu.ordinal_position = c.ordinal_position
|
1642
|
-
|
1643
|
-
ON kcu.CONSTRAINT_SCHEMA = tc.CONSTRAINT_SCHEMA
|
1644
|
-
AND kcu.TABLE_NAME = tc.TABLE_NAME
|
1645
|
-
AND kcu.CONSTRAINT_NAME = tc.constraint_name
|
1646
|
-
WHERE t.table_schema #{is_postgres ?
|
1662
|
+
WHERE t.table_schema #{is_postgres || is_mssql ?
|
1647
1663
|
"NOT IN ('information_schema', 'pg_catalog')"
|
1648
1664
|
:
|
1649
1665
|
"= '#{ActiveRecord::Base.connection.current_database.tr("'", "''")}'"}#{"
|
@@ -1699,22 +1715,23 @@ module Brick
|
|
1699
1715
|
|
1700
1716
|
class << self
|
1701
1717
|
def _add_bt_and_hm(fk, relations, is_polymorphic = false, is_optional = false)
|
1702
|
-
bt_assoc_name = fk[2]
|
1718
|
+
bt_assoc_name = ::Brick.namify(fk[2])
|
1703
1719
|
unless is_polymorphic
|
1704
1720
|
bt_assoc_name = if bt_assoc_name.underscore.end_with?('_id')
|
1705
|
-
bt_assoc_name[0..-4]
|
1721
|
+
bt_assoc_name[-3] == '_' ? bt_assoc_name[0..-4] : bt_assoc_name[0..-3]
|
1706
1722
|
elsif bt_assoc_name.downcase.end_with?('id') && bt_assoc_name.exclude?('_')
|
1707
1723
|
bt_assoc_name[0..-3] # Make the bold assumption that we can just peel off any final ID part
|
1708
1724
|
else
|
1709
1725
|
"#{bt_assoc_name}_bt"
|
1710
1726
|
end
|
1711
1727
|
end
|
1712
|
-
bt_assoc_name = "
|
1728
|
+
bt_assoc_name = "#{bt_assoc_name}_" if bt_assoc_name == 'attribute'
|
1713
1729
|
|
1714
1730
|
# %%% Temporary schema patch
|
1715
1731
|
for_tbl = fk[1]
|
1732
|
+
fk_namified = ::Brick.namify(fk[1])
|
1716
1733
|
apartment = Object.const_defined?('Apartment') && Apartment
|
1717
|
-
fk[0] = Apartment.default_schema if apartment && apartment.excluded_models.include?(
|
1734
|
+
fk[0] = Apartment.default_schema if apartment && apartment.excluded_models.include?(fk_namified.singularize.camelize)
|
1718
1735
|
fk[1] = "#{fk[0]}.#{fk[1]}" if fk[0] # && fk[0] != ::Brick.default_schema
|
1719
1736
|
bts = (relation = relations.fetch(fk[1], nil))&.fetch(:fks) { relation[:fks] = {} }
|
1720
1737
|
|
@@ -1813,7 +1830,7 @@ module Brick
|
|
1813
1830
|
else
|
1814
1831
|
fk[1]
|
1815
1832
|
end
|
1816
|
-
assoc_hm = hms[hm_cnstr_name] = { is_bt: false, fk: fk[2], assoc_name:
|
1833
|
+
assoc_hm = hms[hm_cnstr_name] = { is_bt: false, fk: fk[2], assoc_name: fk_namified.pluralize, alternate_name: bt_assoc_name,
|
1817
1834
|
inverse_table: inv_tbl, inverse: assoc_bt }
|
1818
1835
|
assoc_hm[:polymorphic] = true if is_polymorphic
|
1819
1836
|
hm_counts = relation.fetch(:hm_counts) { relation[:hm_counts] = {} }
|
@@ -49,8 +49,10 @@ module Brick
|
|
49
49
|
# After we're initialized and before running the rest of stuff, put our configuration in place
|
50
50
|
ActiveSupport.on_load(:after_initialize) do |app|
|
51
51
|
assets_path = File.expand_path("#{__dir__}/../../../../vendor/assets")
|
52
|
-
(app.config.assets
|
53
|
-
|
52
|
+
if (app_config = app.config).respond_to?(:assets)
|
53
|
+
(app_config.assets.precompile ||= []) << "#{assets_path}/images/brick_erd.png"
|
54
|
+
(app.config.assets.paths ||= []) << assets_path
|
55
|
+
end
|
54
56
|
# ====================================
|
55
57
|
# Dynamically create generic templates
|
56
58
|
# ====================================
|
@@ -565,7 +567,7 @@ erDiagram
|
|
565
567
|
end %>
|
566
568
|
<% end
|
567
569
|
def dt_lookup(dt)
|
568
|
-
{ 'integer' => 'int', }[dt] || dt
|
570
|
+
{ 'integer' => 'int', }[dt] || dt&.tr(' ', '_') || 'int'
|
569
571
|
end
|
570
572
|
callbacks.merge({model_short_name => #{@_brick_model.name}}).each do |cb_k, cb_class|
|
571
573
|
cb_relation = ::Brick.relations[cb_class.table_name]
|
@@ -581,8 +583,9 @@ erDiagram
|
|
581
583
|
fk.each do |fk_part| %>
|
582
584
|
<%= \"#\{dt_lookup(cols[fk_part].first)} #\{fk_part} \\\" fk\\\"\".html_safe unless pkeys&.include?(fk_part) %><%
|
583
585
|
end
|
584
|
-
else
|
585
|
-
|
586
|
+
else # %%% Does not yet accommodate polymorphic BTs
|
587
|
+
%>
|
588
|
+
<%= \"#\{dt_lookup(cols[fk]&.first)} #\{fk} \\\" fk\\\"\".html_safe unless pkeys&.include?(fk) %><%
|
586
589
|
end
|
587
590
|
end %>
|
588
591
|
}
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -151,6 +151,20 @@ module Brick
|
|
151
151
|
@pending_models ||= {}
|
152
152
|
end
|
153
153
|
|
154
|
+
# Convert spaces to underscores if the second character and onwards is mixed case
|
155
|
+
def namify(name)
|
156
|
+
if name.include?(' ')
|
157
|
+
# All uppers or all lowers?
|
158
|
+
if name[1..-1] =~ /^[A-Z0-9_]+$/ || name[1..-1] =~ /^[a-z0-9_]+$/
|
159
|
+
name.titleize.tr(' ', '_')
|
160
|
+
else # Mixed uppers and lowers -- just remove existing spaces
|
161
|
+
name.tr(' ', '')
|
162
|
+
end
|
163
|
+
else
|
164
|
+
name
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
154
168
|
def get_bts_and_hms(model)
|
155
169
|
bts, hms = model.reflect_on_all_associations.each_with_object([{}, {}]) do |a, s|
|
156
170
|
next if !const_defined?(a.name.to_s.singularize.camelize) && ::Brick.config.exclude_tables.include?(a.plural_name)
|
@@ -469,9 +483,10 @@ In config/initializers/brick.rb appropriate entries would look something like:
|
|
469
483
|
# %%% TODO: If no auto-controllers then enumerate the controllers folder in order to build matching routes
|
470
484
|
# If auto-controllers and auto-models are both enabled then this makes sense:
|
471
485
|
::Brick.relations.each do |rel_name, v|
|
472
|
-
rel_name = rel_name.split('.').map(
|
486
|
+
rel_name = rel_name.split('.').map { |x| ::Brick.namify(x).underscore }
|
473
487
|
schema_names = rel_name[0..-2]
|
474
488
|
schema_names.shift if ::Brick.apartment_multitenant && schema_names.first == Apartment.default_schema
|
489
|
+
# %%% If more than one schema has the same table name, will need to add a schema name prefix to have uniqueness
|
475
490
|
k = rel_name.last
|
476
491
|
unless existing_controllers.key?(controller_name = k.pluralize)
|
477
492
|
options = {}
|
@@ -545,7 +560,11 @@ ActiveSupport.on_load(:active_record) do
|
|
545
560
|
class << self
|
546
561
|
def execute_sql(sql, *param_array)
|
547
562
|
param_array = param_array.first if param_array.length == 1 && param_array.first.is_a?(Array)
|
548
|
-
connection.
|
563
|
+
if ActiveRecord::Base.connection.adapter_name == 'SQLServer'
|
564
|
+
connection.exec_query(send(:sanitize_sql_array, [sql] + param_array)).rows
|
565
|
+
else
|
566
|
+
connection.execute(send(:sanitize_sql_array, [sql] + param_array))
|
567
|
+
end
|
549
568
|
end
|
550
569
|
end
|
551
570
|
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.
|
4
|
+
version: 1.0.70
|
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-
|
11
|
+
date: 2022-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: fancy_gets
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -264,5 +264,5 @@ requirements: []
|
|
264
264
|
rubygems_version: 3.1.6
|
265
265
|
signing_key:
|
266
266
|
specification_version: 4
|
267
|
-
summary:
|
267
|
+
summary: Create a Rails app from data alone
|
268
268
|
test_files: []
|