Version 1
[yaffs-website] / web / core / modules / system / tests / modules / database_test / database_test.install
1 <?php
2
3 /**
4  * @file
5  * Install, update and uninstall functions for the database_test module.
6  */
7
8 /**
9  * Implements hook_schema().
10  *
11  * The database tests use the database API which depends on schema
12  * information for certain operations on certain databases.
13  * Therefore, the schema must actually be declared in a normal module
14  * like any other, not directly in the test file.
15  */
16 function database_test_schema() {
17   $schema['test'] = [
18     'description' => 'Basic test table for the database unit tests.',
19     'fields' => [
20       'id' => [
21         'type' => 'serial',
22         'unsigned' => TRUE,
23         'not null' => TRUE,
24       ],
25       'name' => [
26         'description' => "A person's name",
27         'type' => 'varchar_ascii',
28         'length' => 255,
29         'not null' => TRUE,
30         'default' => '',
31         'binary' => TRUE,
32       ],
33       'age' => [
34         'description' => "The person's age",
35         'type' => 'int',
36         'unsigned' => TRUE,
37         'not null' => TRUE,
38         'default' => 0,
39       ],
40       'job' => [
41         'description' => "The person's job",
42         'type' => 'varchar',
43         'length' => 255,
44         'not null' => TRUE,
45         'default' => 'Undefined',
46       ],
47     ],
48     'primary key' => ['id'],
49     'unique keys' => [
50       'name' => ['name']
51     ],
52     'indexes' => [
53       'ages' => ['age'],
54     ],
55   ];
56
57   // This is an alternate version of the same table that is structured the same
58   // but has a non-serial Primary Key.
59   $schema['test_people'] = [
60     'description' => 'A duplicate version of the test table, used for additional tests.',
61     'fields' => [
62       'name' => [
63         'description' => "A person's name",
64         'type' => 'varchar',
65         'length' => 255,
66         'not null' => TRUE,
67         'default' => '',
68       ],
69       'age' => [
70         'description' => "The person's age",
71         'type' => 'int',
72         'unsigned' => TRUE,
73         'not null' => TRUE,
74         'default' => 0,
75       ],
76       'job' => [
77         'description' => "The person's job",
78         'type' => 'varchar_ascii',
79         'length' => 255,
80         'not null' => TRUE,
81         'default' => '',
82       ],
83     ],
84     'primary key' => ['job'],
85     'indexes' => [
86       'ages' => ['age'],
87     ],
88   ];
89
90   $schema['test_people_copy'] = [
91     'description' => 'A duplicate version of the test_people table, used for additional tests.',
92     'fields' => [
93       'name' => [
94         'description' => "A person's name",
95         'type' => 'varchar',
96         'length' => 255,
97         'not null' => TRUE,
98         'default' => '',
99       ],
100       'age' => [
101         'description' => "The person's age",
102         'type' => 'int',
103         'unsigned' => TRUE,
104         'not null' => TRUE,
105         'default' => 0,
106       ],
107       'job' => [
108         'description' => "The person's job",
109         'type' => 'varchar_ascii',
110         'length' => 255,
111         'not null' => TRUE,
112         'default' => '',
113       ],
114     ],
115     'primary key' => ['job'],
116     'indexes' => [
117       'ages' => ['age'],
118     ],
119   ];
120
121   $schema['test_one_blob'] = [
122     'description' => 'A simple table including a BLOB field for testing BLOB behavior.',
123     'fields' => [
124       'id' => [
125         'description' => 'Simple unique ID.',
126         'type' => 'serial',
127         'not null' => TRUE,
128       ],
129       'blob1' => [
130         'description' => 'A BLOB field.',
131         'type' => 'blob',
132       ],
133     ],
134     'primary key' => ['id'],
135     ];
136
137   $schema['test_two_blobs'] = [
138     'description' => 'A simple test table with two BLOB fields.',
139     'fields' => [
140       'id' => [
141         'description' => 'Simple unique ID.',
142         'type' => 'serial',
143         'not null' => TRUE,
144       ],
145       'blob1' => [
146         'description' => 'A dummy BLOB field.',
147         'type' => 'blob',
148       ],
149       'blob2' => [
150         'description' => 'A second BLOB field.',
151         'type' => 'blob'
152       ],
153     ],
154     'primary key' => ['id'],
155     ];
156
157   $schema['test_task'] = [
158     'description' => 'A task list for people in the test table.',
159     'fields' => [
160       'tid' => [
161         'description' => 'Task ID, primary key.',
162         'type' => 'serial',
163         'not null' => TRUE,
164       ],
165       'pid' => [
166         'description' => 'The {test_people}.pid, foreign key for the test table.',
167         'type' => 'int',
168         'unsigned' => TRUE,
169         'not null' => TRUE,
170         'default' => 0,
171       ],
172       'task' => [
173         'description' => 'The task to be completed.',
174         'type' => 'varchar',
175         'length' => 255,
176         'not null' => TRUE,
177         'default' => '',
178       ],
179       'priority' => [
180         'description' => 'The priority of the task.',
181         'type' => 'int',
182         'unsigned' => TRUE,
183         'not null' => TRUE,
184         'default' => 0,
185       ],
186     ],
187     'primary key' => ['tid'],
188   ];
189
190   $schema['test_null'] = [
191     'description' => 'Basic test table for NULL value handling.',
192     'fields' => [
193       'id' => [
194         'type' => 'serial',
195         'unsigned' => TRUE,
196         'not null' => TRUE,
197       ],
198       'name' => [
199         'description' => "A person's name.",
200         'type' => 'varchar_ascii',
201         'length' => 255,
202         'not null' => FALSE,
203         'default' => '',
204       ],
205       'age' => [
206         'description' => "The person's age.",
207         'type' => 'int',
208         'unsigned' => TRUE,
209         'not null' => FALSE,
210         'default' => 0],
211     ],
212     'primary key' => ['id'],
213     'unique keys' => [
214       'name' => ['name']
215     ],
216     'indexes' => [
217       'ages' => ['age'],
218     ],
219   ];
220
221   $schema['test_serialized'] = [
222     'description' => 'Basic test table for NULL value handling.',
223     'fields' => [
224       'id' => [
225         'type' => 'serial',
226         'unsigned' => TRUE,
227         'not null' => TRUE,
228       ],
229       'name' => [
230         'description' => "A person's name.",
231         'type' => 'varchar_ascii',
232         'length' => 255,
233         'not null' => FALSE,
234         'default' => '',
235       ],
236       'info' => [
237         'description' => "The person's data in serialized form.",
238         'type' => 'blob',
239         'serialize' => TRUE,
240       ],
241     ],
242     'primary key' => ['id'],
243     'unique keys' => [
244       'name' => ['name']
245     ],
246   ];
247
248   $schema['test_composite_primary'] = [
249     'description' => 'Basic test table with a composite primary key',
250     'fields' => [
251       'name' => [
252         'description' => "A person's name",
253         'type' => 'varchar',
254         'length' => 50,
255         'not null' => TRUE,
256         'default' => '',
257         'binary' => TRUE,
258       ],
259       'age' => [
260         'description' => "The person's age",
261         'type' => 'int',
262         'unsigned' => TRUE,
263         'not null' => TRUE,
264         'default' => 0,
265       ],
266       'job' => [
267         'description' => "The person's job",
268         'type' => 'varchar',
269         'length' => 255,
270         'not null' => TRUE,
271         'default' => 'Undefined',
272       ],
273     ],
274     'primary key' => ['name', 'age'],
275   ];
276
277   $schema['test_special_columns'] = [
278     'description' => 'A simple test table with special column names.',
279     'fields' => [
280       'id' => [
281         'description' => 'Simple unique ID.',
282         'type' => 'int',
283         'not null' => TRUE,
284       ],
285       'offset' => [
286         'description' => 'A column with preserved name.',
287         'type' => 'text',
288       ],
289     ],
290     'primary key' => ['id'],
291   ];
292
293   $schema['TEST_UPPERCASE'] = $schema['test'];
294
295   return $schema;
296 }