system_update

5.x system.install system_update($old_schema, $new_schema)
4.x system.install system_update($old_schema, $new_schema)

File

modules/system/system.install, line 73
The install file for the System module

Code

function system_update($old_schema, $new_schema) {
  if ($old_schema <= 1) {
    // Add column to the faculty table
    db_query("ALTER TABLE faculty 
              ADD COLUMN department_code varchar(10) NOT NULL AFTER college, 
              ADD INDEX (department_code)");
  }


  if ($old_schema < 3) {
    // Add an index to the advising_comments table for access_type
    db_query("ALTER TABLE advising_comments
              ADD INDEX (access_type) ");
  }


  if ($old_schema < 4) {
    // Add college-related tables
    db_query("CREATE TABLE `colleges` (
                `college_code` varchar(10) NOT NULL,
                `title` varchar(255) NOT NULL,
                PRIMARY KEY (`college_code`)
                ) ");

    db_query("CREATE TABLE `degree_college` (
                `major_code` varchar(20) NOT NULL,
                `college_code` varchar(10) NOT NULL,
                PRIMARY KEY (`major_code`),
                KEY `college_code` (`college_code`)
              ) ");

    fp_add_message(t("Added college-related tables to database."));
  }

  if ($old_schema < 5) {
    // Update hour fields to be decimal type.
    db_query("ALTER TABLE `advised_courses` MODIFY `var_hours` DECIMAL(8,4) NOT NULL");
    db_query("ALTER TABLE `student_courses` MODIFY `hours_awarded` DECIMAL(8,4) NOT NULL");
    db_query("ALTER TABLE `student_substitutions` MODIFY `sub_hours` DECIMAL(8,4) NOT NULL");

    db_query("ALTER TABLE `courses` MODIFY `min_hours` DECIMAL(8,4) NOT NULL");
    db_query("ALTER TABLE `courses` MODIFY `max_hours` DECIMAL(8,4) NOT NULL");
    db_query("ALTER TABLE `courses` MODIFY `repeat_hours` DECIMAL(8,4) NOT NULL");
    db_query("ALTER TABLE `draft_courses` MODIFY `min_hours` DECIMAL(8,4) NOT NULL");
    db_query("ALTER TABLE `draft_courses` MODIFY `max_hours` DECIMAL(8,4) NOT NULL");
    db_query("ALTER TABLE `draft_courses` MODIFY `repeat_hours` DECIMAL(8,4) NOT NULL");

    db_query("ALTER TABLE `degree_requirements` MODIFY `group_hours_required` DECIMAL(8,4) NOT NULL");
    db_query("ALTER TABLE `draft_degree_requirements` MODIFY `group_hours_required` DECIMAL(8,4) NOT NULL");

    db_query("ALTER TABLE `student_transfer_courses` MODIFY `hours_awarded` DECIMAL(8,4) NOT NULL");
    db_query("ALTER TABLE `transfer_courses` MODIFY `min_hours` DECIMAL(8,4) NOT NULL");
    db_query("ALTER TABLE `transfer_courses` MODIFY `max_hours` DECIMAL(8,4) NOT NULL");


    // Also, expand the varchar fields for students table...
    db_query("ALTER TABLE `students` MODIFY `cumulative_hours` varchar(10) NOT NULL");
    db_query("ALTER TABLE `students` MODIFY `gpa` varchar(10) NOT NULL");


    fp_add_message(t("Updated database fields to allow for decimal hours."));
  }





}