preload
Feb 21

Every time I switch to a new branch in git, I ask the question, “Are my dev and test databases in a state that works with this branch?”  Rarely being able to remember the answer, I go through the ritual of dropping the tables, migrating, loading fixtures, and prepping the test database.  Annoying at best.

I hacked together a potential solution.  This is intended for your dev and test databases only.  This looks like an outstandingly stupid thing to do on your production server.  Although, who deploys their database.yml file from git anyway?

For months, I’ve been using this great shell hack that puts your current branch in your command line.  Thanks github.

jdl ~/hm(master) $ git co foo
Switched to branch "foo"
jdl ~/hm(foo) $

It finally dawned on me that my database.yml file could also use a similar treatment. Modifying the system call a bit, I ended up with this. Notice that I’m using an absolute path to git. That’s because the TextMate test runner wasn’t able to find git in whatever PATH it was picking up. If you’re just using rake or autotest, then you can simply specify ‘git’ there.

local_db: &local_db
  adapter: mysql
  username: root
  password: 
  host: localhost

<% branch_name = `/usr/local/git/bin/git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`.strip.gsub(/[* ]/, '') %>

development:
  <<: *local_db
  database: <%= "project_dev_#{branch_name} "%>

test:
  <<: *local_db
  database: <%= "project_test_#{branch_name} "%>

Creating a new branch takes a bit more effort, but switching is now faster.

jdl ~/hm(master) $ git co -b foo
Switched to a new branch "foo"
jdl ~/hm(foo) $ rake db:create:all; rake db:migrate; rake db:fixtures:load; rake db:test:prepare

The downside to this is that it’s overkill when creating a branch that has no migrations in it. I’m going to try it for a while and see how it goes.

Update: After a week of using this, I have to say that it’s neither terrible nor great. I still think that there is a good idea buried in there, but it needs to be integrated with the git branch hooks to ease the pain a bit. Specifically, I need to figure out the following.

  • Deleting a branch should automatically clean up the databases that were created.
  • It would be great to have this be optional when creating a new branch. If I could decide to just use my base dev db on a branch, or to create a whole new set of local db’s at the time of branch creation that would be the killer feature for this idea.

Not dead, but back to the drawing board.

Tagged with:
Feb 21

I played Goa last night with a couple of people who were newish to that game, but experienced gamers all around. It reminded me that not everyone understands the huge effect that opportunity cost has in that game.

Bidding is a once-around affair, where each player has a turn to offer up a new tile. The offerer hears the others’ bids, and then either accepts the high bid (taking the cash from the bidder) or outbids everyone else and pays his money to the bank. This means that buying your own auctions costs you more than double what the high bidder was willing you pay you.

For example, let’s say you offer a double-ginger plantation and the high bid is 6. If you pay the bank 7, you really just paid 13 (7 real ducats + 6 ducats you passed on). Not only that, but you’ve taken money out of the game economy, inflating the value of the money that’s left in circulation. Since it was your money being siphoned off, that’s probably not a great thing for you.

Bidding on the flag is interesting, because later in the game, not everyone’s actions are worth the same amount of money. If you buy the flag for 5, and you can perform the money action for 6, then at the very worst you can use the free action to make a profit. However, if you put the flag up for auction and the person to your right bid 4, then buying it for 5 in this situation would be a money loser. That doesn’t mean that you shouldn’t buy the flag, but you need to have a very good reason to justify its cost.

Tagged with: