Project 6.1

Apr 4, 2012

Objective

Project 6: Design and implement a database using a client-server DBMS (MySQL) and implement a simple program that demonstrates the use of an ORM.

Project 6.1: Install ActiveRecord and conduct a simple test to make sure your environment is ok.

Scenario

(previously...)

"Oooohhhhnnnnhhh..." you groan. Your head is pounding and for a moment you forget everything except that pain. "What happened to me?" you wonder, "I was just .dumping my schema when --" Your vision clears as you raise your head. You see a suit-wearing clown before you.

"As you can see," says the clown, "we've had our eye on you for some time now, (insert your name). It seems that you've been living two lives. In one life, you're (your name), a student in CSCI403, you have a social security number, you pay your taxes... and you help your landlady carry out her garbage. The other life is lived in computers, where you go by the hacker alias Seekwell and are guilty of virtually every computer crime we have a law for. One of these lives has a future, and one of them does not. I'm going to be as forthcoming as I can be. You're here because we need your help. We know that you've submitted a database to a recent competition and that you have been contacted by a certain individual, a man who calls himself Morpheus. Now whatever you think you know about this man is irrelevant. He is considered by many authorities to be the most dangerous man alive. My colleagues believe that I am wasting my time with you but I believe that you wish to do the right thing. We're willing to wipe the slate clean, give you a fresh start and all that we're asking in return is your cooperation in implementing a simple database-backed program"

"Yeah. Wow," you begin, "that sounds like a really good deal. But I think I've got a better one. How about I give you the finger --"

"Urhm."

"-- and you give me my laptop."

"Hhm, you disappoint me," the clown says as he pulls out a water gun filled with something yellow.

"You can't scare me with this Gestapo crap!" you shout, "I know my rights. I want my laptop!"

"Tell me, what good is a database if you're unable to create a program that uses it? You're going to help us, whether you want to or not."

Requirements

This step in project 6 is short, but there are potential pitfalls that you must avoid by starting early.

We're going to dive into the code next week, so the first step is to make sure your environment is ready to roll. Or rock. Or rumble. Or rabbits, whatever.

Prepare the Project

Continue working in a subdirectory of cs403 called project06. This is your dedicated working directory for all 6.x project assignments.

Set up your environment

In this step of the project, you will import a sample MySQL database, install the ActiveRecord ORM and test your installation by implementing a simple feature.

  1. Create a MySQL database called zoolicious.
  2. Download this MySQL dump and import it. See the MySQL Tutorial book to remind you of the commands to do so.
  3. Make sure your environment is set up correctly:
    1. You should have Ruby 1.8.x or 1.9 installed, and you should have gem installed.
    2. Make sure that ruby is in your path.
    3. Make sure that the mysql bin directory is in your path.
    4. Make sure that gem is in your path.
    5. Make sure that you have the gems for MySQL and ActiveRecord installed. (gem install mysql2 and gem install activerecord. Linux/OSX users, you might use sudo.)
      Warning: Be sure to accomplish this step early, as installing the MySQL gem may raise an error depending on your installation of MySQL.
  4. Test your environment by running this ruby script (save it as ar_test.rb, not ar_test.rb.txt. Be sure to read the script before running it and edit as necessary.

At this point, you should have run the script and it should not report an error. If not, resolve the error before continuing.

Create a copy of ar_test.rb called zoolicious.rb. Next:

ZOOOOOLICIOUS!
Listing 4 users in the database sorted by last name:
Edgar Codd (efcodd)
Chris Date (cjdate)
John Smith (jsmith)
Jane Smith (jasmith)

Notice that the number of users is displayed and that the list is sorted.

Review the Existing Database

Using the MySQL "monitor" or a GUI app, quickly browse the schema. You'll notice that very few constraints have been implemented in this schema. This is intentional -- we will be implementing business rules in the ORM layer, and ALTERing our schema to match.

Grading Criteria (200 pts)

Copy and paste the body of your zoolicious.rb into blackboard (do not attach).

This is due by 11:59PM on Monday, Apr 9.