I have a database that I’ll have to use to build my application. It was modeled by somebody else, but it follows rails conventions. I can easily map it with Active Record.
Can I use migrations to make profound changes to that database or should I keep modeling with the diagrams and exporting it?
Is it a good practice to use migrations or scaffoldings on top of previously modeled databases?
Because after scaffolding I usually get stuck with some kind of evil error messages saying there is a migration trying to create an already existing table. When I delete the problematic migration it only get worst.
For this question: agnostic means use any external modeling tool (GUI SGBD tools).
You can basically go either route. Which one you choose will depend on your development style.
If you do scrum/agile it makes a strong case for doing migrations going forward.
Migrations are also basically part of the big picture for rails and are one of the pieces that makes it work so well in terms of development process. A huge bonus of migrations is that you can create the app with whichever database you want, which is great when moving it to another provider*. However with an db that wasn’t entirely done with migrations there will be two steps to do this – create the initial db ‘up to’ when migrations were started and then continue using them.
Migrations and scaffolding are fine on top of an existing database. Migrations are adding (or removing) new db stuff and scaffolds can create new db record (when migrations are run) and they really help in following the rails standard and creating things like conventionally named.stub tests files.
When first getting used to migrations the error messages and the syntax is pretty maddening but it’s one of those things you’ll get better at over time. There’s a lot of that kinda stuff in rails, i.e. learning all the bits and allowing for weird error messages.
Tools that help out in this area are mySQL Workbench (obv. for mysql) and rubyMine IDE Each of those tools will let you look at an existing database and you can even compare an ERD from mySQL usng the actual tables with rubyMine’s “Model Dependency Diagram” ERD using the information in the rails models.
*however moving the actual data for a live app is another matter.