Project

communard

0.0
No commit activity in last 3 years
No release in over 3 years
Adds some conventions from ActiveRecord to Sequel.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 1.6
>= 0
>= 0
>= 0
>= 0

Runtime

~> 5.2
 Project Readme

Communard

Communard adds some conventions from ActiveRecord to Sequel.

Sequel doesn't provide the exact same functionality as ActiveRecord. Communard doesn't try to make Sequel quack like ActiveRecord, it just tries to help with some (not all) setup.

Installation

Add this line to your application's Gemfile:

gem 'communard'

And then execute:

$ bundle

Or install it yourself as:

$ gem install communard

Usage

Rake integration

To add most Rake tasks, add this to your Rakefile or to lib/tasks/communard.rake:

require "communard/rake"
namespace :db do
  Communard::Rake.add_tasks
end

This will add the most used rake tasks, like db:create, db:migrate, and db:setup.

To see them all:

$ rake -T db

Communard::Rake.add_tasks accepts the same configuration options as Sequel.connect. It doesn't immediately make a connection, only when needed.

The default connection string is ENV["DATABASE_URL"], so if you use that, there is no need to configure anything.

Other configuration options, can be set via a block:

namespace :db do
  Communard::Rake.add_tasks do |config|

    # Change where the application is located (default: db)
    config.db_path = File.join(Dir.pwd, "db")

    # Automatically generate schema (default: false)
    config.dump_after_migrating = false

    # Dump types in native format (default) or Ruby (more portable)
    config.same_db = true

    # Add a logger
    config.logger = Logger.new("log/migrations.log")

  end
end

Example with using config/database.yml:

namespace :db do
  environment = ENV["RAILS_ENV"] || "development"
  all_config = YAML.load_file("config/database.yml")
  Communard::Rake.add_tasks(config.fetch(environment))
end

Note about test environment: Communard doesn't try to create a test database like ActiveRecord does. The only rake task that attempts to do that is rake db:test:prepare. It respawns rake with different environment variables set. Your mileage may vary.

Migrations

To generate a migration:

$ communard migration create_posts

Communard doesn't support more arguments, like the Rails generator does. You'll have to edit the generated migration file yourself.

Communard supports both timestamps and integer versions. It automatically detects which type you have. If you have no migrations yet and want to use timestamps, add --timestamps. Read more about how to choose in the Sequel docs.

Contributing

  1. Fork it ( https://github.com/iain/communard/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request