0.0
No commit activity in last 3 years
No release in over 3 years
Fork your database
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

DatabaseFork

Create a copy of your development and test databases when you switch git branches.

Installation

Add this line to your application's Gemfile:

gem 'database_fork', '>= 0.0.8'

And then execute:

$ bundle

Add this file to your .gitignore:

.db_forks.yml

Add the git hook:

touch .git/hooks/post-checkout
sudo chmod +x .git/hooks/post-checkout

Now add this to the .git/hooks/post-checkout file:

#!/usr/bin/env ruby
if File.exists?(File.join(ENV['PWD'], 'Gemfile'))
  begin
    require 'rubygems'
    require 'bundler/setup'
    require 'database_fork'
  
    DatabaseFork.new(ENV['PWD']).run
  rescue LoadError
    puts 'DatabaseFork: Could not load DatabaseFork gem.'
  end
else
  puts "DatabaseFork: No Gemfile found in #{ENV['PWD']}. Run from to your Application's root!"
end

Rails: add this line at the end of your application.rb:

unless Rails.env.production?
  begin
    DatabaseFork.setup_env(Rails.env, Rails.root)
  rescue LoadError
    'DatabaseFork not available'
  end
end

To dynamically load the database clone, add this to each environment in your Rails database.yml:

development:
  database: <%= ENV['DATABASE_FORK_DEVELOPMENT'] || 'my_app_development' %>

Limitations

  • only tested with Rails
  • currently only works with Mysql

TODO:

  • add postgresql adapter
  • improve specs (as usual ;) )

Help is welcome

If you want to contribute an adapter, write specs or refactor the gem, please feel free to send a pull request!

Contributing

  1. Fork it ( https://github.com/[my-github-username]/database_fork/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