function user_update_8014

Create new {users_data} table.

Related topics

File

drupal/core/modules/user/user.install, line 897
Install, update and uninstall functions for the user module.

Code

function user_update_8014() {

  // Create the {users_data} table.
  db_create_table('users_data', array(
    'description' => 'Stores module data as key/value pairs per user.',
    'fields' => array(
      'uid' => array(
        'description' => 'Primary key: {users}.uid for user.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'module' => array(
        'description' => 'The name of the module declaring the variable.',
        'type' => 'varchar',
        'length' => 204,
        'not null' => TRUE,
        'default' => '',
      ),
      'name' => array(
        'description' => 'The identifier of the data.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'value' => array(
        'description' => 'The value.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
      ),
      'serialized' => array(
        'description' => 'Whether value is serialized.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'uid',
      'module',
      'name',
    ),
    'indexes' => array(
      'module' => array(
        'module',
      ),
      'name' => array(
        'name',
      ),
    ),
    'foreign keys' => array(
      'uid' => array(
        'users' => 'uid',
      ),
    ),
  ));

  // Create backup table for data migration.
  // Since the origin/owner of individual values in {users}.data is unknown,
  // other modules need to migrate their existing values from {_d7_users_data}.
  db_create_table('_d7_users_data', array(
    'description' => 'Backup of {users}.data for migration.',
    'fields' => array(
      'uid' => array(
        'description' => 'Primary Key: {users}.uid for user.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'name' => array(
        'description' => 'The name of the variable.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'value' => array(
        'description' => 'The serialized value of the variable.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'uid',
      'name',
    ),
    'foreign keys' => array(
      'uid' => array(
        'users' => 'uid',
      ),
    ),
  ));
}