You are here

function course_update_6135 in Course 6

Same name and namespace in other branches
  1. 7.2 course.install \course_update_6135()
  2. 7 course.install \course_update_6135()

Naming conventions update.

File

./course.install, line 771
course.install Install and update functions for Courses.

Code

function course_update_6135() {
  $ret = array();

  // Change primary keys to int (so we can drop the primary key).
  db_change_field($ret, 'course_outline', 'snid', 'snid', array(
    'type' => 'int',
  ));
  db_change_field($ret, 'course_outline_fulfillment', 'sfid', 'sfid', array(
    'type' => 'int',
  ));

  // Drop old PK.
  db_drop_primary_key($ret, 'course_outline');
  db_drop_primary_key($ret, 'course_outline_fulfillment');

  // Drop affected indexes.
  db_drop_unique_key($ret, 'course_outline_fulfillment', 'snid_uid');
  db_drop_index($ret, 'course_outline_fulfillment', 'snid');

  // Rename columns, add back PK.
  db_change_field($ret, 'course_outline', 'snid', 'coid', array(
    'type' => 'serial',
    'not null' => TRUE,
    'unsigned' => TRUE,
  ), array(
    'primary key' => array(
      'coid',
    ),
  ));
  db_change_field($ret, 'course_outline_fulfillment', 'sfid', 'cofid', array(
    'type' => 'serial',
    'not null' => TRUE,
    'unsigned' => TRUE,
  ), array(
    'primary key' => array(
      'cofid',
    ),
  ));
  db_change_field($ret, 'course_outline_fulfillment', 'snid', 'coid', array(
    'type' => 'int',
    'not null' => TRUE,
    'unsigned' => TRUE,
    'default' => 0,
  ));

  // Change requirement_type/requirement_component fields.
  db_change_field($ret, 'course_outline', 'requirement_type', 'module', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  ));
  db_change_field($ret, 'course_outline', 'requirement_component', 'object_type', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  ));

  // Add keys back.
  db_add_unique_key($ret, 'course_outline_fulfillment', 'coid_uid', array(
    'coid',
    'uid',
  ));
  db_add_index($ret, 'course_outline_fulfillment', 'coid', array(
    'coid',
  ));

  // Update crid to match schema.
  db_change_field($ret, 'course_report', 'crid', 'crid', array(
    'type' => 'serial',
    'not null' => TRUE,
    'unsigned' => TRUE,
  ));
  return $ret;
}