forest_admin_datasource_active_record 1.24.8 → 1.24.9
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/forest_admin_datasource_active_record/collection.rb +13 -11
- data/lib/forest_admin_datasource_active_record/datasource.rb +24 -3
- data/lib/forest_admin_datasource_active_record/utils/query.rb +1 -1
- data/lib/forest_admin_datasource_active_record/utils/query_aggregate.rb +1 -1
- data/lib/forest_admin_datasource_active_record/version.rb +1 -1
- 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: e5c7dab30299e9c16bc2b67188d771da65d7ceaf88a66d2eace9fd57ccb9e9bf
|
|
4
|
+
data.tar.gz: 93d8127540c4be84e32f9244b7233592129260fabe2f05e3eea36ffe0c1d13b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7630f9b61c11049f854d959138c3dc0071bc3fbe9d8ecaa63ae2eea73fcc77986638dd35bee3ee6d7c3d70714037679916458b1e7949661d7eeab08eaa835a4f
|
|
7
|
+
data.tar.gz: b5c521c0dbc2bd15678f8011020f4d2eba04d0f503de792bd0d3d3ad82024b79a0ac6abf04242d5d873872b8e8da029a572056ff73ddae1ea36151cd8d907f95
|
|
@@ -18,7 +18,10 @@ module ForestAdminDatasourceActiveRecord
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def native_driver
|
|
21
|
-
ActiveRecord::Base.
|
|
21
|
+
connection = ActiveRecord::Base.connection_pool.lease_connection
|
|
22
|
+
yield connection
|
|
23
|
+
ensure
|
|
24
|
+
ActiveRecord::Base.connection_pool.release_connection
|
|
22
25
|
end
|
|
23
26
|
|
|
24
27
|
def list(_caller, filter, projection)
|
|
@@ -224,16 +227,15 @@ module ForestAdminDatasourceActiveRecord
|
|
|
224
227
|
through_model_name = association.join_table.classify
|
|
225
228
|
|
|
226
229
|
# Check if the join table exists and has an 'id' column
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
end
|
|
230
|
+
has_id_column = ActiveRecord::Base.connection_pool.with_connection do |conn|
|
|
231
|
+
conn.table_exists?(join_table) && conn.columns(join_table).any? { |col| col.name == 'id' }
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
if has_id_column
|
|
235
|
+
begin
|
|
236
|
+
through_model_name.constantize
|
|
237
|
+
rescue NameError
|
|
238
|
+
create_virtual_habtm_model(association, through_model_name)
|
|
237
239
|
end
|
|
238
240
|
end
|
|
239
241
|
|
|
@@ -34,8 +34,10 @@ module ForestAdminDatasourceActiveRecord
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
begin
|
|
37
|
-
|
|
38
|
-
pool =
|
|
37
|
+
connection_spec = @live_query_connections[connection_name]
|
|
38
|
+
pool = @native_query_pools[connection_spec]
|
|
39
|
+
|
|
40
|
+
raise "No connection pool found for '#{connection_spec}'" unless pool
|
|
39
41
|
|
|
40
42
|
result = pool.with_connection do |conn|
|
|
41
43
|
conn.exec_query(query, "SQL Native Query on '#{connection_name}'", binds)
|
|
@@ -87,7 +89,7 @@ module ForestAdminDatasourceActiveRecord
|
|
|
87
89
|
|
|
88
90
|
def init_orm(db_config)
|
|
89
91
|
ActiveRecord::Base.establish_connection(db_config)
|
|
90
|
-
current_config = ActiveRecord::Base.
|
|
92
|
+
current_config = ActiveRecord::Base.connection_pool.db_config.env_name
|
|
91
93
|
configurations = ActiveRecord::Base.configurations
|
|
92
94
|
.configurations
|
|
93
95
|
.group_by(&:env_name)
|
|
@@ -98,6 +100,25 @@ module ForestAdminDatasourceActiveRecord
|
|
|
98
100
|
end.to_h
|
|
99
101
|
|
|
100
102
|
@connection_drivers = configurations[current_config]
|
|
103
|
+
init_native_query_pools(current_config)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def init_native_query_pools(env_name)
|
|
107
|
+
@native_query_pools = {}
|
|
108
|
+
@live_query_connections.each_value do |spec_name|
|
|
109
|
+
next if @native_query_pools.key?(spec_name)
|
|
110
|
+
|
|
111
|
+
db_config = ActiveRecord::Base.configurations.configs_for(
|
|
112
|
+
env_name: env_name,
|
|
113
|
+
name: spec_name
|
|
114
|
+
)
|
|
115
|
+
next unless db_config
|
|
116
|
+
|
|
117
|
+
@native_query_pools[spec_name] = ActiveRecord::Base.connection_handler.establish_connection(
|
|
118
|
+
db_config,
|
|
119
|
+
owner_name: "ForestAdminNativeQuery::#{spec_name}"
|
|
120
|
+
)
|
|
121
|
+
end
|
|
101
122
|
end
|
|
102
123
|
|
|
103
124
|
def build_habtm(model)
|
|
@@ -149,7 +149,7 @@ module ForestAdminDatasourceActiveRecord
|
|
|
149
149
|
end
|
|
150
150
|
|
|
151
151
|
# Use database-specific regex syntax
|
|
152
|
-
adapter_name = @collection.model.
|
|
152
|
+
adapter_name = @collection.model.connection_pool.db_config.adapter.downcase
|
|
153
153
|
table_and_column = "#{arel_attr.relation.name}.#{arel_attr.name}"
|
|
154
154
|
regex_clause = case adapter_name
|
|
155
155
|
when 'postgresql'
|
|
@@ -72,7 +72,7 @@ module ForestAdminDatasourceActiveRecord
|
|
|
72
72
|
private
|
|
73
73
|
|
|
74
74
|
def date_trunc_sql(operation, field, original_field_name = nil)
|
|
75
|
-
adapter_name = @collection.model.
|
|
75
|
+
adapter_name = @collection.model.connection_pool.db_config.adapter.downcase
|
|
76
76
|
operation = operation.to_s.downcase
|
|
77
77
|
|
|
78
78
|
unless VALID_DATE_OPERATIONS.include?(operation)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: forest_admin_datasource_active_record
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.24.
|
|
4
|
+
version: 1.24.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matthieu
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2026-02
|
|
12
|
+
date: 2026-03-02 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activerecord
|