You are here

update_test_schema.install in Zircon Profile 8

Update hooks and schema definition for the update_test_schema module.

File

core/modules/system/tests/modules/update_test_schema/update_test_schema.install
View source
<?php

/**
 * @file
 * Update hooks and schema definition for the update_test_schema module.
 */

/**
 * Implements hook_schema().
 *
 * The schema defined here will vary on state to allow for update hook testing.
 */
function update_test_schema_schema() {
  $schema_version = \Drupal::state()
    ->get('update_test_schema_version', 8000);
  $table = [
    'fields' => [
      'a' => [
        'type' => 'int',
        'not null' => TRUE,
      ],
      'b' => [
        'type' => 'blob',
        'not null' => FALSE,
      ],
    ],
  ];
  switch ($schema_version) {
    case 8001:

      // Add the index.
      $table['indexes']['test'] = [
        'a',
      ];
      break;
  }
  return [
    'update_test_schema_table' => $table,
  ];
}

// Update hooks are defined depending on state as well.
$schema_version = \Drupal::state()
  ->get('update_test_schema_version', 8000);
if ($schema_version >= 8001) {

  /**
   * Schema version 8001.
   */
  function update_test_schema_update_8001() {
    $table = [
      'fields' => [
        'a' => [
          'type' => 'int',
          'not null' => TRUE,
        ],
        'b' => [
          'type' => 'blob',
          'not null' => FALSE,
        ],
      ],
    ];

    // Add a column.
    db_add_index('update_test_schema_table', 'test', [
      'a',
    ], $table);
  }
}

Functions

Namesort descending Description
update_test_schema_schema Implements hook_schema().