Monday, October 22, 2007

Rails: Want to change your db server... done.

I have started to develop a few pet projects using Ruby on Rails now that I have my head around the Ruby language a little more. One thing that impressed me was the ability to maintain your database schema via the db:migrate Rake tasks. Here is my two minute example of how this worked wonderfully for me...

I grabbed a very old P4 with 256MB of RAM out of the basement and cobbled together a machine that would actually boot and run. I then loaded the beta release of Ubuntu Server 7.10 (I haven't used Ubuntu too much so this was a good chance to learn this distro while also learning Rails). I loaded up the typical LAMP stack as part of the install.

I started a new site and loaded up about 5 db migration tasks into the standard MySQL db (with test data of course) when I decided that MySQL was overkill for me, a single developer just tinkering. So I thought, could I switch the whole thing over to something more lightweight without a lot of hassle? According to the Rails folks you can.

Simply adjust the config/database.yaml development section to include the new db adapter of your choice. (I decided to go with sqlite3 as there is no server and the db is a single file plus very easy backups). Then I ran rake db:migrate and bingo! All my db and test data was loaded into a sqlite3 db. I then shutdown the MySQL service (gaining back some precious RAM) and clicked around on the site. It worked, very simple, and very cool.

No comments: