972f9017616fedbddd1e1d53c46b3e5de41dab77
[yaffs-website] / update_test_schema.install
1 <?php
2
3 /**
4  * @file
5  * Update hooks and schema definition for the update_test_schema module.
6  */
7
8 /**
9  * Implements hook_schema().
10  *
11  * The schema defined here will vary on state to allow for update hook testing.
12  */
13 function update_test_schema_schema() {
14   $schema_version = \Drupal::state()->get('update_test_schema_version', 8000);
15   $table = [
16     'fields' => [
17       'a' => ['type' => 'int', 'not null' => TRUE],
18       'b' => ['type' => 'blob', 'not null' => FALSE],
19     ],
20   ];
21   switch ($schema_version) {
22     case 8001:
23       // Add the index.
24       $table['indexes']['test'] = ['a'];
25       break;
26   }
27   return ['update_test_schema_table' => $table];
28 }
29
30 // Update hooks are defined depending on state as well.
31 $schema_version = \Drupal::state()->get('update_test_schema_version', 8000);
32
33 if ($schema_version >= 8001) {
34   /**
35    * Schema version 8001.
36    */
37   function update_test_schema_update_8001() {
38     $table = [
39       'fields' => [
40         'a' => ['type' => 'int', 'not null' => TRUE],
41         'b' => ['type' => 'blob', 'not null' => FALSE],
42       ],
43     ];
44
45     // Add a column.
46     db_add_index('update_test_schema_table', 'test', ['a'], $table);
47   }
48 }