I have a fat multi-tenant Rails app on Apache + mod_passenger that outputs product prices from a PostgreSQL table as follows:
Table "public.products"
Column | Type
id | bigint
name | character varying(100)
price | numeric(8,2)
Then inside products.rb I have...
class Product < PostgresDatabase
self.table_name = "products"
# ... yadda yadda
end
What I want is to partition the "products" table in a very specific way so that I end up with something like products_TENANT-ID for each tenant (basically views of the main products table but that's another story) and be able to query like this:
Products.for_tenant(TENANT-ID).where(:name => "My product")......
I figure I can just create a method:
class Product < PostgresDatabase
self.table_name = "products"
# ... yadda yadda
def for_tenant(tid)
self.table_name = "products_" + tid.to_s
self
end
end
But what kind of impact could this have on the application considering there's lots of traffic (thousands of requests per second)? Is there something I am missing? Should I try a different strategy?
Thank you very much for any feedback/thoughts!