Hi 👋 I'm looking for some help and would really appreciate any feedback. I'm working on an established Rails app, we have a new use-case in the business and I'm considering how to approach it in code. We currently have a
Charity model in the app, it's widely used and has a lot of associations, but we've tried not to overload it (we use services classes to try and prevent the model having to do too much other than represent the charity).
We will now have organisations coming into the app that are not registered charities, but which will have much of the same functionality (they're social enterprises, community interest companies etc). Long term, as they're so similar I want them all to be instances of
Organisation (we may well start working with other types of orgs in the future).
What's the best way to go about that transition from
Organisation? I don't really like the idea of a single ‘rename everything’ project as the risk is pretty high. Although maybe that is viable if there are great tools out there? I'm worried about missing something and the mass-renaming in tests meaning that it's not caught
My first thought is to create
Organisation as a parent class of
Charity, but add nothing to it and set it's
table_name to 'charities' (or perhaps vice versa, not sure which way around would be best to do that).
Then begin the long job of transitioning all uses of
Organisation, once that's done, then creating a database table called
organisations (while still having the
Organisation class point at the
charities table). We then add callbacks to
Charity to keep the two tables in sync (so as a charity is updated or added, it updates the organisations table too). Once all that's done, we can then point the
Organisation class at the 'organisations' table and we're done, so we can remove the
Charity class and
charities table altogether.
I hope that makes some sense. If anyone has been through a project like that, I'd love to hear what worked, what didn't work for you. Thanks!