Say, for example, I am running a Rails application that has static content that is relevant to all my environments, but I still want to be able to change if necessary. Examples: statuses, quiz questions, wine varieties, etc. There is a relationship between your user-generated content and this static data, and I want to be able to modify it if necessary, so it should be stored in a database.
I have always dealt with migrations to synchronize my team and all my environments.
I had people who dogmatically say that migration should only be for structural changes in the database. I see the point.
My counterargument is that this mainly βstaticβ data is necessary for the application to function, and if I do not update it automatically (everyone is already trained to start the migration), someone will have crashes and search around what problem before they find out that a new required field has been added to the table and that they need to import something. So I just do it during the migration process. It also simplifies and simplifies deployment.
The way I specifically did this is to update my test fixture files with good data (which has a side effect, allowing me to write more realistic tests) and re-import it when necessary. I do this with connection.execute "some SQL" and not with models, because I found that Model.reset_column_information + a bunch of Model.create sometimes works if everything is updated immediately, but eventually explode on my face when I will push a few weeks later because I would have newer model checks that would contradict the 2-week carryover.
Anyway, I think this YAML + SQL process works to explode a little less, but I also find it pretty kludgey. I was wondering how people manage such data. Are there any other tricks in Rails? Are there gems for managing static data?
source share