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.

Apple Needs a Channel 9

I’m an Apple fanboy.  I own a Macbook Pro, an iPod, an iPhone, and I’ve spent countless dollars in the iTunes store.  Sure there are a few things I really can’t stand, like the lack of control over my iPhone, but it’s manageable.  Overall, I’m pleased.  There is a distinct improvement in the quality of software when moving from a PC to a Mac, and that has been the biggest thing driving my praise.

However, I’ve been noticing a trend from Apple.  They treat their independent developers worse than microsoft does.  There is a very low barrier of entry into writing software for microsoft.  There are countless articles, podcasts, and videos available to help someone get started, but also help all levels of developer.  With Apple, it’s extremely difficult.  I’ve been on the lookout for even a book that helps someone get started in development on Leopard.  There are reference books available, and books that are targeted at earlier versions of OS X, but nothing recent.

But what brought on this most specific rant?  This posting from macworld, announcing that the videos from WWDC (the apple developers conference) had been made available on iTunes U.  That sounds awesome, and I headed over to check it out immediately.  Unfortunately, these videos are free, but only to those developers that have paid $3500+ to become an apple “premier” developer.  Compare this to say the availablility of all the Lang.NET 2008 conference videos for free. You don’t have to sign up for anything.  The videos are listed in a clean interface and you can just scroll and download.  Things can’t get much better than that when it comes to developer videos.

Come on, Apple!  Get with it!

Computer Programming and the Higher Mind

Lately, I’ve been consuming the latest round of technical books, mainly “Head First Design Patterns” first O’Reilly Publishing. First, let my highly reccomend this book. It is a great way to get into design patterns, and very entertaining as well.

Over the past few weeks, many things have began to converge in my coding, and my thought process that go along with it. I’ve developed a “Problem Solving Mode,” which I enter and know nothing else other than the problem I’m trying to fix. It struck me that this could be similar to what some religions might consider a deep state of meditation, and it started a train of thought I’m going to attempt to explain and complete in this entry.

Religion is many times about Abstraction, usually an abstract truth of some sort. The idea of the existence of god is an abstraction. That there are absolute rules we must follow is an abstraction. Coding is alot about abstraction too. Ok, so where does that leave us? If it Floats like a duck, if it quacks like a duck, etc. ? I don’t think so.

Computer Programming is hardly a religion. Let us take a look for a moment at why people might meditate. Personally, I would meditate in order to attempt some insight. Sometimes we know exactly what we are looking for; other time, this insight might be the result of something totally random. We would expect to see a deeper meaning of things. In summary, we wish to enlighten our mind. This is exactly what we are always working towards when we code: the most elegant solution.

I know if I’m faced with a coding problem, I will spend a good amount of time thinking of possible solutions. I will consider the different options I have. If a solution is not apparant quickly, I will continue to think upon it until one does appear. I guess the question burning most in my mind right now is: “Do Carpenters, or Medics, or Lawyers, or any other profession have the ability to do this?” I definately think the possibility is there. But Computer Programming has a definate advantage. It’s all abstract. You create your own world. A Doctor cannot kill a patient to get rid of their cancer. The equivalent in programming is norm. When solving a problem, the only limit is our mind.