Who doesn't love the simplicity of working with Rails and ActiveRecord when you have to touch a database? Unfortunately, there are times that you have to use a database and don't get to work in Rails. This gem tries to make your life a little bit easier by providing a lot of the Rails-y/ActiveRecord goodness without all the Rails.
There are a few opinions that Enrar holds onto from Rails that tend to not be a problem, but that you should be aware of:
- The default location for you database configuration is in PROJECT_ROOT/config/database.yml. If that's where you've got it, you're all set from the get-go.
- Your migrations will get placed in PROJECT_ROOT/db/migrate. This is non-negotiable at the moment.
- Your schema.rb will get placed in PROJECT_ROOT/db. This is also non-negotiable.
Add this line to your application's Gemfile:
gem 'enrar'
And then execute:
$ bundle
Or install it yourself as:
$ gem install enrar
After you've added Ernar to your project, add the following lines to your Rakefile:
require 'enrar/task'
Enrar.initialize! # Connect to DB
Enrar::Task.new # Generate the Rake tasks
Then you can run around almost as if you're in Rails-land.
$ rake 'enrar:db:migrations:generate[migration_name]'
$ # The quotes are necessary if you're in zsh. You can leave them off in you're in bash.
$ rake 'enrar:db:migrate'
$ rake 'enrar:db:version'
Additionally, you can use Enrar in your code to manage the ActiveRecord configurations.
#!/usr/bin/env ruby
require 'enrar'
Enrar.initialize!
# From here on out, ActiveRecord::Base is setup with ENRAR_ENV as the environment
# and ActiveRecord::Base.configurations is defined as expected.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request