Did a little bit of Rails over the weekend for the first time in years. I'm very well versed in Grails so I'm having a few snags regarding the work flow of getting up and running. I created a new project and then I ran the initial rake db:create command. After this is where my questions are.
Following an online guide from the official web site, I created a new domain and gave it some initial properties. Then I ran rake db:migrate. Everything worked fine. I then went and created a new domain that is related to my first domain. And then I started getting all confused because I can't just go into the domain and set the associations like I want (has_many, belongs_to). I also have to manage the migrate files and get those set up correctly, which I've been unable to do.
So, this flow isn't working for me. Although it might be trivial for a more seasoned Rails person. And I can see how rake is a good thing later on down the road, but I'm having a hard time finding its usefulness when just trying to setup your primary domains. So my preferred way of working would be this....
create rails project
when I think they are "pretty close" to what I initially need, then run rake db:migrate. That way, my initial schema file is correct and I don't already have N number of migration files to deal with, nor do I have to manually create migration files for associations up until this point. Does that make sense to anyone?
I should add that part of my confusion with rake is that I created the many side of a one-to-many first. If I had created the 1 side first, it wouldn't have been a big deal. But in the real world, you don't always know exactly what these associations are going to be like right up front.
There's a rake db:rollback command that will reverse the last migration, assuming your migration file included the self.down definition (in many cases the down definition is dropping a table or a couple columns). I've mentioned using vim before - the railsvim plugin has a nice command :Rinvert that will create the down automatically based on the contents of the up. There might be a similar plugin for your editor/IDE of choice.
It's common, while working on a single feature, to bounce back and forth between rake db:migrate (which runs all migrations that have not yet been run) and rake db:rollback to peel back the latest migration until you know you'll got a migration file that is correct.