[psql] not cleaning with same database, different schemas
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu từ lookup_from_connection_pool, được gọi từ connection_class, và so sánh nó với hai cấu hình ActiveRecord được hiển thị trong spec_helper. Tái hiện việc dọn dẹp trên cùng một cơ sở dữ liệu với các giá trị schema_search_path khác nhau, sau đó xác minh rằng mỗi cleaner chọn kết nối tương ứng và hành vi này được kiểm thử bằng một regression test.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hi. I've been having trouble with making database cleaner work when trying to delete data from different psql schemas, but in the same database.
database.yml:
test: &test
adapter: postgresql
database: test_project
host: localhost
port: 6432
user: postgres
test_non_public:
<<: *test
schema_search_path: non_public
What I did in spec_helper:
config.before(:suite) do
DatabaseCleaner.clean_with :deletion
DatabaseCleaner[:active_record, connection: :test_non_public].clean_with :deletion
end
From what I understand it happens because of this code:
def lookup_from_connection_pool
if ::ActiveRecord::Base.respond_to?(:descendants)
database_name = connection_hash["database"] || connection_hash[:database]
models = ::ActiveRecord::Base.descendants
models.detect { |m| m.connection_pool.spec.config[:database] == database_name }
end
end
This method is invoked from connection_class, and because both connection "test" and "test_non_public" are configured to connect to the same database it ends up returning a model with an incorrect connection. This could be solved (I think) by adding one more condition, so that besides checking for the database_name it also checks for the schema_search_path.
While writing this issue I ended up editing the code as follows and it worked:
def lookup_from_connection_pool
if ::ActiveRecord::Base.respond_to?(:descendants)
database_name = connection_hash["database"] || connection_hash[:database]
schema_search_path = connection_hash["schema_search_path"] || connection_hash[:schema_search_path]
models = ::ActiveRecord::Base.descendants
models.detect do |m|
m.connection_pool.spec.config[:database] == database_name &&
m.connection_pool.spec.config[:schema_search_path] == schema_search_path
end
end
end
Does it look like a good fix? If not how should I approach this problem so that I can solve this issue?
Thanks
- Ngôn ngữ chính
- Ruby
- Star
- 76
- Fork
- 76
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của DatabaseCleaner/database_cleaner-active_record
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
DatabaseCleaner/database_cleaner-active_record#128 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
DatabaseCleaner/database_cleaner-active_record#127 · 3 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
-
Parallelized truncates Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Tất cả issue của DatabaseCleaner/database_cleaner-active_record
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
ai-generated
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
hanami/hanami-cli#449 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
hanami/hanami-router#310 ·