You are here

function uc_product_update_1 in Ubercart 5

File

uc_product/uc_product.install, line 102
Database installation, uninstallation, and updates for the product module.

Code

function uc_product_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_class_choices} CHANGE name name varchar(255) NOT NULL");
      $ret[] = update_sql("ALTER TABLE {uc_class_fields} CHANGE name name varchar(255) NOT NULL, DROP COLUMN title");
      $ret[] = update_sql("ALTER TABLE {uc_product_classes} CHANGE name name varchar(255) NOT NULL");
      $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} CHANGE value value varchar(255) NOT NULL, ADD PRIMARY KEY (nid, cfid, value)");
      $ret[] = update_sql("ALTER TABLE {uc_products} CHANGE model model varchar(255) NOT NULL");
      break;
    case 'pgsql':
      db_change_column($ret, 'uc_class_choices', 'name', 'name', 'varchar(255)', array(
        'not null' => true,
        'default' => "''",
      ));
      db_change_column($ret, 'uc_class_fields', 'name', 'name', 'varchar(255)', array(
        'not null' => true,
        'default' => "''",
      ));
      $ret[] = update_sql("ALTER TABLE {uc_class_fields} DROP title");
      db_change_column($ret, 'uc_product_classes', 'name', 'name', 'varchar(255)', array(
        'not null' => true,
        'default' => "''",
      ));
      db_change_column($ret, 'uc_product_class_choices', 'value', 'value', 'varchar(255)', array(
        'not null' => true,
        'default' => "''",
      ));
      $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} ADD PRIMARY KEY (nid, cfid, value)");
      db_change_column($ret, 'uc_products', 'model', 'model', 'varchar(255)', array(
        'not null' => true,
        'default' => "''",
      ));
      break;
  }
  if ($max_id = db_result(db_query_range("SELECT cfid FROM {uc_class_fields} ORDER BY cfid DESC", 0, 1))) {
    $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{uc_class_fields}_cfid', %d)", $max_id);
  }
  return $ret;
}