Using Ruby to Manage Sql Server db creation

One of the things I hate about programming is dealing with the database. There are just so many things about it that cause more pain than pleasure.  The rise of ORM’s has gone a long way in making that better, but we still have a ways to go.

One of the problems with developing against databases is that unless you go out of your way, there it’s difficult to include in your source version control repository.  The “best” way in the .NET world has been generating your sql server creation scripts and go from there.  I didn’t feel like this was a good solution, though, especially since the code that is generated utilizes a lot of SQL that I don’t understand, nor have any desire to learn.  So I set about trying to find a better way.

The first constraints I decided upon were pretty simple:

  1. There needs to be a way to include the database schema in a text file that can be versioned with the rest of the code.
  2. The text file should be able to be transformed into a database (i.e. executable).
  3. I should be able to insert base data into the system.  For example, if I want to populate a Settings table with some default values.
  4. It would be able to completely reset the database to a pristine state.

Being a previous Rails developer, active_record migrations jump to mind, but I ran into problems pretty quickly.  As it turns out, active_record doesn’t respect foreign keys, which is what the Entity Framework uses to find relationships.  Active_record was a no go.  I decided to stay in the ruby world, though, and check out what else they had for me.  After some searching, I found Sequel.  So far, it’s worked pretty well.

I decided not to go the migrations route, because that didn’t seem to really fit my development pattern.  Instead, I’m generating the entire database at once.  This may turn out to be the wrong decision.  Currently, here is where I”m at:

There are quite a few problems with this code, but it’s got me on a path I’m feeling pretty good about.  Since it’s all in ruby, this means I can easily integrate it with Albacore build system (for .NET).

Okay, so this is pretty standard stuff in the ruby world.  So how well does this fit in with the Entity Framework?  Pretty well so far.  I can run that script above and then right-click and choose “Update Models” from Visual Studio.  The models are updated, and I’m ready to go.

I’m going to continue working on this, but I am really starting to feel like I’m on the right track here.

Introducing Grease

Something that has really bothered me about software music players out there is just how poor their performance is.  Whether it’s iTunes or Songbird or even Foobar, it seems like I would wait forever for them to start up and run through all the things they need to do.  So I decided to do something about it.  I built my own music player that I’ve been calling “Grease”.

As I was thinking about this, I thought about how exactly I use these mp3 players.  Usually, I just pull them up and have them play random songs from my library.

I decided that this is *all* Grease would do.  Embracing the Unix philosophy of “Do one thing well” as inspired by onethingwell I set to work.grease

After a few hours,  I had something I was able to start using personally, and after some polish, it’s ready for it’s first general release.  I’m calling this somewhere between “Alpha” and “Beta” quality.  There are still some issues, but I thought I would release it to see what the response is.

How to use Grease:

  1. Click on the folder to select a folder full of mp3’s.
  2. Grease recursively walks through that directory finding any MP3’s (and m4a’s).
  3. Click play, and enjoy.

It will remember your directory, so you don’t need to select it every time.  It will load up your music files on startup the next time you open Grease.

I definitely wanted keyboard short cuts, so here they are:

Space-bar: Play toggle
Left arrow: go back a song
Right Arrow: skip to the next song
Down arrow: volume down.
Up arrow: volume up.

That’s all there is to it.  It’s a WPF application, and I’ve only tested it on Windows 7.  If you try it out, please let me know what you think!

It doesn’t require installation.  You can just unzip the binaries and run them.  The source code is on github if you’re interested in that.

Grease: Source Code | Binary Zip

EDIT: I have discovered a bug where keyboard short cuts don’t work after clicking the folder icon.  I’m not sure why this is, but if you restart the application, the shortcuts will once again work.