Reputation: 1239
I am developing a Rails app as one part of a larger solution. This solution will have a mySQL database at its heart, and will have other web services, and connectors attached to it in the future.
We plan to model the data, column names, relationships, according to the rails conventions first. But I am expecting that I will use "establish_connection" to do a table to table mapping to the actual database, and then not use any migrations in rails itself.
So my question is, what is the best practice for attaching a rails app to an external data source for ongoing changes to the data model.
Should I simply update the model.rb files with new fields, and relationships manually, and then allow rails to connect to each table via establish?
Are there any tools that can sync the changed fields and/or relationships that may have changed in the data model? One of the other developers is familiar with Symfony and said they had used something like that. The gems I located for reverse engineering a database were either out of date, or only seemed to stub out the .rb files, not taking into account the fields or the relationships.
Thanks!
Upvotes: 2
Views: 1164
Reputation: 1509
Are there any tools that can sync the changed fields and/or relationships that may have changed in the data model?
By design Ruby on Rail's migrations are intended to incrementally update the Database whenever a change is made to a RoR model.
If I understand you correctly you are interested in documenting changes in the opposite direction; an anti-migration if you will ;). If so then migrations are not a good match for this.
Depending on how your Database changes are documented (you mention that this webapp is a cog in a larger machine) I would recommend abandoning migrations all together as these are intended to make changes to the database. Having said that, I would strongly suggest using migrations to document your database changes.
Back to your issue. I could be wrong on this one by simply running rake db:migrate
(with the absence of any migrations) simply updates the db\schema.rb
file. schema.rb
will always reflect the latest DB structure on invocation. Unfortunatly that is where the magic stops. The Rails webapp will need to be updated to reflect any DB metadata changes if it impacts a model's property names.
Should I simply update the model.rb files with new fields, and relationships manually, and then allow rails to connect to each table via establish?
Yes, IMHO :)
HTH and good luck.
Upvotes: 3