You are here

perfmon.install in Performance monitor 8

Same filename and directory in other branches
  1. 7 perfmon.install

Install, update and uninstall functions for the perfmon module.

File

perfmon.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the perfmon module.
 */

/**
 * Implements hook_schema().
 */
function perfmon_schema() {
  $schema['perfmon'] = [
    'fields' => [
      'id' => [
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Unique perfmon log record id',
      ],
      'testname' => [
        'type' => 'varchar',
        'length' => 160,
        'not null' => TRUE,
        'default' => '',
      ],
      'result' => [
        'type' => 'varchar',
        'length' => 160,
        'not null' => TRUE,
        'default' => 0,
      ],
      'lastrun' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => [
      'id',
    ],
    'unique keys' => [
      'testname' => [
        'testname',
      ],
    ],
  ];
  $schema['perfmon_test'] = [
    'fields' => [
      'id' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'testname' => [
        'type' => 'varchar',
        'length' => 160,
        'not null' => TRUE,
        'default' => 0,
      ],
      'data' => [
        'type' => 'varchar',
        'length' => 160,
        'not null' => TRUE,
        'default' => '',
      ],
    ],
    'primary key' => [
      'id',
    ],
  ];
  return $schema;
}

/**
 * Add serial id key to perfmon talbe.
 */
function perfmon_update_8101() {
  $spec = [
    'type' => 'serial',
    'not null' => TRUE,
    'default' => 0,
  ];
  $schema = \Drupal::database()
    ->schema();
  $schema
    ->addField('perfmon', 'id', $spec);
}

/**
 * Update keys of perfmon table.
 */
function perfmon_update_81002() {
  $schema = \Drupal::database()
    ->schema();
  $schema
    ->dropPrimaryKey('perfmon');
  $schema
    ->addPrimaryKey('perfmon', [
    'id',
  ]);
  $schema
    ->addUniqueKey('perfmon', 'testname', [
    'testname',
  ]);
}

Functions

Namesort descending Description
perfmon_schema Implements hook_schema().
perfmon_update_81002 Update keys of perfmon table.
perfmon_update_8101 Add serial id key to perfmon talbe.