b4e3ca5632558fb4337c03d5b523791b9684b063
[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     ],
213     'primary key' => ['id'],
214     'unique keys' => [
215       'name' => ['name']
216     ],
217     'indexes' => [
218       'ages' => ['age'],
219     ],
220   ];
221
222   $schema['test_serialized'] = [
223     'description' => 'Basic test table for NULL value handling.',
224     'fields' => [
225       'id' => [
226         'type' => 'serial',
227         'unsigned' => TRUE,
228         'not null' => TRUE,
229       ],
230       'name' => [
231         'description' => "A person's name.",
232         'type' => 'varchar_ascii',
233         'length' => 255,
234         'not null' => FALSE,
235         'default' => '',
236       ],
237       'info' => [
238         'description' => "The person's data in serialized form.",
239         'type' => 'blob',
240         'serialize' => TRUE,
241       ],
242     ],
243     'primary key' => ['id'],
244     'unique keys' => [
245       'name' => ['name']
246     ],
247   ];
248
249   $schema['test_composite_primary'] = [
250     'description' => 'Basic test table with a composite primary key',
251     'fields' => [
252       'name' => [
253         'description' => "A person's name",
254         'type' => 'varchar',
255         'length' => 50,
256         'not null' => TRUE,
257         'default' => '',
258         'binary' => TRUE,
259       ],
260       'age' => [
261         'description' => "The person's age",
262         'type' => 'int',
263         'unsigned' => TRUE,
264         'not null' => TRUE,
265         'default' => 0,
266       ],
267       'job' => [
268         'description' => "The person's job",
269         'type' => 'varchar',
270         'length' => 255,
271         'not null' => TRUE,
272         'default' => 'Undefined',
273       ],
274     ],
275     'primary key' => ['name', 'age'],
276   ];
277
278   $schema['test_special_columns'] = [
279     'description' => 'A simple test table with special column names.',
280     'fields' => [
281       'id' => [
282         'description' => 'Simple unique ID.',
283         'type' => 'int',
284         'not null' => TRUE,
285       ],
286       'offset' => [
287         'description' => 'A column with preserved name.',
288         'type' => 'text',
289       ],
290     ],
291     'primary key' => ['id'],
292   ];
293
294   $schema['TEST_UPPERCASE'] = $schema['test'];
295
296   return $schema;
297 }