You are here

function flag_update_5002 in Flag 5

Add a 'serial' primary key, fcid, to the flag_content table.

File

./flag.install, line 345
Flag module install/update hooks.

Code

function flag_update_5002() {
  $ret = array();
  if (!_flag_column_exists('flag_content', 'fcid')) {
    switch ($GLOBALS['db_type']) {
      case 'mysql':
      case 'mysqli':
        $ret[] = update_sql('ALTER TABLE {flag_content} DROP PRIMARY KEY');
        $ret[] = update_sql('ALTER TABLE {flag_content} ADD fcid int unsigned NOT NULL auto_increment FIRST, ADD PRIMARY KEY (fcid)');
        $ret[] = update_sql('ALTER TABLE {flag_content} ADD UNIQUE INDEX fid_content_type_content_id_uid (fid, content_type, content_id, uid)');
        break;
      case 'pgsql':
        $ret[] = update_sql('ALTER TABLE {flag_content} DROP CONSTRAINT {flag_content}_pkey');
        db_add_column($ret, 'flag_content', 'fcid', 'serial');
        $ret[] = update_sql('ALTER TABLE {flag_content} ADD PRIMARY KEY (fcid)');
        $ret[] = update_sql('ALTER TABLE {flag_content} ADD CONSTRAINT {flag_content}_fid_content_type_content_id_uid_key UNIQUE (fid, content_type, content_id, uid)');
        break;
    }
  }
  return $ret;
}