Setting up Our Database
If the thought of setting up databases provokes this response:
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).
-
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).
-
Normalise (to get rid of repetition) or De-Normalise (to put it back when removing it is actually not totally logical or necessary)
-
Create a migration file. Name this using the Rails convention: date×tamp_migration.rb. Store this file in db/migrations/ directory of your application.
-
Write the migration in Sequel, creating tables in the order required for any foreign keys between tables to compute.
-
Create a Rakefile. Write the migration methods here.
-
In terminal create the database (if you haven’t already): createdb databaseName
-
Create a Gemfile that includes all required gems (in this case ‘sequel’, ‘rake’, and ‘pg’).
-
In terminal run bundle install to install the required gems localy
-
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: