Closed
Description
Our software has 1 PostgreSQL schema per company using our software using the Apartments gem most of the time it works but when there is a lot of activity we will get SQL where the apartment gem is selecting the right schema to insert data into, but this gem is saying to use the wrong schema's sequence for the primary key.
For example, we will be doing an import into schema 3 and it will look up the sequence for schema 1 which was used recently by another company
This either results in:
- a very large id in a schema where barely any records exist
- "PG::UniqueViolation: ERROR: duplicate key value violates unique constraint"
neither of which is preferable since the first will lead to the second eventually unless we intervene and the other just stops saving of the new record all together.
It appears that the sequence being passed in here
can be for the wrong schema.For background information Apartments sets the current schema using the search_path and setting it to:
- #{schema_name}, public
Activity