ActiveRecord y Sinatra

El siguiente texto esta tomado de la lista Sinatra Q&A How do I use ActiveRecord migrations?

To use ActiveRecord’s 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.)



Subsecciones
Casiano Rodriguez León 2015-01-07