2008-07-25

Freezing Rails 2.10 with MS SQL Server

So I'm starting to catch up with a lot of the deployment improvements in Rails up to 2.1.0; I'm freezing Rails, and any associated gems. Some of my apps run against Microsoft SQL Server, so the activerecord-sqlserver-adapter is required. That's where I ran into trouble; trying to freeze that in... apparently a frozen instance of Rails expects the adapters to be frozen as well!

So, here's my recipe for freezing Rails into your app, with support for Microsoft SQL Server:
  1. If you've already frozen rails, you'll need to unfreeze it:
    rake rails:unfreeze
  2. add the gem dependency to your environment.rb:
    config.gem "activerecord-sqlserver-adapter",
    :lib => "active_record/connection_adapters/sqlserver_adapter",
    :source => "http://gems.rubyonrails.org"
  3. Install your gem(s) if you haven't already:
    rake gems:install
  4. Freeze your gem(s):
    rake gems:unpack
  5. Refreeze Rails (I use my gems - you could do this from edge instead):
    rake rails:freeze:gems
Viola! Your Rails app now includes the Rails version it runs against, and any requried gems, including ActiveRecord's SQL Server Adapter.

P.S. This would be easily adaptable for any external ActiveRecord adapter (Oracle, db2, etc.)