You are here

function system_schema in Drupal 8

Same name and namespace in other branches
  1. 6 modules/system/system.install \system_schema()
  2. 7 modules/system/system.install \system_schema()
  3. 9 core/modules/system/system.install \system_schema()

Implements hook_schema().

2 calls to system_schema()
install_begin_request in core/includes/install.core.inc
Begins an installation request, modifying the installation state as needed.
install_verify_database_ready in core/includes/install.core.inc
Verify that the database is ready (no existing Drupal installation).

File

core/modules/system/system.install, line 1407
Install, update and uninstall functions for the system module.

Code

function system_schema() {
  $schema['key_value'] = [
    'description' => 'Generic key-value storage table. See the state system for an example.',
    'fields' => [
      'collection' => [
        'description' => 'A named collection of key and value pairs.',
        'type' => 'varchar_ascii',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ],
      'name' => [
        'description' => 'The key of the key-value pair. As KEY is a SQL reserved keyword, name was chosen instead.',
        'type' => 'varchar_ascii',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ],
      'value' => [
        'description' => 'The value.',
        'type' => 'blob',
        'not null' => TRUE,
        'size' => 'big',
      ],
    ],
    'primary key' => [
      'collection',
      'name',
    ],
  ];
  $schema['key_value_expire'] = [
    'description' => 'Generic key/value storage table with an expiration.',
    'fields' => [
      'collection' => [
        'description' => 'A named collection of key and value pairs.',
        'type' => 'varchar_ascii',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ],
      'name' => [
        // KEY is an SQL reserved word, so use 'name' as the key's field name.
        'description' => 'The key of the key/value pair.',
        'type' => 'varchar_ascii',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ],
      'value' => [
        'description' => 'The value of the key/value pair.',
        'type' => 'blob',
        'not null' => TRUE,
        'size' => 'big',
      ],
      'expire' => [
        'description' => 'The time since Unix epoch in seconds when this item expires. Defaults to the maximum possible time.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 2147483647,
      ],
    ],
    'primary key' => [
      'collection',
      'name',
    ],
    'indexes' => [
      'all' => [
        'name',
        'collection',
        'expire',
      ],
      'expire' => [
        'expire',
      ],
    ],
  ];
  $schema['sequences'] = [
    'description' => 'Stores IDs.',
    'fields' => [
      'value' => [
        'description' => 'The value of the sequence.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
    ],
    'primary key' => [
      'value',
    ],
  ];
  $schema['sessions'] = [
    'description' => "Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated.",
    'fields' => [
      'uid' => [
        'description' => 'The {users}.uid corresponding to a session, or 0 for anonymous user.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'sid' => [
        'description' => "A session ID (hashed). The value is generated by Drupal's session handlers.",
        'type' => 'varchar_ascii',
        'length' => 128,
        'not null' => TRUE,
      ],
      'hostname' => [
        'description' => 'The IP address that last used this session ID (sid).',
        'type' => 'varchar_ascii',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ],
      'timestamp' => [
        'description' => 'The Unix timestamp when this session last requested a page. Old records are purged by PHP automatically.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'session' => [
        'description' => 'The serialized contents of $_SESSION, an array of name/value pairs that persists across page requests by this session ID. Drupal loads $_SESSION from here at the start of each request and saves it at the end.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
      ],
    ],
    'primary key' => [
      'sid',
    ],
    'indexes' => [
      'timestamp' => [
        'timestamp',
      ],
      'uid' => [
        'uid',
      ],
    ],
    'foreign keys' => [
      'session_user' => [
        'table' => 'users',
        'columns' => [
          'uid' => 'uid',
        ],
      ],
    ],
  ];
  return $schema;
}