GithubHelp home page GithubHelp logo

room118solutions / branchbot Goto Github PK

View Code? Open in Web Editor NEW
25.0 3.0 7.0 33 KB

Save and restore the state of your Rails development and test databases as you work on different branches

License: MIT License

Ruby 100.00%

branchbot's Introduction

git-rails-database-branch-hook

Save and restore the state of your Rails development and test databases as you work on different branches.

This allows you to make some changes to the structure of your database on a feature branch, then be able to quickly switch back to your master branch to make a hotfix or start a new feature branch with your original database structure and content.

Installation

Download the post-checkout file into the .git/hooks directory of your project. Be sure to keep the post-checkout name to match Git's expectations.

Alternatively, you can clone this repository to your computer then symlink the post-checkout file into the .git/hooks directory of each of your projects. This allows you to manage the file in one place and be able to easily pull down updates.

Support

Only PostgreSQL and MySQL databases are currently supported.

Non-Rails Usage

While this hook is geared towards Rails and depends on Ruby, it is very easy to use it in non-Ruby/Rails projects, so long as you have Ruby installed on your system.

This script will look for a config/database.yml file in your project's root directory, and expects it to look like this:

development:
  adapter: <adapter>
  username: <database username>
  password: <database password>
  database: <database name>

We currently support two adapters: mysql2 and postgresql. We don't actually rely on these gems, but instead use them to determine which database's command line tools we should use (mysqldump/mysql or pg_dump/psql). Use mysql2 if you are using a MySQL database, or postgresql if you are using a PostgreSQL database.

branchbot's People

Contributors

cgunther avatar jimryan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

branchbot's Issues

git checkout without arguments from branch saves branch dump as master

I just hit this, didn't get a chance to dig in, but documenting it a bit for future self.

If you're on branch foo and run git checkout (no arguments, meant to run git checkout . to discard changes in my working directory), git leaves you on branch foo, but the hooks seem to cause branchbot to dump the state of the current database (branch) as master, which effectively just blew away your master dump, replacing it with your feature dump.

I'll have to come back and test this a bit more to confirm, but assuming that's reproducible, I'd be curious if we can catch this and do something better, either not dumping at all (you're not really changing branches), or at least not dumping to master.

Edit: Should also note the feature branch didn't have any commits yet, so it's head commit would have matched master at that point. Perhaps if there had been a commit already, that deviation in head commit would have caused it to dump the feature DB named after the feature, rather than after master.

Expose snapshot and restore commands

  • Users should be able to snapshot their current branch on-demand
  • Users should be able to select a prior manual snapshot to restore from
  • The switch command should simply perform a snapshot and a restore, but not keyed to a specific time (same as current behavior where the automated snapshot is keyed to the branch)

Fails when branch name contains a slash

I found when switching from a branch named 'feature/description-of-feature', I'll get an error along the lines of:

Saving state of development database on 'feature/description-of-feature' branch...sh: 1: cannot create /home/peterh/project/.db_branch_dumps/database_development-feature/description-of-feature: Directory nonexistent
failed!
Failed to dump database. Halting.

Installer

install command should launch a guided installer that creates and configures the post-checkout hook for the user.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.