function comment_update_7003

7.x comment.install comment_update_7003()

Split {comment}.timestamp into 'created' and 'changed', improve indexing on {comment}.

Related topics

File

drupal-7.x/modules/comment/comment.install, line 187
Install, update and uninstall functions for the comment module.

Code

function comment_update_7003() {
  // Drop the old indexes.
  db_drop_index('comment', 'status');
  db_drop_index('comment', 'pid');

  // Create a created column.
  db_add_field('comment', 'created', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));

  // Rename the timestamp column to changed.
  db_change_field('comment', 'timestamp', 'changed', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));

  // Migrate the data.
  // @todo db_update() should support this.
  db_query('UPDATE {comment} SET created = changed');

  // Recreate the indexes.
  // The 'comment_num_new' index is optimized for comment_num_new()
  // and comment_new_page_count().
  db_add_index('comment', 'comment_num_new', array('nid', 'status', 'created', 'cid', 'thread'));
  db_add_index('comment', 'comment_pid_status', array('pid', 'status'));
}