inchworm

inchworms

Summer of Coding, one inch at a time...

Setting up Our Database

inchworms -

If the thought of setting up databases provokes this response:

freaked matt

FEAR NOT!!!

Follow these simple steps instead:

(This is what we did to set up the (development) database we’ll be using for our Farmsubsidy project).

  1. Map out the basic data model on a piece of paper, including the relationships between each dataset/table (i.e. one to many, must have, zero or more).

  2. Normalise (to get rid of repetition) or De-Normalise (to put it back when removing it is actually not totally logical or necessary)

  3. Create a migration file. Name this using the Rails convention: date&timestamp_migration.rb. Store this file in db/migrations/ directory of your application.

  4. Write the migration in Sequel, creating tables in the order required for any foreign keys between tables to compute.

  5. Create a Rakefile. Write the migration methods here.

  6. In terminal create the database (if you haven’t already): createdb databaseName

  7. Create a Gemfile that includes all required gems (in this case ‘sequel’, ‘rake’, and ‘pg’).

  8. In terminal run bundle install to install the required gems localy

  9. In terminal run rake db:migrate to run the migration and create all the tables in the database.

Then enjoy wearing your DataBase forehead sticker with pride:

cheeky matt