I am building an app that every company has it own private schema(Postgresql).
For every requisition, I set the Postgres search path in a before_action like this:
ActiveRecord::Base.connection.schema_search_path = 'company_id, public'
If I have multiple Unicorn workers, and one worker ‘A’ set the path, while another work ‘B’ set the path before worker A has finish, I think it will generate some conflict and ‘A’ worker could accidently save/read models from the wrong schema, right?
Is this solution going to fail even if Unicorn is one thread per worker(process)? If this is not the right way, what else can I do? Is it possible for ActiveRecord to set namespaces for tables( Specify schemas in query) like:
Select * from 'company_1'.clients
?