function user_schema

Implements hook_schema().

File

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

Code

function user_schema() {

  // The table name here is plural, despite Drupal table naming standards,
  // because "user" is a reserved word in many databases.
  $schema['users'] = array(
    'description' => 'Stores user data.',
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Unique user ID.',
        'default' => 0,
      ),
      'uuid' => array(
        'description' => 'Unique Key: Universally unique identifier for this entity.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 60,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Unique user name.',
      ),
      'langcode' => array(
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
        'description' => "The {language}.langcode of the user's profile.",
      ),
      'pass' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => "User's password (hashed).",
      ),
      'mail' => array(
        'type' => 'varchar',
        'length' => 254,
        'not null' => FALSE,
        'default' => '',
        'description' => "User's e-mail address.",
      ),
      'theme' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => "User's default theme.",
      ),
      'signature' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => "User's signature.",
      ),
      'signature_format' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'description' => 'The filter format ID of the signature.',
      ),
      'created' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Timestamp for when user was created.',
      ),
      'access' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Timestamp for previous time user accessed the site.',
      ),
      'login' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => "Timestamp for user's last login.",
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'Whether the user is active(1) or blocked(0).',
      ),
      'timezone' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => FALSE,
        'description' => "User's time zone.",
      ),
      'preferred_langcode' => array(
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The {language}.langcode that the user prefers for receiving emails and viewing the site.',
      ),
      'preferred_admin_langcode' => array(
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The {language}.langcode that the user prefers for viewing administration pages.',
      ),
      'init' => array(
        'type' => 'varchar',
        'length' => 254,
        'not null' => FALSE,
        'default' => '',
        'description' => 'E-mail address used for initial account creation.',
      ),
    ),
    'indexes' => array(
      'access' => array(
        'access',
      ),
      'created' => array(
        'created',
      ),
      'mail' => array(
        'mail',
      ),
    ),
    'unique keys' => array(
      'uuid' => array(
        'uuid',
      ),
      'name' => array(
        'name',
      ),
    ),
    'primary key' => array(
      'uid',
    ),
    'foreign keys' => array(
      'signature_format' => array(
        'table' => 'filter_format',
        'columns' => array(
          'signature_format' => 'format',
        ),
      ),
    ),
  );
  $schema['role_permission'] = array(
    'description' => 'Stores the permissions assigned to user roles.',
    'fields' => array(
      'rid' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'description' => 'Foreign Key: {role}.rid.',
      ),
      'permission' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'A single permission granted to the role identified by rid.',
      ),
      'module' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => "The module declaring the permission.",
      ),
    ),
    'primary key' => array(
      'rid',
      'permission',
    ),
    'indexes' => array(
      'permission' => array(
        'permission',
      ),
    ),
    'foreign keys' => array(
      'role' => array(
        'table' => 'role',
        'columns' => array(
          'rid' => 'rid',
        ),
      ),
    ),
  );
  $schema['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',
      ),
    ),
  );
  $schema['users_roles'] = array(
    'description' => 'Maps users to roles.',
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Primary Key: {users}.uid for user.',
      ),
      'rid' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'description' => 'Primary Key: {role}.rid for role.',
      ),
    ),
    'primary key' => array(
      'uid',
      'rid',
    ),
    'indexes' => array(
      'rid' => array(
        'rid',
      ),
    ),
    'foreign keys' => array(
      'user' => array(
        'table' => 'users',
        'columns' => array(
          'uid' => 'uid',
        ),
      ),
      'role' => array(
        'table' => 'role',
        'columns' => array(
          'rid' => 'rid',
        ),
      ),
    ),
  );
  return $schema;
}