Arfy

Allow use ActiveRecord and Migration from Rails

(even if you don't use all Rails stack)

This is a very early implementation, so any comments are wellcome, but we are developing this on a daily basis. Huge changes in few days are expected.

gem install arfy

On your project's folder, put a Rakefile.rb with:

require 'arfy'

Check if you are ready to go:

rake -T

You should see some familiar tasks:

rake db:create           # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
rake db:drop             # Drops the database for the current Rails.env (use db:drop:all to drop all databases)
rake db:fixtures:load    # Load fixtures into the current environment's database.
rake db:migrate          # Migrate the database (options: VERSION=x, VERBOSE=false).
rake db:migrate:status   # Display status of migrations
rake db:rollback         # Rolls the schema back to the previous version (specify steps w/ STEP=n).
rake db:schema:dump      # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load      # Load a schema.rb file into the database
rake db:seed             # Load the seed data from db/seeds.rb
rake db:setup            # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
rake db:structure:dump   # Dump the database structure to an SQL file
rake db:version          # Retrieves the current schema version number
rake generate:migration  # Generate migration (options NAME=migration_file_name, OUTDIR=db/migrate, TARGET=environment)
rake rails_env           # Changes the environment (options TARGET=development) - use your's configuration name on database.yml

The goal here is to use the Migrations. You can use the Rails conventions and create two dirs on your project: your_project/ db/migrate/ config/

To generate a skeleton for a migration, use the task:

rake generate:migration NAME=my-MigrationName

(The awkward name here is just to illustrate that the task will create a file with a pretty name for you, something like: 20110920000101_my_migration_name.rb)

A new file, with the timestamp as a prefix on name, will be generated on db/migrate or on the path pointed by the OUTDIR option.

Create your migration files, following the Rails docs.

Inside config, create your database.yml, just like you can do with Rails. On db/migrate, put your migration files.

Now you can do:

rake db:create:all
rake db:migrate

Enjoy and, if you can, help me improve this tool.