Archive for Databases

Setting up Ruby on Rails Database Connection using SQLite (version 2 and 3) on Ubuntu Feisty Fawn

SQLite is good for development and testing, and depending on your needs production even. By default Typo uses SQLite for production. The greatest advantage is that it’s light. (like duh), and very easy to deploy.

Note: There are two versions of SQLite, version 2 and 3. They produce databases which are incompatible with each other.

Version 2

Enter into the Terminal:

sudo apt-get install ruby1.8-dev libsqlite0-dev
sudo gem install sqlite-ruby

If you see this, select 1 (enter it in).

Select which gem to install for your platform (i486-linux)
 1. sqlite-ruby 2.2.3 (ruby)
 2. sqlite-ruby 2.2.3 (mswin32)
 3. sqlite-ruby 2.2.2 (ruby)
 4. sqlite-ruby 2.2.2 (mswin32)
 5. Skip this gem
 6. Cancel installation
>

Edit the file File RAILS_ROOT/config/database.yml. For now we are using the Database development environment. The environment you are deploying your database should look like so.

development:
  adapter: sqlite
  dbfile: db/development.sql

Version 3

Enter into the Terminal:

sudo apt-get install ruby1.8-dev libsqlite3-dev
sudo gem install sqlite3-ruby

If you see this, select 1 (enter it in).

Select which gem to install for your platform (i486-linux)
 1. sqlite3-ruby 1.2.1 (ruby)
 2. sqlite3-ruby 1.2.1 (mswin32)
 3. sqlite3-ruby 1.2.0 (mswin32)
 4. sqlite3-ruby 1.2.0 (ruby)
 5. Skip this gem
 6. Cancel installation
>

Edit the file File RAILS_ROOT/config/database.yml. For now we are using the Database development environment. The environment you are deploying your database should look like so.

development:
  adapter: sqlite3
  dbfile: db/development.sql

Conclusion

There you have it, your database is now set up!

Comments (2)

Avoid Using A Field Called ’status’

status‘ sounds like a good name for a field name doesn’t it? It can indicate whether your Post is draft, published or private. Or may be it can be used to indicate the current stage that your Product is in, ie: manufacturing, cleaning, testing, complete.

Surely sound’s like a brilliant solution doesn’t it? And it is actually!

Except for one thing.

Avoid Using a ’select’ Field

Except MySQL uses the keyword ‘status‘. So if you wanted to do queries like so:

you would need to enclose the ‘status‘ field in back ticks, like so:

Now that isn’t cool at all, because using find method with conditions can be highly irritating, and doesn’t look clean at all.

So if you actually do decide to use a field called ’status’ and enclose it within back ticks, then you’ll run into another problem. Database independence.

SQLite does not support back ticks. So if you like to develop and test on SQLite initially, and similarly since your application has been comfortable with SQLite, you decide to also use it production. But what happens when SQLite can’t scale anymore? Well you’ve got to move elsewhere. Unh unh right?

Note: I am inexperienced with PostgreSQL, so maybe others can update me on this.

Alternatives

Other alternative I have been using is to call the field ‘stage‘ or ‘state‘. There are probably tons of other possibilities out there, but do avoid using a field called ’status’.

Any suggestions for other possible alternatives to use?

Comments (2)

Next entries »