Archive for the ‘Mac Stuff’ Category

Easier Capistrano Deployment with legacy databases.

Saturday, May 17th, 2008

As my last Rails project was drawing to a close and deployment tasks were closing in, it became apparent I’d have my work cut out for me when deploying each box. This project was in no way adhering to “the Rails way” with regards to database architecture(or anything else for that matter…..a topic for another post).

With this odd system setup I had to get creative with the Capistrano deployment file. I’ve include my solution to the legacy db problem. As you will see, I’ve added “before” and “after” method calls to handle the proper linking of the project and it’s database.yml after building it from within my deploy.rb file.

So what happens now?

Now when you run cap:deploy from your app root the :db namespace will be run prior to the usual setup. This will build the database.yml file from the entry examples below and process the symlink updates after the script has completed.

Voila! A nice, easy way to manage connections to multiple databases through capistrano.

require 'erb'

#require 'mongrel_cluster/recipes'

before “deploy:setup”, :db

after “deploy:update_code”, “db:symlink”

set :user, “–yourusername–”

set :used_sudo, “true”

set :svn_user, ENV[’svn_user’] || “yoursvnusername”

set :svn_password, Proc.new { Capistrano::CLI.password_prompt(’SVN Password: ‘) }

set :repository,

Proc.new { “–username #{svn_user} ” +

“–password #{svn_password} ” +

“–no-auth-cache ” +

“http://–yoursvnurl–/”}

set :spinner, “false”

set :application, “–yourappname–”

set :deploy_to, “/var/www/#{application}”

set :mongrel_conf, “#{deploy_to}/current/config/mongrel_cluster.yml”

role :app, “yourip”

role :web, “yourip”

# role :app, “yourip”

# role :web, “yourip”

# role :db, “yourip”, :primary => true

role :db, “yourip”, :primary => true

namespace :db do

desc “Create database.yml in shared/config”

task :default do

database_configuration = ERB.new <<-EOF

development:

adapter: sqlserver

mode: odbc

dsn: dsn1

username:

password:

test:

adapter: sqlserver

mode: odbc

dsn: dsn1

username:

password:

production:

adapter: sqlserver

mode: odbc

dsn: dsn1

username:

password:

legacy_db1:

adapter: sqlserver

mode: odbc

dsn: dsn2

username:

password:

legacy_db2:

adapter: sqlserver

mode: odbc

dsn: dsn3

username:

password:

legacy_db3:

adapter: sqlserver

mode: odbc

dsn: dsn4

username:

password:

EOF

run “mkdir -p #{deploy_to}/#{shared_dir}/config”

put database_configuration.result, “#{deploy_to}/#{shared_dir}/config/database.yml”

end

desc “Link in the production database.yml”

task :symlink do

run “ln -nfs #{deploy_to}/#{shared_dir}/config/database.yml #{release_path}/config/database.yml”

end

end


FreeTDS Compiler for Mac

Sunday, February 10th, 2008

Ok, so this is my first post of the year…..deal with it. Not much to report right now. I’m almost ready to switch my blog over to a custom Rails CMS in the near future and I’m gearing up this week to do some training on the latest version of Rails, fun. I always like walking people through a method line by line only to find they weren’t paying attention because they’re too busy being right. That piss anyone else off? I do love REST integration in form objects in 2.0.Yesterday I started compiling a cocoa installer for FreeTDS on Leopard. I’m tired of configuring developer’s machines by hand whenever they need to hit an MS Sql box from their MacBook, so that’s my motivation….and it’d been pretty nice to have. I’ll post to Google Code as soon as it’s tested. With the current work load it’ll probably end up being June.That’s really all for now. Trying to get a major enterprise Rails app out the door this month so it’s likely I won’t have any updates until March or April.