jekuno / milia

Easy multi-tenanting for Rails5 (or Rails4) + Devise
MIT License
341 stars 72 forks source link

Making application-wide changes to tenanted models #50

Closed Chris-VorData closed 7 years ago

Chris-VorData commented 9 years ago

Is there a way, say, from a rake task, to make changes to all instances of a tenanted model?

From my reading of the docs it seems that I might have to loop over all the tenants, set each one as the current tenant, and operate on each of their associated tenanted models.

Is there a better way?

dsaronin commented 9 years ago

No. I also faced this issue with my web application and have concluded that the safer, correct, and preferred way is to loop through each tenant and have the rake task do what's necessary for that tenant alone.

BUT, there have been instances where it was necessary to do entire database-related functions, such as after I refactored the app and did some major housekeeping. In that case, I did not use rake tasks, but rather made database-wide adjustments using execute SQL statements. But even then, I made sure that tenanted control was maintained via the SQL statement.

On Thu Feb 19 2015 at 11:07:03 PM Chris-VorData notifications@github.com wrote:

Is there a way, say, from a rake task, to make changes to all instances of a tenanted model? From my reading of the docs it seems that I might have to loop over all the tenants and operate on each of their associated tenanted models. Is there a better way?

— Reply to this email directly or view it on GitHub https://github.com/dsaronin/milia/issues/50.

jekuno commented 7 years ago

Added according info to the README