function SessionHandler::schemaDefinition

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Session/SessionHandler.php \Drupal\Core\Session\SessionHandler::schemaDefinition()

Defines the schema for the session table.

@internal

1 call to SessionHandler::schemaDefinition()
SessionHandler::ensureTableExists in core/lib/Drupal/Core/Session/SessionHandler.php
Check if the session table exists and create it if not.

File

core/lib/Drupal/Core/Session/SessionHandler.php, line 164

Class

SessionHandler
Default session handler.

Namespace

Drupal\Core\Session

Code

protected function schemaDefinition() : array {
    $schema = [
        '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,
                'size' => 'big',
            ],
            'session' => [
                'description' => 'The serialized contents of the user\'s session, an array of name/value pairs that persists across page requests by this session ID. Drupal loads the user\'s 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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.