Code Monkey home page Code Monkey logo

db_branch's Introduction

DB_BRANCH

Rails plugin to play nice with git branching and databases. Loads a branch-specific database YAML file allowing you to migrate in branches without affecting the database of other branches.

More information:

Usage

First, you should have your db backed up. Just saying.

By default, it will run setup, config, and create_clone tasks so you'll end up with a running copy of your existing db for your branch.

rake db:branch

Update the db again? The clone task will drop and recreate the db and reload it from the original.

rake db:branch:clone

Just want a clean db without the data? create_empty will create the config and just load the db from the schema.

rake db:branch:create_empty

No longer need the branched db? purge will remove the branched databases and config.

rake db:branch:purge

Branch database config files are named database.branch.[branch_name].yml. The database names for the branch are renamed as [application]_[environment]_[branch] or [databasename]_[branch] if the originals where not named using a [application]_[environment] convention.

You can alter which branch name is used for the creation or purging of databases and config by setting the DB\_BRANCH variable.

rake db:branch DB_BRANCH=refactor

You can alter which database is used for the cloning or schema loading by setting the RAILS\_ENV variable.

rake db:branch:clone RAILS_ENV=development

Explicitly configuring which environments to branch

I have a project that has a lot of tunneled connections defined in it's config/database.yml. I do not want the plugin to attempt to create branched versions of all these dbs, so I added support for explicitly stating which environments should have the db branched by adding a branch: true or false to the database.yml where appropriate. So, if you just want production and development dbs to be branched, you can set branch: true to those stanzas of the config and the rest will be included in the new config unmanipulated.

Once 'branch' has been defined in any stanza, any stanza lacking it or having it set to something that does not evaluate to true will be treated as a remote db, effectively omitting it from the create/drop tasks.

But can it go to Eleven?

The only thing I can imagine making this any better is possibly finding a way of using gits hooks to automatically run rake db:branch when creating a new branch and rake db:branch:purge when deleting a branch. That'd be pretty hot.

Authors

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.