CS 549, Spring 2007
Assignment #2
(due on 11, Wednesday or later if reasonable)

You may work on this assignment as a group of one or two students. If anything does not work as described here, notify the instructor immediately. Do one of the following tasks.

  1. Install Mantis, which is a bug tracking system available at http://www.mantisbt.org.

  2. Install Zen Cart, which is an e-commerce system available at http://www.zen-cart.com.

  3. Create a WebGen interface for Trac, which is a project managment system available at http://trac.edgewall.org. The database is available as a PostgreSQL database. You can create a WebGen interface by using app_skeleton implemented as described in CS 440 Assignment #5. See the instructor for the details.

  4. Install CakePHP, which is a development framework in PHP available at http://www.cakephp.org. See the instructor for the details.

  5. Install Ruby on Rails, which is a development framework in Ruby available at http://www.rubyonrails.org. See the instructor for the details.

  6. Migrate a Mail Order database from MySQL to PostgreSQL and create a schema diagram with Microsoft Visio. See the instructor for the details.

  7. Migrate a Webgen5_Example_V3 database from MySQL to PostgreSQL and create a schema diagram with Microsoft Visio. See the instructor for the details.

  8. Migrate a Mantis database from MySQL to PostgreSQL and create a schema diagram with Microsoft Visio. See the instructor for the details.

  9. Migrate a Zen Cart database from MySQL to PostgreSQL and create a schema diagram with Microsoft Visio. See the instructor for the details.

  10. Populate a Trac database and create a schema diagram with Microsoft Visio. See the instructor for the details.

  11. If you want to work on an independent project for this course, provide a project description including a database schema.

Additional Information

  1. The Mantis and Zen Cart applications have been installed in directories mantis-1.0.6 and zen_cart in /usr/local/classes/eecs/winter2007/cs440/public_html on the ENGR file server, and they can be accessed with the following URLs:
    1. http://classes.engr.oregonstate.edu/eecs/winter2007/cs440/mantis-1.0.6
    2. http://classes.engr.oregonstate.edu/eecs/winter2007/cs440/zen_cart


  2. You can find the modified configiration files by issuing the command grep -r cs440 * in the top-most directory of each application under /usr/local/classes/eecs/winter2007/cs440/public_html.

  3. A downloaded file xxx.tar.gz can be unpacked with Unix command tar -xvzf xxx.tar.gz.

  4. The instruction for installing Mantis is in file INSTALL in directory mantis-1.0.6/doc. In installing, say, Mantis, create your database with name cs549_your-login-name_mantis.

  5. A simple instruction for installing Zen Cart is in file install.txt.

Creating foreign-key constraints for a MySQL database

  1. A database reverse engineering tool can create a schema diagram for a database semi-automatically. The required information, which is often called meta-data, is available in a system catalog or data dictionary. The meta data for a MySQL database can be accessed from INFORMATION_SCHEMA, which is explained at http://www.mysql.org/doc/refman/5.0/en/information-schema.html

  2. When foreign key constraints are defined, relationship-types in a schema diagram can be automatically generated. Therefore, we must add foreign key constraints to the tables. If your tables are not created with the ENGINE=INNODB option, they must be recreated with this option, since the INNOB engine is needed to support foreign key constraints.

  3. When Mantis and Zen Cart are installed, the tables use the MyISAM engine. You can check this with phpMyAdmin by clicking Database: your-database-name at the top of the screen. The engine option for each table can be changed with the following SQL statement:
      alter table table_name ENGINE=INNODB;
    
    You can create a script containing this statement for every table and execute it. I use a keyboard macro of emacs for this kind of editing work. Alternatively, you may use phpMyAdmin to change the engine option for each table. Click the name of a table on the left-hand side, select Operations, and change the engine. Repeat this process for each table within the database.

  4. One way of adding foreign key constraints is as follows:
    create table supplier_product (
        supplier_product_id  int primary key auto_increment,
        supplier_id          int  not null,
        product_id           int  not null,
        whole_sale_price     integer
        FOREIGN KEY (supplier_id) REFERENCES supplier(supplier_id),
        FOREIGN KEY (product_id)  REFERENCES product(product_id)
      ) ENGINE=INNODB;
    
    Note the ENGINE=INNODB option at the end of the create table statement.

  5. Another way of adding foreign key constraints is to use separate SQL statements as shown below:
    ALTER TABLE  mantis_bug_table
      ADD CONSTRAINT mantis_bug_table_bug_text_id_fkey
      FOREIGN KEY (bug_text_id) REFERENCES mantis_bug_text_table(id);
    
    ALTER TABLE  mantis_bug_table
      ADD CONSTRAINT mantis_bug_table_profile_id_fkey
      FOREIGN KEY (profile_id) REFERENCES mantis_user_profile_table(id);
    
        .    .    .
    
    \u information_schema
    select * from key_column_usage where position_in_unique_constraint is not null;
    \u mmantis
    
    Foreign key constraints can be dropped as follows:
    ALTER TABLE  mantis_bug_table
      DROP FOREIGN KEY mantis_bug_table_bug_text_id_fkey;
    
    ALTER TABLE  mantis_bug_table
      DROP FOREIGN KEY mantis_bug_table_profile_id_fkey;
    
        .    .    .
    
    
    For a PostgreSQL database, change DROP FOREIGN KEY to DROP CONSTRAINT. Now, create in directory sql_queries_mysql two files xxxx_fkeys_create.sql and xxxx_fkeys_drop.sql that add and delete foreign key constraints.

  6. You may modify file zencart_add_drop_fkeys.php in zen_cart/forms_mysql/utilities/ to create files xxxx_fkeys_create.sql and xxxx_fkeys_drop.sql. The script considers column zzz_id in table yyy as a foreign key to column zzz_id in table zzz if such a column exists.

  7. Foreign key constraints created can be listed as follows:
    mysql> \u information_schema  -- connect to the INFORMATION_SCHEMA database.
    mysql> select * from key_column_usage
           where POSITION_IN_UNIQUE_CONSTRAINT is not null;
    
    Foreign key constraints for a table can be checked as follows:
    mysql> \u information_schema  -- connect to the INFORMATION_SCHEMA database.
    mysql> show table status from database_name like 'supplier_product';
    
  8. By the way, primary key constraints can be listed as follows:
    mysql> \u information_schema  -- connect to the INFORMATION_SCHEMA database.
    mysql> select * from  key_column_usage
           where POSITION_IN_UNIQUE_CONSTRAINT is NULL;
    

Creating a schema diagram

  1. We can create a schema diagram semi-automatically by using Microsoft Visio. In order to use this program a database must be migrated to a PostgreSQL database.

  2. In order to connect to a PostgreSQL database from a Windows machine, you need to create a Data Source.
      Start --> Settings --> Control Panel -> Administrative Tools
      --> Data Sources (ODBC)
    
    When a dialog for DSNs is displayed do
      User DSN --> PostgreSQL Unicode --> Add
       --> PostgreSQL Unicode
    
    Provide the name of your database for Database Name, nagara.een.orst.edu for the server name, and your login name, and then click the Save button. Now, you can activate Visio:
      Programs --> Microsoft Office --> Microsoft Visio 2003
    
    Once the window of Visio is opened, do
      File --> New --> Database --> Data Model Diagram (Metric)
      Database --> Reverse Engineer --> 
      ODBC Generic Driver, PostgreSQL Unicode --> Select Tables --> ...
    
    Use the Help pages for further information.