Can ActiveRecord::Base.connection.schema_search_path be set per process?

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

?

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?

What you do in one process won't affect the other

Fred

I mean, is there a better solution that fits better Unicorn design?

One more thing guys, could someone please tell me if the ORM will need to re-load its schema( table metadata) on each request if I set the Postgres search path?