daniel hammond 2.0

about

thoughts, insights, links, and ramblings by Daniel R Hammond: student, developer, musician, and human View Daniel Hammond's profile on LinkedIn Daniel R Hammond

Using SQLite3 for Rails on MediaTemple (dv)

SQLite is a really easy to use serverless, selfcontained database engine. Additionally it is the default db adapter for Ruby on Rails version 2.0. This post gives a quick overview for using SQLite3 and Ruby on Rails on a Media Temple Dedicated Virtual 3.0 Server.

Pre-Requisites

Install SQLite

I downloaded 3.5.6 with configure script and makefiles at this url:

http://www.sqlite.org/sqlite-amalgamation-3.5.6.tar.gz.

You can get the latest copy of SQLite from:

http://www.sqlite.org/download.html.

The install process follows the traditional 3-step build from source procedure:

  • [root@domain ~]# tar -xvzf sqlite-amalgamation-3.5.6.tar.gz
  • [root@domain ~]# cd sqlite-3.5.6/
  • [root@domain sqlite-3.5.6]# ./configure
  • [root@domain sqlite-3.5.6]# make
  • [root@domain sqlite-3.5.6]# make install

Important: If you haven’t already you need to add the following line to your /etc/ld.so.conf file otherwise rails will not be able to find the SQLite library

  • /usr/local/lib

After adding that line to /etc/ld.so.conf you need to run the following command

  • [root@domain sqlite-3.5.6]# ldconfig

Instaling the SQLite Gem

Next you need to install the sqlite3-ruby gem that allows rails (and other ruby programs) to interface SQLite3

  • [root@domain ~]# gem install sqlite3-ruby

Configuring your database.yml file

Lastly if you want to use sqlite in one of your Rails apps you should edit your conf/database.yml file and change the appropriate lines for adapter and database. Below is an example:

  • [snip…]
  • production:
  • adapter: sqlite3 
  • database: db/production.sqlite3
  • timeout: 5000

You’ll also likely need to run your database migrations to create the necessary tables and data for your app

Caveats

SQLite is a great database engine for testing, development, and “small” sites. The SQLite Documentation has a great page on Appropriate Uses for SQLite. With Rails built in database migrations, the switch to a “real” relational database is seamless when necessary, so SQLite is definitely a great tool to have available.

Hope you found this guide useful, if you run into any problems feel free to contact me and I’d be glad to help.