I’m fairly certain I am using them a little unconventionally, and just wondered – am I alone? Before going on I will add that I’m able to use them this way because a) the app is still in development, and b) I am the only developer.
Given I started on the app at the beginning of this year and have worked on it an hour or two a day (give or take a few weeks here and there!) since, notice anything unusual?
That’s right – they are mostly migrations for creating tables. But how do I modify my tables/schema?
Easy, (depending on the migration) I just open it, change it, save it. Then run:
If the migration contains indexes that I need to change (or anything more complex that the Rails ‘change’ method can’t handle) then I just do the edit after running rake db:migrate VERSION=0.
In my rake db:populate file, I clear out tables before refilling them with the data I need to work with, eg:
namespace :db do
desc "Erase and repopulate"
task :populate => :environment do
User.create do |user|
user.email = "email@example.com"
user.name = "Me"
user.password = "secret"
user.password_confirmation = "secret"
I just feel it is tidier, and easier to work with. Whenever I want to see what my table consists of I go straight to the migration, instead of the schema file (although not always – depends if I know I want to change something or not) and of course I get a fresh DB with all my defaults. Also, I think from simplicity comes a certain degree of safety – but then I am an overcautious person.
To date I haven’t found any negatives doing it this way – but then this is my first Rails app… maybe you can find a cause for concern that I may have overlooked? Or am I not alone in how I’m using them…