News for hackers. Stuff that matters.
Re:Fork Your Application's Data (Not Just Your Code) by eggbrain on Thursday November 08, 2012 @02:49PM (#4759496)
One of the biggest problems I have is that I'll branch out to a new feature branch, modify (add/rename columns) in the db, then get sidetracked by something where I have to switch back to master, making everything explode because the db is still modified, while my application is calling the old values.

I'd love it if they found a way to link up your database to a repo, so that it could track/rollback changes easily as switching branches (I guess an sqlite db might work, but it's not perfect)

Re:Fork Your Application's Data (Not Just Your Code) by wahnfrieden on Thursday November 08, 2012 @04:14PM (#4759875)
You're using branches in production? Consider not doing that.
Re:Fork Your Application's Data (Not Just Your Code) by thibaut_barrere on Thursday November 08, 2012 @05:03PM (#4760126)
It's fairly common and works pretty well if you have a good test coverage and monitoring in place.

GitHub is a documented example (and I happen to deploy branches daily too :-):

https://github.com/blog/1241-deploying-at-github

Re:Fork Your Application's Data (Not Just Your Code) by amatix on Thursday November 08, 2012 @05:35PM (#4760270)
I've read several times about github's use of branches in deployment/production. How are DB schema/data migrations handled (and kept safe/sane)? Presumably hubot and friends prevent Bad Things from happening by deploying a branch that doesn't match the current DB state?
Re:Fork Your Application's Data (Not Just Your Code) by wahnfrieden on Thursday November 08, 2012 @09:19PM (#4760932)
I didn't say one way is strictly better. There are tradeoffs to consider and that's all that really matters. I'm not sure it occurred to the OP that there are benefits to forgoing remote branches, so I mentioned it.
Re:Fork Your Application's Data (Not Just Your Code) by thibaut_barrere on Friday November 09, 2012 @03:17AM (#4761880)
My bad, I read "Consider not doing that." as a more strict recommendation!
Re:Fork Your Application's Data (Not Just Your Code) by wahnfrieden on Friday November 09, 2012 @05:16PM (#4764972)
Sorry, I was too blunt :)
Re:Fork Your Application's Data (Not Just Your Code) by eggbrain on Thursday November 08, 2012 @04:26PM (#4759933)
Who said anything about production? Are you saying you've never hit a snag with a local db that had data that would be a pain to re-import?
Re:Fork Your Application's Data (Not Just Your Code) by grey-area on Friday November 09, 2012 @03:00AM (#4761844)
Keep your database config for the app in version control with the code, and change to another database per branch.

This means your data in that db will diverge from the main branch slightly, but if that is too much of a problem and you need constant updates from live, you could look into migrations like those used by rails, which store your db changes so that they can be replayed on top of newer data from master and bring it up to the new schema. It's quite easy to setup a bare bones migration system using plain SQL migration files and some scripts if this is a problem you see often.

I often work with several branches of code in rails, and it's not a big problem, you just need a system for keeping the data in sync with the code.

Re:Fork Your Application's Data (Not Just Your Code) by wahnfrieden on Thursday November 08, 2012 @09:22PM (#4760940)
Consider forgoing long-lived/significant local branches too then. Branching has its downsides, and avoiding it has some upsides particularly for small teams. As an alternative, you might start using feature flags instead. Look into "continuous deployment" as well for more insight.
Re:Fork Your Application's Data (Not Just Your Code) by thibaut_barrere on Thursday November 08, 2012 @04:56PM (#4760098)
This has been around in Rails since 2008 using ERB:

http://mislav.uniqpath.com/rails/branching-the-database-alon...

This way you can enable a branch-specific database (if needed) and switch back and forth during the day if you need it.

One could somehow easily adapt that for another development framework, though!

Re:Fork Your Application's Data (Not Just Your Code) by atomical on Thursday November 08, 2012 @03:21PM (#4759645)
I would disagree with this strategy as it adds more complexity than the original problem. It's much easier to rollback the migrations on the feature branch and switch to master. Avoiding situations like this is the best policy though as unexpected things will happen and you can be less sure that things are working properly.
Re:Fork Your Application's Data (Not Just Your Code) by eggbrain on Thursday November 08, 2012 @03:41PM (#4759723)
"Avoiding situations like this is the best policy though as unexpected things will happen"

Yes, but they happen. This seems like replying to someone drowning "well, you should have avoided swimming!"

You also make the assumption that we are using Rails (or some framework with migration support) -- many people won't have that luxury.

Finally, while the setup might be challenging (as in, figuring out a way to implement db tracking in git), I find it very curious that it would be much easier in anyones mind to do two tasks, doing all the rollbacks and switching branches, vs just switching the branch.

Re:Fork Your Application's Data (Not Just Your Code) by atomical on Thursday November 08, 2012 @05:04PM (#4760132)
This isn't a setup issue. Don't work on more than one branch/feature at a time. It's a bad idea and not conducive to getting shit done.
Re:Fork Your Application's Data (Not Just Your Code) by samspot on Thursday November 08, 2012 @06:49PM (#4760539)
You act like we have a choice in the matter.

"Sorry, I can't look into your emergency production problem, I'm adding features to a blog."

Re:Fork Your Application's Data (Not Just Your Code) by eggbrain on Thursday November 08, 2012 @05:53PM (#4760328)

  Git checkout -b "feature-1"
  Git commit -am "Added feature 1, which included a migration"
  Git checkout -b "feature-2-that-builds-off-feature-1"
  Git commit -am "Added feature 2, which includes another migration"
  Git checkout master
  Broken (and with multiple migration files, even though I branched off for each new feature.)
Re:Fork Your Application's Data (Not Just Your Code) by grey-area on Friday November 09, 2012 @03:08AM (#4761857)
Have you considered branching the database along with your code?
Re:Fork Your Application's Data (Not Just Your Code) by mhitza on Thursday November 08, 2012 @04:26PM (#4759932)
I'll start hacking on that. Now to keep this comment, if it ever comes to happen, I'll notify you :)
Re:Fork Your Application's Data (Not Just Your Code) by robertfw on Thursday November 08, 2012 @03:22PM (#4759649)
One approach is to use multiple local databases, one for each schema in use. When you switch branches, update your app config to point at the appropriate database.

It's not perfect and we still have to do work keeping in sync within our team, but it does the job locally.

Re:Fork Your Application's Data (Not Just Your Code) by ubercore on Thursday November 08, 2012 @11:03PM (#4761215)
We've been using a db-follows-branch system with Fabric. Devs can run "fab update_db" to get a new dump of production-based testing data, and create a database named after the current branch. Still a bit manual, but it really helps in situations like that.
Re:Fork Your Application's Data (Not Just Your Code) by nlh on Thursday November 08, 2012 @03:00PM (#4759543)
It's a great idea and something that even I, humble amateur developer, have encountered (and wanted).

Any thoughts about which DB would be best suited for this? I wonder if it could be integrated with git somehow and make the whole process seamless.

Re:Fork Your Application's Data (Not Just Your Code) by viaken on Thursday November 08, 2012 @03:16PM (#4759618)
You could certainly use SQLite this way, as long as you don't need anything hefty. Add and commit your db file, then fork and modify as needed.
Re:Fork Your Application's Data (Not Just Your Code) by mamcx on Thursday November 08, 2012 @04:50PM (#4760058)
Perhaps having a DB.sql script, plus a data generator and/or a dump of the data before doing the branch plus auto-create & load the data when switch.

Yep, look like not as easy I think at the start of the reply...

Re:Fork Your Application's Data (Not Just Your Code) by arscan on Thursday November 08, 2012 @04:06PM (#4759833)
Personally I find this interesting from a marketing perspective... its not like cloning a DB is a new concept, but by calling it "forking your data" they make it seem quite a bit sexier.

I'm not sure if technically its the best term to use, but it does sound cool.

Re:Fork Your Application's Data (Not Just Your Code) by scdoshi on Thursday November 08, 2012 @06:57PM (#4760565)
Couldn't you always clone a git repo too? But the ability to "fork" (clone plus some setup) on github is still very useful.
Re:Fork Your Application's Data (Not Just Your Code) by grimlck on Thursday November 08, 2012 @03:51PM (#4759755)
So you can't merge changes on the fork back to the main database?

Without the ability to merge, shouldn't it just be called 'copying'

Re:Fork Your Application's Data (Not Just Your Code) by thibaut_barrere on Thursday November 08, 2012 @02:42PM (#4759468)
Also interesting: data clips

https://postgres.heroku.com/dataclips

I'll have to wait for them to become SafeHarbor compliant before using them, though (in progress!).

Re:Fork Your Application's Data (Not Just Your Code) by TheMakeA on Thursday November 08, 2012 @02:37PM (#4759453)
Interesting. I would take it a step further and say that everything related to your project should be forkable and branchable. Your source, your assets, your databases, etc. I would love to be able to go back to any moment in the projects history and get a full, working build.
Re:Fork Your Application's Data (Not Just Your Code) by Q6T46nT668w6i3m on Thursday November 08, 2012 @03:11PM (#4759595)
I would take it a step further and say that everything related to your project should be forkable and branchable. Your source, your assets, your databases, etc.

Isn’t that the advantage of Perforce?

Re:Fork Your Application's Data (Not Just Your Code) by TheMakeA on Thursday November 08, 2012 @03:14PM (#4759609)
It is possible with Perforce, but it is far from ideal. Compare branching in Git to branching in Perforce. There's still a lot of room for improvement.
Re:Fork Your Application's Data (Not Just Your Code) by hythloday on Thursday November 08, 2012 @07:31PM (#4760664)
You should compare branching in Git to "streaming" in Perforce:

http://www.perforce.com/product/product_features/perforce_st...

Re:Fork Your Application's Data (Not Just Your Code) by pvh on Thursday November 08, 2012 @07:46PM (#4760702)
Yes, wouldn't it be cool if you could fork an entire running app?
Re:Fork Your Application's Data (Not Just Your Code) by CookWithMe on Thursday November 08, 2012 @04:32PM (#4759963)
What about images? Should one save them in the DB? Is Postgres able to handle high-res images?

Last time I checked (for MySQL) it was possible, but not really recommended/wide-spread. Does anyone have practical experience with Postgres (and Heroku)?

Re:Fork Your Application's Data (Not Just Your Code) by 5vforest on Thursday November 08, 2012 @02:55PM (#4759522)
This is neat. I've always used Amazon RDS in the past because of its ease of import/export, but this may be enough to switch me over to Heroku's offerings.
Re:Fork Your Application's Data (Not Just Your Code) by sterling312 on Thursday November 08, 2012 @05:41PM (#4760292)
I've been wanting people to post their eigenvector/value on facial recognition training for a while. Imagine a crowdsource trained facial recognition database!