Version 1
[yaffs-website] / web / core / modules / system / tests / modules / update_test_schema / update_test_schema.install
diff --git a/web/core/modules/system/tests/modules/update_test_schema/update_test_schema.install b/web/core/modules/system/tests/modules/update_test_schema/update_test_schema.install
new file mode 100644 (file)
index 0000000..972f901
--- /dev/null
@@ -0,0 +1,48 @@
+<?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);
+  }
+}