Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * @file
  5. * Install, update and uninstall functions for the hello module.
  6. */
  7.  
  8. use Drupal\Core\Database\Database;
  9.  
  10. /**
  11. * Implements hook_schema().
  12. */
  13. function hello_schema() {
  14. $schema['hello_node_history'] = [
  15. 'description' => 'Stores node update history.',
  16. 'fields' => [
  17. 'hid' => [
  18. 'description' => 'Primary Key: Unique history ID.',
  19. 'type' => 'serial',
  20. 'unsigned' => TRUE,
  21. 'not null' => TRUE,
  22. ],
  23. 'nid' => [
  24. 'description' => 'Node ID.',
  25. 'type' => 'int',
  26. 'unsigned' => TRUE,
  27. 'not null' => TRUE,
  28. ],
  29. 'uid' => [
  30. 'description' => 'Node ID.',
  31. 'type' => 'int',
  32. 'unsigned' => TRUE,
  33. 'not null' => TRUE,
  34. ],
  35. 'update_time' => [
  36. 'description' => 'Timestamp of node update.',
  37. 'type' => 'int',
  38. 'unsigned' => TRUE,
  39. 'not null' => TRUE,
  40. ],
  41. ],
  42. 'primary key' => ['hid'],
  43. 'indexes' => ['nid' => ['nid']],
  44. ];
  45.  
  46. return $schema;
  47. }
  48.  
  49. /**
  50. * Implements hook_update_N().
  51. */
  52. /**
  53. * Add a 'uid' field to the hello_node_history table.
  54. */
  55. function hello_update_8100() {
  56. $field_spec = [
  57. 'type' => 'int',
  58. 'description' => "Store user ID.",
  59. 'unsigned' => TRUE,
  60. 'not null' => TRUE,
  61. ];
  62. $schema = Database::getConnection()->schema();
  63. $schema->addField('hello_node_history', 'uid', $field_spec);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement