1.

How Do I Use Activerecord Migrations?

Answer»

From Adam Wiggins’s blog:

To use ActiveRecord migrations with Sinatra (or other non-RAILS project), add the following to your Rakefile:

namespace :db do

DESC "Migrate the database"

task(:migrate => :environment) do

ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Migration.verbose = TRUE

ActiveRecord::Migrator.migrate("db/migrate")

end

end

This assumes you have a task called :environment which LOADS your app’s environment (requires the right files, sets up the database connection, etc).

Now you can create a DIRECTORY called db/migrate and fill in your migrations. I usually call the first one 001_init.rb. (I prefer the old sequential method for numbering migrations vs. the datetime method used since Rails 2.1, but either will work.)

From Adam Wiggins’s blog:

To use ActiveRecord migrations with Sinatra (or other non-Rails project), add the following to your Rakefile:

namespace :db do

desc "Migrate the database"

task(:migrate => :environment) do

ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Migration.verbose = true

ActiveRecord::Migrator.migrate("db/migrate")

end

end

This assumes you have a task called :environment which loads your app’s environment (requires the right files, sets up the database connection, etc).

Now you can create a directory called db/migrate and fill in your migrations. I usually call the first one 001_init.rb. (I prefer the old sequential method for numbering migrations vs. the datetime method used since Rails 2.1, but either will work.)



Discussion

No Comment Found