function file_schema

Same name and namespace in other branches
  1. 10 core/modules/file/file.install \file_schema()
  2. 11.x core/modules/file/file.install \file_schema()
  3. 9 core/modules/file/file.install \file_schema()
  4. 8.9.x core/modules/file/file.install \file_schema()

Implements hook_schema().

File

core/modules/file/file.install, line 20

Code

function file_schema() : Schema {
  $tables[] = new Table(name: 'file_usage', description: 'Track where a file is used.', columns: [
    Column::int(name: 'fid', description: 'File ID.', unsigned: TRUE, notNull: TRUE),
    Column::varcharAscii(name: 'module', description: 'The name of the module that is using the file.', length: DRUPAL_EXTENSION_NAME_MAX_LENGTH, notNull: TRUE, default: new StringValue('')),
    Column::varcharAscii(name: 'type', description: 'The name of the object type in which the file is used.', length: 64, notNull: TRUE, default: new StringValue('')),
    Column::varcharAscii(name: 'id', description: 'The primary key of the object using the file.', length: 64, notNull: TRUE, default: new StringValue('0')),
    Column::int(name: 'count', description: 'The number of times this file is used by this object.', unsigned: TRUE, notNull: TRUE, default: new IntValue(0)),
  ], primaryKey: new PrimaryKey([
    'fid',
    'type',
    'id',
    'module',
  ]), indexes: [
    new Index(name: 'type_id', columns: [
      'type',
      'id',
    ]),
    new Index(name: 'fid_count', columns: [
      'fid',
      'count',
    ]),
    new Index(name: 'fid_module', columns: [
      'fid',
      'module',
    ]),
  ]);
  return new Schema(type: SchemaDefinitionType::Module, name: 'file', tables: $tables);
}

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