No commit activity in last 3 years
No release in over 3 years
Give each git branch its own databases for ActiveRecord.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.8.0
>= 1.4.1

Runtime

>= 2.0.2
 Project Readme

branch_db¶ ↑

DESCRIPTION:¶ ↑

Give each git branch its own databases for ActiveRecord.

FEATURES/PROBLEMS:¶ ↑

  • alpha quality

  • create, delete, copy git branch-specific databases using rake tasks

  • automatic switching based on currently checked out branch

SYNOPSIS:¶ ↑

Put the following block of code into config/environment.rb before Rails::Initializer.run. This code ensures that the database is automatically switched, based on the checked out git branch.

# config/environment.rb
...
require 'branch_db/configuration_twiddler'
Rails::Configuration.class_eval do
  include ::BranchDb::ConfigurationTwiddler
end
...

In config/database.yml, mark the configuration that may have databases specific to current branch

# config/database.yml
development: &development
  adapter: postgresql
  database: myproject_development
  host: localhost
  port: 5432
  per_branch: true

To your Rakefile or a file in lib/tasks add

require 'tasks/db_branches'

Then you can use these rake tasks to manage your databases.

rake db:branches:list
    List all branch databases

rake db:branches:current
    Currently selected databases.

rake db:branches:create
    Create empty databases for a branch. Current or BRANCH.

rake db:branches:copy
    Copy databases from one branch to another.
    Default is from ORIG_BRANCH=master to BRANCH=<current branch>

rake db:branches:delete
    Delete databases for a branch given by BRANCH

Say, you have a configuration as above and you’re currently on git branch “feature” when you decide that you need a database specific to this branch. Then

~/projects/myproject (feature*)$ rake db:branches:copy ORIG_BRANCH=master

will give you a copy of the database from branch “master”. If your branch already has a database that you want to overwrite, add OVERWRITE=true to the command line.

REQUIREMENTS:¶ ↑

  • ActiveRecord

INSTALL:¶ ↑

  • sudo gem install mschuerig-branch_db

LICENSE:¶ ↑

(The MIT License)

Copyright © 2009 Michael Schuerig

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.