This is a mashup of:
- https://github.com/jwo/ActiveRecord-Without-Rails
- http://exposinggotchas.blogspot.jp/2011/02/activerecord-migrations-without-rails.html
The Gemfile can be configured for a combo of JRuby, JDBC, and Microsoft MSSQL server, as well as for a combo of MRI Ruby (tested on 2.1.2) and SQLite3/Postgres.
Just a simple example of using ActiveRecord migrations without Rails
rake db:create
rake db:migrate
rake db:drop
rake db:rollback
rake db:version
ruby ar-no-rails
Output:
Count of Pages: 0
$ irb
>> require "./ar-no-rails"
=> true
>> Page.new
=> #<Page id: nil, content: nil, published: false>
>> Page.create content: "the-content"
=> #<Page id: 1, content: "the-content", published: false>
For the JRuby/JDBC option, you'll need:
- Java (tested on Java 6)
- JRuby
- A Mssql database server
Note: This project is configured for Rails 3.2.13, because I have to use Java 6 in my current environment. Rails 4.0 would force an upgrade of the JDBC drivers, which require Java 7.
- Download the zip file (or git clone)
- Unzip the archive.
- rename folder to your project name:
mv ActiveRecord-Without-Rails-JDBC-Mssql myproj
cd myproj
bundle install
- configure the database in config/database.yml
rake db:version
# check to see that the db config is correct.rake --tasks
make sure everything is working okay
The database.yml is set up to allow for different environments.
By default it has one environment, development
defined.
If you define a production
environment in the config/database.yml, you can use DATABASE_ENV=production rake db:version
to run against the production environment.
(this is different from the RAILS_ENV you will see in a lot of Active Record migration documentation because... well, we are not using rails here.)
I haven't checked this out yet, but there is a standalone-migrations gem: