views:

365

answers:

2

Hi, I am trying to learn Rails by working with different packages (ActiveRecord, ActiveSupport) without rails gem.

I can't figure out how to create a database with three classes, though. Here's my rakefile:

require 'rubygems'
require 'activerecord'   
require 'yaml'   

task :default => :migrate   

desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"   
task :migrate => :environment do   
  ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )   
end   

task :environment do   
  ActiveRecord::Base.establish_connection(YAML::load(File.open('database.yml')))   
  ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a'))   
end

And I have three files:

001_create_appearances.rb 001_create_movies.rb 001_create_actors.rb

Which I have all run successfully in the past, each one just inherits from ActiveRecord::Migration and does self.up/self.down.

I have, however, problem, that when I run rake, it returns "Multiple migrations have the version number 1". Should I pack all the migrations into one file, like 001_create_database.rb?

Is there a manual somewhere that describes how these versions work?

I tried reading source of migrator.rb but couldn't find where up_without_benchmarks/down_without_benchmarks where located.

A: 

Oh, wait, I think I got. I marked files 001_, 002_, and 003__. I see.

mannicken
+2  A: 

Right. Migrations must start with unique numbers in order that you wish for them to be executed. By default in rails 2.x this number will be a representation of the current date and time.

The reason for this is to allow developers to easily run and undo migrations. Timestamps are used instead of sequential integers in case two developers simultaneously create a new migration (Which would result in them having the same number when they are pushed to a version control system).

Gdeglin