You are here

function date_api_update_6004 in Date 6.2

The "date_format" table is missing on boxes having MySQL 5.0.67 installed. There seems to be a bug in MySQL that prevents the creation of tables with a name "date_format" and indexes with the name "format".

We rename the table and index as a workaround.

File

./date_api.install, line 421

Code

function date_api_update_6004() {
  $ret = array();
  $schema['date_formats'] = array(
    'description' => 'For storing configured date formats.',
    'fields' => array(
      'dfid' => array(
        'description' => 'The date format identifier.',
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'format' => array(
        'description' => 'The date format string.',
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
      ),
      'type' => array(
        'description' => 'The date format type, e.g. medium.',
        'type' => 'varchar',
        'length' => 200,
        'not null' => TRUE,
      ),
      'locked' => array(
        'description' => 'Whether or not this format can be modified.',
        'type' => 'int',
        'size' => 'tiny',
        'default' => 0,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'dfid',
    ),
    'unique keys' => array(
      'formats' => array(
        'format',
        'type',
      ),
    ),
  );

  // Create missing table.
  if (!db_table_exists('date_format')) {
    db_create_table($ret, 'date_formats', $schema['date_formats']);
    date_formats_rebuild();
  }
  else {
    db_drop_unique_key($ret, 'date_format', 'format');
    if (db_table_exists('date_formats')) {
      db_drop_table($ret, 'date_format');
    }
    else {
      db_rename_table($ret, 'date_format', 'date_formats');
      db_add_unique_key($ret, 'date_formats', 'formats', array(
        'format',
        'type',
      ));
    }
  }
  return $ret;
}