database_test.install 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the database_test module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. *
  9. * The database tests use the database API which depends on schema
  10. * information for certain operations on certain databases.
  11. * Therefore, the schema must actually be declared in a normal module
  12. * like any other, not directly in the test file.
  13. */
  14. function database_test_schema() {
  15. $schema['test'] = array(
  16. 'description' => 'Basic test table for the database unit tests.',
  17. 'fields' => array(
  18. 'id' => array(
  19. 'type' => 'serial',
  20. 'unsigned' => TRUE,
  21. 'not null' => TRUE,
  22. ),
  23. 'name' => array(
  24. 'description' => "A person's name",
  25. 'type' => 'varchar',
  26. 'length' => 255,
  27. 'not null' => TRUE,
  28. 'default' => '',
  29. 'binary' => TRUE,
  30. ),
  31. 'age' => array(
  32. 'description' => "The person's age",
  33. 'type' => 'int',
  34. 'unsigned' => TRUE,
  35. 'not null' => TRUE,
  36. 'default' => 0,
  37. ),
  38. 'job' => array(
  39. 'description' => "The person's job",
  40. 'type' => 'varchar',
  41. 'length' => 255,
  42. 'not null' => TRUE,
  43. 'default' => 'Undefined',
  44. ),
  45. ),
  46. 'primary key' => array('id'),
  47. 'unique keys' => array(
  48. 'name' => array('name')
  49. ),
  50. 'indexes' => array(
  51. 'ages' => array('age'),
  52. ),
  53. );
  54. // This is an alternate version of the same table that is structured the same
  55. // but has a non-serial Primary Key.
  56. $schema['test_people'] = array(
  57. 'description' => 'A duplicate version of the test table, used for additional tests.',
  58. 'fields' => array(
  59. 'name' => array(
  60. 'description' => "A person's name",
  61. 'type' => 'varchar',
  62. 'length' => 255,
  63. 'not null' => TRUE,
  64. 'default' => '',
  65. ),
  66. 'age' => array(
  67. 'description' => "The person's age",
  68. 'type' => 'int',
  69. 'unsigned' => TRUE,
  70. 'not null' => TRUE,
  71. 'default' => 0,
  72. ),
  73. 'job' => array(
  74. 'description' => "The person's job",
  75. 'type' => 'varchar',
  76. 'length' => 255,
  77. 'not null' => TRUE,
  78. 'default' => '',
  79. ),
  80. ),
  81. 'primary key' => array('job'),
  82. 'indexes' => array(
  83. 'ages' => array('age'),
  84. ),
  85. );
  86. $schema['test_one_blob'] = array(
  87. 'description' => 'A simple table including a BLOB field for testing BLOB behavior.',
  88. 'fields' => array(
  89. 'id' => array(
  90. 'description' => 'Simple unique ID.',
  91. 'type' => 'serial',
  92. 'not null' => TRUE,
  93. ),
  94. 'blob1' => array(
  95. 'description' => 'A BLOB field.',
  96. 'type' => 'blob',
  97. ),
  98. ),
  99. 'primary key' => array('id'),
  100. );
  101. $schema['test_two_blobs'] = array(
  102. 'description' => 'A simple test table with two BLOB fields.',
  103. 'fields' => array(
  104. 'id' => array(
  105. 'description' => 'Simple unique ID.',
  106. 'type' => 'serial',
  107. 'not null' => TRUE,
  108. ),
  109. 'blob1' => array(
  110. 'description' => 'A dummy BLOB field.',
  111. 'type' => 'blob',
  112. ),
  113. 'blob2' => array(
  114. 'description' => 'A second BLOB field.',
  115. 'type' => 'blob'
  116. ),
  117. ),
  118. 'primary key' => array('id'),
  119. );
  120. $schema['test_task'] = array(
  121. 'description' => 'A task list for people in the test table.',
  122. 'fields' => array(
  123. 'tid' => array(
  124. 'description' => 'Task ID, primary key.',
  125. 'type' => 'serial',
  126. 'not null' => TRUE,
  127. ),
  128. 'pid' => array(
  129. 'description' => 'The {test_people}.pid, foreign key for the test table.',
  130. 'type' => 'int',
  131. 'unsigned' => TRUE,
  132. 'not null' => TRUE,
  133. 'default' => 0,
  134. ),
  135. 'task' => array(
  136. 'description' => 'The task to be completed.',
  137. 'type' => 'varchar',
  138. 'length' => 255,
  139. 'not null' => TRUE,
  140. 'default' => '',
  141. ),
  142. 'priority' => array(
  143. 'description' => 'The priority of the task.',
  144. 'type' => 'int',
  145. 'unsigned' => TRUE,
  146. 'not null' => TRUE,
  147. 'default' => 0,
  148. ),
  149. ),
  150. 'primary key' => array('tid'),
  151. );
  152. $schema['test_null'] = array(
  153. 'description' => 'Basic test table for NULL value handling.',
  154. 'fields' => array(
  155. 'id' => array(
  156. 'type' => 'serial',
  157. 'unsigned' => TRUE,
  158. 'not null' => TRUE,
  159. ),
  160. 'name' => array(
  161. 'description' => "A person's name.",
  162. 'type' => 'varchar',
  163. 'length' => 255,
  164. 'not null' => FALSE,
  165. 'default' => '',
  166. ),
  167. 'age' => array(
  168. 'description' => "The person's age.",
  169. 'type' => 'int',
  170. 'unsigned' => TRUE,
  171. 'not null' => FALSE,
  172. 'default' => 0),
  173. ),
  174. 'primary key' => array('id'),
  175. 'unique keys' => array(
  176. 'name' => array('name')
  177. ),
  178. 'indexes' => array(
  179. 'ages' => array('age'),
  180. ),
  181. );
  182. $schema['test_serialized'] = array(
  183. 'description' => 'Basic test table for NULL value handling.',
  184. 'fields' => array(
  185. 'id' => array(
  186. 'type' => 'serial',
  187. 'unsigned' => TRUE,
  188. 'not null' => TRUE,
  189. ),
  190. 'name' => array(
  191. 'description' => "A person's name.",
  192. 'type' => 'varchar',
  193. 'length' => 255,
  194. 'not null' => FALSE,
  195. 'default' => '',
  196. ),
  197. 'info' => array(
  198. 'description' => "The person's data in serialized form.",
  199. 'type' => 'blob',
  200. 'serialize' => TRUE,
  201. ),
  202. ),
  203. 'primary key' => array('id'),
  204. 'unique keys' => array(
  205. 'name' => array('name')
  206. ),
  207. );
  208. return $schema;
  209. }