database_test.install 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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_people_copy'] = $schema['test_people'];
  87. $schema['test_people_copy']['description'] = 'A duplicate version of the test_people table, used for additional tests.';
  88. $schema['test_one_blob'] = array(
  89. 'description' => 'A simple table including a BLOB field for testing BLOB behavior.',
  90. 'fields' => array(
  91. 'id' => array(
  92. 'description' => 'Simple unique ID.',
  93. 'type' => 'serial',
  94. 'not null' => TRUE,
  95. ),
  96. 'blob1' => array(
  97. 'description' => 'A BLOB field.',
  98. 'type' => 'blob',
  99. ),
  100. ),
  101. 'primary key' => array('id'),
  102. );
  103. $schema['test_two_blobs'] = array(
  104. 'description' => 'A simple test table with two BLOB fields.',
  105. 'fields' => array(
  106. 'id' => array(
  107. 'description' => 'Simple unique ID.',
  108. 'type' => 'serial',
  109. 'not null' => TRUE,
  110. ),
  111. 'blob1' => array(
  112. 'description' => 'A dummy BLOB field.',
  113. 'type' => 'blob',
  114. ),
  115. 'blob2' => array(
  116. 'description' => 'A second BLOB field.',
  117. 'type' => 'blob'
  118. ),
  119. ),
  120. 'primary key' => array('id'),
  121. );
  122. $schema['test_task'] = array(
  123. 'description' => 'A task list for people in the test table.',
  124. 'fields' => array(
  125. 'tid' => array(
  126. 'description' => 'Task ID, primary key.',
  127. 'type' => 'serial',
  128. 'not null' => TRUE,
  129. ),
  130. 'pid' => array(
  131. 'description' => 'The {test_people}.pid, foreign key for the test table.',
  132. 'type' => 'int',
  133. 'unsigned' => TRUE,
  134. 'not null' => TRUE,
  135. 'default' => 0,
  136. ),
  137. 'task' => array(
  138. 'description' => 'The task to be completed.',
  139. 'type' => 'varchar',
  140. 'length' => 255,
  141. 'not null' => TRUE,
  142. 'default' => '',
  143. ),
  144. 'priority' => array(
  145. 'description' => 'The priority of the task.',
  146. 'type' => 'int',
  147. 'unsigned' => TRUE,
  148. 'not null' => TRUE,
  149. 'default' => 0,
  150. ),
  151. ),
  152. 'primary key' => array('tid'),
  153. );
  154. $schema['test_null'] = array(
  155. 'description' => 'Basic test table for NULL value handling.',
  156. 'fields' => array(
  157. 'id' => array(
  158. 'type' => 'serial',
  159. 'unsigned' => TRUE,
  160. 'not null' => TRUE,
  161. ),
  162. 'name' => array(
  163. 'description' => "A person's name.",
  164. 'type' => 'varchar',
  165. 'length' => 255,
  166. 'not null' => FALSE,
  167. 'default' => '',
  168. ),
  169. 'age' => array(
  170. 'description' => "The person's age.",
  171. 'type' => 'int',
  172. 'unsigned' => TRUE,
  173. 'not null' => FALSE,
  174. 'default' => 0),
  175. ),
  176. 'primary key' => array('id'),
  177. 'unique keys' => array(
  178. 'name' => array('name')
  179. ),
  180. 'indexes' => array(
  181. 'ages' => array('age'),
  182. ),
  183. );
  184. $schema['test_serialized'] = array(
  185. 'description' => 'Basic test table for NULL value handling.',
  186. 'fields' => array(
  187. 'id' => array(
  188. 'type' => 'serial',
  189. 'unsigned' => TRUE,
  190. 'not null' => TRUE,
  191. ),
  192. 'name' => array(
  193. 'description' => "A person's name.",
  194. 'type' => 'varchar',
  195. 'length' => 255,
  196. 'not null' => FALSE,
  197. 'default' => '',
  198. ),
  199. 'info' => array(
  200. 'description' => "The person's data in serialized form.",
  201. 'type' => 'blob',
  202. 'serialize' => TRUE,
  203. ),
  204. ),
  205. 'primary key' => array('id'),
  206. 'unique keys' => array(
  207. 'name' => array('name')
  208. ),
  209. );
  210. return $schema;
  211. }