database_test.install 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. $schema['test_classtype'] = array(
  55. 'description' => 'A duplicate version of the test table, used for fetch_style PDO::FETCH_CLASSTYPE tests.',
  56. 'fields' => array(
  57. 'classname' => array(
  58. 'description' => "A custom class name",
  59. 'type' => 'varchar',
  60. 'length' => 255,
  61. 'not null' => TRUE,
  62. 'default' => '',
  63. ),
  64. 'name' => array(
  65. 'description' => "A person's name",
  66. 'type' => 'varchar',
  67. 'length' => 255,
  68. 'not null' => TRUE,
  69. 'default' => '',
  70. ),
  71. 'age' => array(
  72. 'description' => "The person's age",
  73. 'type' => 'int',
  74. 'unsigned' => TRUE,
  75. 'not null' => TRUE,
  76. 'default' => 0,
  77. ),
  78. 'job' => array(
  79. 'description' => "The person's job",
  80. 'type' => 'varchar',
  81. 'length' => 255,
  82. 'not null' => TRUE,
  83. 'default' => '',
  84. ),
  85. ),
  86. 'primary key' => array('job'),
  87. 'indexes' => array(
  88. 'ages' => array('age'),
  89. ),
  90. );
  91. // This is an alternate version of the same table that is structured the same
  92. // but has a non-serial Primary Key.
  93. $schema['test_people'] = array(
  94. 'description' => 'A duplicate version of the test table, used for additional tests.',
  95. 'fields' => array(
  96. 'name' => array(
  97. 'description' => "A person's name",
  98. 'type' => 'varchar',
  99. 'length' => 255,
  100. 'not null' => TRUE,
  101. 'default' => '',
  102. ),
  103. 'age' => array(
  104. 'description' => "The person's age",
  105. 'type' => 'int',
  106. 'unsigned' => TRUE,
  107. 'not null' => TRUE,
  108. 'default' => 0,
  109. ),
  110. 'job' => array(
  111. 'description' => "The person's job",
  112. 'type' => 'varchar',
  113. 'length' => 255,
  114. 'not null' => TRUE,
  115. 'default' => '',
  116. ),
  117. ),
  118. 'primary key' => array('job'),
  119. 'indexes' => array(
  120. 'ages' => array('age'),
  121. ),
  122. );
  123. $schema['test_people_copy'] = $schema['test_people'];
  124. $schema['test_people_copy']['description'] = 'A duplicate version of the test_people table, used for additional tests.';
  125. $schema['test_one_blob'] = array(
  126. 'description' => 'A simple table including a BLOB field for testing BLOB behavior.',
  127. 'fields' => array(
  128. 'id' => array(
  129. 'description' => 'Simple unique ID.',
  130. 'type' => 'serial',
  131. 'not null' => TRUE,
  132. ),
  133. 'blob1' => array(
  134. 'description' => 'A BLOB field.',
  135. 'type' => 'blob',
  136. ),
  137. ),
  138. 'primary key' => array('id'),
  139. );
  140. $schema['test_two_blobs'] = array(
  141. 'description' => 'A simple test table with two BLOB fields.',
  142. 'fields' => array(
  143. 'id' => array(
  144. 'description' => 'Simple unique ID.',
  145. 'type' => 'serial',
  146. 'not null' => TRUE,
  147. ),
  148. 'blob1' => array(
  149. 'description' => 'A dummy BLOB field.',
  150. 'type' => 'blob',
  151. ),
  152. 'blob2' => array(
  153. 'description' => 'A second BLOB field.',
  154. 'type' => 'blob'
  155. ),
  156. ),
  157. 'primary key' => array('id'),
  158. );
  159. $schema['test_task'] = array(
  160. 'description' => 'A task list for people in the test table.',
  161. 'fields' => array(
  162. 'tid' => array(
  163. 'description' => 'Task ID, primary key.',
  164. 'type' => 'serial',
  165. 'not null' => TRUE,
  166. ),
  167. 'pid' => array(
  168. 'description' => 'The {test_people}.pid, foreign key for the test table.',
  169. 'type' => 'int',
  170. 'unsigned' => TRUE,
  171. 'not null' => TRUE,
  172. 'default' => 0,
  173. ),
  174. 'task' => array(
  175. 'description' => 'The task to be completed.',
  176. 'type' => 'varchar',
  177. 'length' => 255,
  178. 'not null' => TRUE,
  179. 'default' => '',
  180. ),
  181. 'priority' => array(
  182. 'description' => 'The priority of the task.',
  183. 'type' => 'int',
  184. 'unsigned' => TRUE,
  185. 'not null' => TRUE,
  186. 'default' => 0,
  187. ),
  188. ),
  189. 'primary key' => array('tid'),
  190. );
  191. $schema['test_null'] = array(
  192. 'description' => 'Basic test table for NULL value handling.',
  193. 'fields' => array(
  194. 'id' => array(
  195. 'type' => 'serial',
  196. 'unsigned' => TRUE,
  197. 'not null' => TRUE,
  198. ),
  199. 'name' => array(
  200. 'description' => "A person's name.",
  201. 'type' => 'varchar',
  202. 'length' => 255,
  203. 'not null' => FALSE,
  204. 'default' => '',
  205. ),
  206. 'age' => array(
  207. 'description' => "The person's age.",
  208. 'type' => 'int',
  209. 'unsigned' => TRUE,
  210. 'not null' => FALSE,
  211. 'default' => 0),
  212. ),
  213. 'primary key' => array('id'),
  214. 'unique keys' => array(
  215. 'name' => array('name')
  216. ),
  217. 'indexes' => array(
  218. 'ages' => array('age'),
  219. ),
  220. );
  221. $schema['test_serialized'] = array(
  222. 'description' => 'Basic test table for NULL value handling.',
  223. 'fields' => array(
  224. 'id' => array(
  225. 'type' => 'serial',
  226. 'unsigned' => TRUE,
  227. 'not null' => TRUE,
  228. ),
  229. 'name' => array(
  230. 'description' => "A person's name.",
  231. 'type' => 'varchar',
  232. 'length' => 255,
  233. 'not null' => FALSE,
  234. 'default' => '',
  235. ),
  236. 'info' => array(
  237. 'description' => "The person's data in serialized form.",
  238. 'type' => 'blob',
  239. 'serialize' => TRUE,
  240. ),
  241. ),
  242. 'primary key' => array('id'),
  243. 'unique keys' => array(
  244. 'name' => array('name')
  245. ),
  246. );
  247. $schema['virtual'] = array(
  248. 'description' => 'Basic test table with a reserved name.',
  249. 'fields' => array(
  250. 'id' => array(
  251. 'type' => 'serial',
  252. 'unsigned' => TRUE,
  253. 'not null' => TRUE,
  254. ),
  255. 'function' => array(
  256. 'description' => "A column with a reserved name.",
  257. 'type' => 'varchar',
  258. 'length' => 255,
  259. 'not null' => FALSE,
  260. 'default' => '',
  261. ),
  262. ),
  263. 'primary key' => array('id'),
  264. );
  265. $schema['TEST_UPPERCASE'] = $schema['test'];
  266. $schema['test_db_specific_datatype'] = array(
  267. 'description' => 'Schema with database specific data type.',
  268. 'fields' => array(
  269. 'id' => array(
  270. 'type' => 'serial',
  271. 'unsigned' => TRUE,
  272. 'not null' => TRUE,
  273. ),
  274. 'age' => array(
  275. 'description' => "The person's age.",
  276. 'mysql_type' => 'tinyint',
  277. 'pgsql_type' => 'smallint',
  278. 'sqlite_type' => 'tinyint',
  279. 'not null' => FALSE,
  280. 'default' => 0,
  281. ),
  282. ),
  283. 'primary key' => array('id'),
  284. );
  285. return $schema;
  286. }