citusdata / activerecord-multi-tenant

Rails/ActiveRecord support for distributed multi-tenant databases like Postgres+Citus
MIT License
717 stars 97 forks source link

Issue when having multiple databases with tables with the same name. #100

Open serch opened 4 years ago

serch commented 4 years ago

There is an issue when having multiple databases with tables with the same name.

The case I experienced is the following: I have 2 databases, the main postgres database that uses the citus extension, and a smaller sqlite db. There are some tables in both databases that have the same name.

I set up Active Record 6 to work with both databases and I use the multi-tenant extension in the main db. When I try to delete a record in the sqlite db the multi-tenant gem picks the model from the main db (that has a table with the same name) and inserts the tenant clause causing the query to fail.

I believe this comes from the fact that the multi tenant models are stored in a hash indexed by table name https://github.com/citusdata/activerecord-multi-tenant/blob/master/lib/activerecord-multi-tenant/multi_tenant.rb#L27-L30

gurkanindibay commented 1 year ago

@serch Could you write a test case for this scenario? It is rather complex.

gurkanindibay commented 1 year ago

We need to create some tests for multiple databases scenario to prioritize it

serch commented 1 year ago

@gurkanindibay I'm really sorry but I can't, I'm swamped atm 🤷‍♂️