brick 1.0.110 → 1.0.111
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brick/extensions.rb +32 -3
- data/lib/brick/frameworks/rails/engine.rb +32 -34
- data/lib/brick/frameworks/rails/form_tags.rb +1 -0
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +10 -5
- 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: cb97e4a946526ed99a24e67b1e65d5f6490a40c97dc170dd0680166b087d1ccb
|
4
|
+
data.tar.gz: 48d9c4f2afcd737d9a857f8c771448639c1b0d2d568dc966bbe4b85a97cb4610
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 383d9996affbbd4fa049ab125490879143299a5477e98f921d450ea6b5b466d66a4cd210aac8db9c105a6eaf5f10eae8ac181d84d78fb6fc0b4c4151ac9dcee3
|
7
|
+
data.tar.gz: b9902fc959b0de870ef5c402fe75e76d939d0c7c5abc7b8d3c16451b87f56929eb6e329153c6b5697936f10228752ba3b2f5f2a7de6aa5c9c77c105c34dd2cfa
|
data/lib/brick/extensions.rb
CHANGED
@@ -2019,6 +2019,21 @@ end.class_exec do
|
|
2019
2019
|
# .default_schema are specified then we can work with non-tenanted models more appropriately
|
2020
2020
|
if (apartment = Object.const_defined?('Apartment')) &&
|
2021
2021
|
File.exist?(apartment_initializer = ::Rails.root.join('config/initializers/apartment.rb'))
|
2022
|
+
require 'apartment/adapters/abstract_adapter'
|
2023
|
+
Apartment::Adapters::AbstractAdapter.class_exec do
|
2024
|
+
if instance_methods.include?(:process_excluded_models)
|
2025
|
+
def process_excluded_models
|
2026
|
+
# All other models will share a connection (at Apartment.connection_class) and we can modify at will
|
2027
|
+
Apartment.excluded_models.each do |excluded_model|
|
2028
|
+
begin
|
2029
|
+
process_excluded_model(excluded_model)
|
2030
|
+
rescue NameError => e
|
2031
|
+
(@bad_models ||= []) << excluded_model
|
2032
|
+
end
|
2033
|
+
end
|
2034
|
+
end
|
2035
|
+
end
|
2036
|
+
end
|
2022
2037
|
unless @_apartment_loaded
|
2023
2038
|
load apartment_initializer
|
2024
2039
|
@_apartment_loaded = true
|
@@ -2057,13 +2072,27 @@ end.class_exec do
|
|
2057
2072
|
schema = possible_schema
|
2058
2073
|
orig_schema = ActiveRecord::Base.execute_sql('SELECT current_schemas(true)').first['current_schemas'][1..-2].split(',')
|
2059
2074
|
ActiveRecord::Base.execute_sql("SET SEARCH_PATH = ?", schema)
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2075
|
+
# When testing, just find the most recently-created schema
|
2076
|
+
elsif begin
|
2077
|
+
Rails.env == 'test' ||
|
2078
|
+
ActiveRecord::Base.execute_sql("SELECT value FROM ar_internal_metadata WHERE key='environment';").first&.fetch('value', nil) == 'test'
|
2079
|
+
rescue
|
2080
|
+
end
|
2081
|
+
::Brick.default_schema = ::Brick.apartment_default_tenant
|
2082
|
+
::Brick.test_schema = schema = ::Brick.db_schemas.to_a.sort { |a, b| b.last[:dt] <=> a.last[:dt] }.first.first
|
2083
|
+
if possible_schema.blank?
|
2084
|
+
puts "While running tests, using the most recently-created schema, #{schema}."
|
2085
|
+
else
|
2086
|
+
puts "While running tests, had noticed in the brick.rb initializer that the line \"::Brick.schema_behavior = ...\" refers to a schema called \"#{possible_schema}\" which does not exist. Reading table structure from the most recently-created schema, #{schema}."
|
2087
|
+
end
|
2063
2088
|
orig_schema = ActiveRecord::Base.execute_sql('SELECT current_schemas(true)').first['current_schemas'][1..-2].split(',')
|
2089
|
+
::Brick.config.schema_behavior = { multitenant: {} } # schema_to_analyse: [schema]
|
2064
2090
|
ActiveRecord::Base.execute_sql("SET SEARCH_PATH = ?", schema)
|
2065
2091
|
else
|
2066
2092
|
puts "*** In the brick.rb initializer the line \"::Brick.schema_behavior = ...\" refers to schema(s) called #{possible_schemas.map { |s| "\"#{s}\"" }.join(', ')}. No mentioned schema exists. ***"
|
2093
|
+
if ::Brick.db_schemas.key?(::Brick.apartment_default_tenant)
|
2094
|
+
::Brick.default_schema = schema = ::Brick.apartment_default_tenant
|
2095
|
+
end
|
2067
2096
|
end
|
2068
2097
|
end
|
2069
2098
|
when 'Mysql2', 'Trilogy'
|
@@ -36,11 +36,12 @@ module Brick
|
|
36
36
|
// This PageTransitionEvent fires when the page first loads, as well as after any other history
|
37
37
|
// transition such as when using the browser's Back and Forward buttons.
|
38
38
|
window.addEventListener(\"pageshow\", linkSchemas);
|
39
|
-
var brickSchema
|
39
|
+
var brickSchema,
|
40
|
+
brickTestSchema;
|
40
41
|
function linkSchemas() {
|
41
42
|
var schemaSelect = document.getElementById(\"schema\");
|
42
43
|
var tblSelect = document.getElementById(\"tbl\");
|
43
|
-
if (tblSelect) { // Always present
|
44
|
+
if (tblSelect) { // Always present for Brick pages
|
44
45
|
// Used to be: var i = # {::Brick.config.path_prefix ? '0' : 'schemaSelect ? 1 : 0'},
|
45
46
|
var changeoutList = changeout(location.href);
|
46
47
|
for (var i = 0; i < changeoutList.length; ++i) {
|
@@ -53,32 +54,32 @@ function linkSchemas() {
|
|
53
54
|
if (brickSchema) lhr = changeout(lhr, \"_brick_schema\", schemaSelect.value);
|
54
55
|
location.href = lhr;
|
55
56
|
});
|
56
|
-
}
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
58
|
+
if (schemaSelect) { // First drop-down is only present if multitenant
|
59
|
+
if (brickSchema = changeout(location.href, \"_brick_schema\")) {
|
60
|
+
[... document.getElementsByTagName(\"A\")].forEach(function (a) { a.href = changeout(a.href, \"_brick_schema\", brickSchema); });
|
61
|
+
}
|
62
|
+
if (schemaSelect.options.length > 1) {
|
63
|
+
schemaSelect.value = brickSchema || brickTestSchema || \"public\";
|
64
|
+
schemaSelect.addEventListener(\"change\", function () {
|
65
|
+
// If there's an ID then remove it (trim after selected table)
|
66
|
+
location.href = changeout(location.href, \"_brick_schema\", this.value, tblSelect.value);
|
67
|
+
});
|
68
|
+
}
|
68
69
|
}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
form.
|
75
|
-
|
76
|
-
|
77
|
-
|
70
|
+
tblSelect.focus();
|
71
|
+
|
72
|
+
[... document.getElementsByTagName(\"FORM\")].forEach(function (form) {
|
73
|
+
if (brickSchema)
|
74
|
+
form.action = changeout(form.action, \"_brick_schema\", brickSchema);
|
75
|
+
form.addEventListener('submit', function (ev) {
|
76
|
+
[... ev.target.getElementsByTagName(\"SELECT\")].forEach(function (select) {
|
77
|
+
if (select.value === \"^^^brick_NULL^^^\") select.value = null;
|
78
|
+
});
|
79
|
+
return true;
|
78
80
|
});
|
79
|
-
return true;
|
80
81
|
});
|
81
|
-
}
|
82
|
+
}
|
82
83
|
};
|
83
84
|
"
|
84
85
|
|
@@ -359,15 +360,11 @@ window.addEventListener(\"popstate\", linkSchemas);
|
|
359
360
|
(is_status = ::Brick.config.add_status && args[0..1] == ['status', ['brick_gem']]) ||
|
360
361
|
(is_orphans = ::Brick.config.add_orphans && args[0..1] == ['orphans', ['brick_gem']]) ||
|
361
362
|
(is_crosstab = args[0..1] == ['crosstab', ['brick_gem']])
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
return possible_template
|
366
|
-
end
|
367
|
-
rescue
|
363
|
+
begin
|
364
|
+
if (possible_template = _brick_find_template(*args, **options))
|
365
|
+
return possible_template
|
368
366
|
end
|
369
|
-
|
370
|
-
return possible_template
|
367
|
+
rescue
|
371
368
|
end
|
372
369
|
# Used to also have: ActionView.version < ::Gem::Version.new('5.0') &&
|
373
370
|
model_name = (args[1].is_a?(Array) ? set_brick_model(args) : nil)&.name
|
@@ -851,8 +848,9 @@ document.querySelectorAll(\"input[type=submit][data-confirm]\").forEach(function
|
|
851
848
|
});
|
852
849
|
});
|
853
850
|
|
854
|
-
#{JS_CHANGEOUT}
|
855
|
-
|
851
|
+
#{JS_CHANGEOUT}#{
|
852
|
+
"\nbrickTestSchema = \"#{::Brick.test_schema}\";" if ::Brick.test_schema
|
853
|
+
}
|
856
854
|
// Snag first TR for sticky header
|
857
855
|
var grid = document.getElementById(\"#{table_name}\");
|
858
856
|
#{table_name}HtColumns = grid && [grid.getElementsByTagName(\"TR\")[0]];
|
@@ -201,6 +201,7 @@ module Brick::Rails::FormTags
|
|
201
201
|
end
|
202
202
|
filter = "?#{filter_parts.join('&')}" if filter_parts.present?
|
203
203
|
app_routes = Rails.application.routes # In case we're operating in another engine, reference the application since Brick routes are placed there.
|
204
|
+
relation = ::Brick.relations.fetch(rel_name || args.first.table_name, nil)
|
204
205
|
if (klass_or_obj&.is_a?(Class) && klass_or_obj < ActiveRecord::Base) ||
|
205
206
|
(klass_or_obj&.is_a?(ActiveRecord::Base) && klass_or_obj.new_record? && (klass_or_obj = klass_or_obj.class))
|
206
207
|
path = (proc = kwargs[:index_proc]) ? proc.call(klass_or_obj, relation) : "#{app_routes.path_for(controller: klass_or_obj.base_class._brick_index(nil, '/', relation), action: :index)}#{filter}"
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -135,7 +135,8 @@ module Brick
|
|
135
135
|
@existing_stis ||= Brick.config.sti_namespace_prefixes.each_with_object({}) { |snp, s| s[snp.first[2..-1]] = snp.last unless snp.first.end_with?('::') }
|
136
136
|
end
|
137
137
|
|
138
|
-
attr_accessor :default_schema, :db_schemas, :
|
138
|
+
attr_accessor :default_schema, :db_schemas, :test_schema,
|
139
|
+
:routes_done, :is_oracle, :is_eager_loading, :auto_models, :initializer_loaded
|
139
140
|
|
140
141
|
def set_db_schema(params = nil)
|
141
142
|
# If Apartment::Tenant.current is not still the default (usually 'public') then an elevator has brought us into
|
@@ -148,6 +149,10 @@ module Brick
|
|
148
149
|
::Brick.db_schemas&.key?(schema)
|
149
150
|
Apartment::Tenant.switch!(schema)
|
150
151
|
schema
|
152
|
+
elsif ::Brick.test_schema
|
153
|
+
is_show_schema_list = true
|
154
|
+
Apartment::Tenant.switch!(::Brick.test_schema)
|
155
|
+
::Brick.test_schema
|
151
156
|
else
|
152
157
|
current_schema # Just return the current schema
|
153
158
|
end
|
@@ -1497,12 +1502,12 @@ module ActiveRecord
|
|
1497
1502
|
# entry in your .select().
|
1498
1503
|
# More information: https://discuss.rubyonrails.org/t/includes-and-select-for-joined-data/81640
|
1499
1504
|
def apply_column_aliases(relation)
|
1500
|
-
if (
|
1505
|
+
if !(@join_root_alias = relation.select_values.empty?) &&
|
1506
|
+
relation.select_values.first.to_s == '_brick_eager_load'
|
1507
|
+
relation.select_values.shift
|
1501
1508
|
used_cols = {}
|
1502
1509
|
# Find and expand out all column names being used in select(...)
|
1503
|
-
new_select_values =
|
1504
|
-
next if col == '_brick_eager_load'
|
1505
|
-
|
1510
|
+
new_select_values = relation.select_values.map(&:to_s).each_with_object([]) do |col, s|
|
1506
1511
|
if col.include?(' ') # Some expression? (No chance for a simple column reference)
|
1507
1512
|
s << col # Just pass it through
|
1508
1513
|
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.111
|
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-
|
11
|
+
date: 2023-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|