There are several options for handling an application with multiple tenants.
First, you can add a region to your tables (as suggested by Chad Birch - using company_id). For most use cases, this is normal. If you process sensitive data (such as credentials), you must be very careful in your testing to ensure data privacy.
. , , . , . . (capistrano, chef, puppet ..) . , , .
PostgreSQL, - .
PostgresQL . , , , . , .
Rails , .
- :
before_filter :set_app
def set_app
current_app = App.find_by_subdomain(...)
schema = current_app.schema
set_schema_path(schema)
end
def set_schema_path(schema)
connection = ActiveRecord::Base.connection
connection.execute("SET search_path TO #{schema}, #{connection.schema_search_path}")
end
def reset_schema_path
connection = ActiveRecord::Base.connection
connection.execute("SET search_path TO #{connection.schema_search_path}")
end