Skip to content

Commit

Permalink
fix #18 - multi-schema Postgres DBs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorin Thwaits committed Apr 6, 2024
1 parent a197692 commit 68e6a98
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
brick (1.0.212)
brick (1.0.214)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ https://user-images.githubusercontent.com/5301131/184541537-99b37fc6-ed5e-46e9-9
| Version | Documentation |
| -------------- | ----------------------------------------------------- |
| Unreleased | https://github.com/lorint/brick/blob/master/README.md |
| 1.0.212 | https://github.com/lorint/brick/blob/v1.0/README.md |
| 1.0.214 | https://github.com/lorint/brick/blob/v1.0/README.md |

One core goal behind The Brick is to adhere as closely as possible to Rails conventions. As
such, models, controllers, and views are treated independently. You can use this tool to only
Expand Down
2 changes: 1 addition & 1 deletion docs/bug_report_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
source 'https://rubygems.org'
gem 'activerecord', '5.2.6'
gem 'minitest', '5.15'
gem 'brick', '1.0.212'
gem 'brick', '1.0.214'
gem 'sqlite3'
end

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_5.0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.212)
brick (1.0.214)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_5.1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.212)
brick (1.0.214)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_5.2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.212)
brick (1.0.214)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_6.0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.212)
brick (1.0.214)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_6.1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.212)
brick (1.0.214)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_7.0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.212)
brick (1.0.214)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_7.1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.212)
brick (1.0.214)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
19 changes: 14 additions & 5 deletions lib/brick/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def real_model(params)
end
end

# Accommodate STI
def real_singular(params)
real_model = real_model(params)
[real_model, real_model.name.underscore.split('/').last]
end

def json_column?(col)
col.type == :json || ::Brick.config.json_columns[table_name]&.include?(col.name) ||
(
Expand Down Expand Up @@ -2474,7 +2480,8 @@ def skip_bullet
send(params_name_sym)
rescue
end
new_params ||= model.attribute_names.each_with_object({}) do |a, s|
real_model, singular_table_name = model.real_singular(params)
new_params ||= real_model.attribute_names.each_with_object({}) do |a, s|
if (val = params["__#{a}"])
# val = case new_obj.class.column_for_attribute(a).type
# when :datetime, :date, :time, :timestamp
Expand All @@ -2485,7 +2492,7 @@ def skip_bullet
s[a] = val
end
end
if (new_obj = model.new(new_params)).respond_to?(:serializable_hash)
if (new_obj = real_model.new(new_params)).respond_to?(:serializable_hash)
# Convert any Filename objects with nil into an empty string so that #encode can be called on them
new_obj.serializable_hash.each do |k, v|
new_obj.send("#{k}=", ::ActiveStorage::Filename.new('')) if v.is_a?(::ActiveStorage::Filename) && !v.instance_variable_get(:@filename)
Expand Down Expand Up @@ -2518,13 +2525,13 @@ def skip_bullet
created_obj.send("#{inh_col}=", model.name)
end
created_obj.save
@_lookup_context.instance_variable_set(:@_brick_model, model)
@_lookup_context.instance_variable_set(:@_brick_model, real_model)
if created_obj.errors.empty?
instance_variable_set("@#{table_name}".to_sym, created_obj)
instance_variable_set("@#{singular_table_name}".to_sym, created_obj)
index
render :index
else # Surface errors to the user in a flash message
instance_variable_set("@#{real_model.name.underscore}".to_sym, created_obj)
instance_variable_set("@#{singular_table_name}".to_sym, created_obj)
flash.now.alert = (created_obj.errors.errors.map { |err| "<b>#{err.attribute}</b> #{err.message}" }.join(', '))
new
render :new
Expand All @@ -2543,6 +2550,7 @@ def skip_bullet
code << " end\n"
self.define_method :edit do
_schema, @_is_show_schema_list = ::Brick.set_db_schema(params)
_, singular_table_name = model.real_singular(params)
instance_variable_set("@#{singular_table_name}".to_sym, find_obj)
add_csp_hash
end
Expand Down Expand Up @@ -2570,6 +2578,7 @@ def skip_bullet
# return
end

_, singular_table_name = model.real_singular(params)
instance_variable_set("@#{singular_table_name}".to_sym, (obj = find_obj))
upd_params = send(params_name_sym)
json_overrides = ::Brick.config.json_columns&.fetch(table_name, nil)
Expand Down
2 changes: 1 addition & 1 deletion lib/brick/frameworks/rails/form_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def brick_header(rel, klass, show_row_count, show_erd_button, show_in_app_button

# -----------------------------------------------------------------------------------------------
def set_grid_javascript(klass, pk, show_new_button = nil, row_count = nil, total_row_count = nil)
table_name = klass.table_name
table_name = klass.table_name.split('.').last

# Javascript for brick_grid and brick_constellation
grid_scripts = (@_brick_javascripts ||= {})[:grid_scripts] = +''
Expand Down
2 changes: 1 addition & 1 deletion lib/brick/version_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Brick
module VERSION
MAJOR = 1
MINOR = 0
TINY = 212
TINY = 214

# PRE is nil unless it's a pre-release (beta, RC, etc.)
PRE = nil
Expand Down
2 changes: 1 addition & 1 deletion v1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ https://user-images.githubusercontent.com/5301131/184541537-99b37fc6-ed5e-46e9-9
| Version | Documentation |
| -------------- | ----------------------------------------------------- |
| Unreleased | https://github.com/lorint/brick/blob/master/README.md |
| 1.0.212 | https://github.com/lorint/brick/blob/v1.0/README.md |
| 1.0.214 | https://github.com/lorint/brick/blob/v1.0/README.md |

One core goal behind The Brick is to adhere as closely as possible to Rails conventions. As
such, models, controllers, and views are treated independently. You can use this tool to only
Expand Down

0 comments on commit 68e6a98

Please sign in to comment.