summaryrefslogtreecommitdiff
path: root/modules/taxonomy/taxonomy.install
blob: 9fc2ad23cc531d776669152bd42e9183e1f66bac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
// $Id$

 /**
 * Implementation of hook_install().
 */
function taxonomy_install() {
  // Create tables.
  drupal_install_schema('taxonomy');
}

/**
 * Implementation of hook_uninstall().
 */
function taxonomy_uninstall() {
  // Remove tables.
  drupal_uninstall_schema('taxonomy');
}

/**
 * Implementation of hook_schema().
 */
function taxonomy_schema() {
  $schema['taxonomy_term_data'] = array(
    'description' => 'Stores term information.',
    'fields' => array(
      'tid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Unique term ID.',
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {taxonomy_vocabulary}.vid of the vocabulary to which the term is assigned.',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The term name.',
      ),
      'description' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
        'description' => 'A description of the term.',
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'The weight of this term in relation to other terms.',
      ),
    ),
    'primary key' => array('tid'),
    'indexes' => array(
      'taxonomy_tree' => array('vid', 'weight', 'name'),
      'vid_name' => array('vid', 'name'),
    ),
  );

  $schema['taxonomy_term_hierarchy'] = array(
    'description' => 'Stores the hierarchical relationship between terms.',
    'fields' => array(
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Primary Key: The {taxonomy_term_data}.tid of the term.',
      ),
      'parent' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => "Primary Key: The {taxonomy_term_data}.tid of the term's parent. 0 indicates no parent.",
      ),
    ),
    'indexes' => array(
      'parent' => array('parent'),
    ),
    'primary key' => array('tid', 'parent'),
  );

  $schema['taxonomy_term_node'] = array(
    'description' => 'Stores the relationship of terms to nodes.',
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Primary Key: The {node}.nid of the node.',
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Primary Key: The {node}.vid of the node.',
      ),
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Primary Key: The {taxonomy_term_data}.tid of a term assigned to the node.',
      ),
    ),
    'indexes' => array(
      'vid' => array('vid'),
      'nid' => array('nid'),
    ),
    'primary key' => array('tid', 'vid'),
  );

  $schema['taxonomy_term_relation'] = array(
    'description' => 'Stores non-hierarchical relationships between terms.',
    'fields' => array(
      'trid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique term relation ID.',
      ),
      'tid1' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {taxonomy_term_data}.tid of the first term in a relationship.',
      ),
      'tid2' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {taxonomy_term_data}.tid of the second term in a relationship.',
      ),
    ),
    'unique keys' => array(
      'tid1_tid2' => array('tid1', 'tid2'),
    ),
    'indexes' => array(
      'tid2' => array('tid2'),
    ),
    'primary key' => array('trid'),
  );

  $schema['taxonomy_term_synonym'] = array(
    'description' => 'Stores term synonyms.',
    'fields' => array(
      'tsid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique term synonym ID.',
      ),
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {taxonomy_term_data}.tid of the term.',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The name of the synonym.',
      ),
    ),
    'indexes' => array(
      'tid' => array('tid'),
      'name_tid' => array('name', 'tid'),
    ),
    'primary key' => array('tsid'),
  );

  $schema['taxonomy_vocabulary'] = array(
    'description' => 'Stores vocabulary information.',
    'fields' => array(
      'vid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Unique vocabulary ID.',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Name of the vocabulary.',
      ),
      'description' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
        'description' => 'Description of the vocabulary.',
      ),
      'help' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Help text to display for the vocabulary.',
      ),
      'relations' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'Whether or not related terms are enabled within the vocabulary. (0 = disabled, 1 = enabled)',
      ),
      'hierarchy' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'The type of hierarchy allowed within the vocabulary. (0 = disabled, 1 = single, 2 = multiple)',
      ),
      'multiple' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'Whether or not multiple terms from this vocabulary may be assigned to a node. (0 = disabled, 1 = enabled)',
      ),
      'required' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'Whether or not terms are required for nodes using this vocabulary. (0 = disabled, 1 = enabled)',
      ),
      'tags' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'Whether or not free tagging is enabled for the vocabulary. (0 = disabled, 1 = enabled)',
      ),
      'module' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The module which created the vocabulary.',
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'The weight of the vocabulary in relation to other vocabularies.',
      ),
    ),
    'primary key' => array('vid'),
    'indexes' => array(
      'list' => array('weight', 'name'),
    ),
  );

  $schema['taxonomy_vocabulary_node_type'] = array(
    'description' => 'Stores which node types vocabularies may be used with.',
    'fields' => array(
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Primary Key: the {taxonomy_vocabulary}.vid of the vocabulary.',
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The {node}.type of the node type for which the vocabulary may be used.',
      ),
    ),
    'primary key' => array('type', 'vid'),
    'indexes' => array(
      'vid' => array('vid'),
    ),
  );

  return $schema;
}

/**
 * Rename taxonomy tables.
 */
function taxonomy_update_7001() {
  $ret = array();
  db_rename_table($ret, 'term_data', 'taxonomy_term_data');
  db_rename_table($ret, 'term_hierarchy', 'taxonomy_term_hierarchy');
  db_rename_table($ret, 'term_node', 'taxonomy_term_node');
  db_rename_table($ret, 'term_relation', 'taxonomy_term_relation');
  db_rename_table($ret, 'term_synonym', 'taxonomy_term_synonym');
  db_rename_table($ret, 'vocabulary', 'taxonomy_vocabulary');
  db_rename_table($ret, 'vocabulary_node_types', 'taxonomy_vocabulary_node_type');
  
  return $ret;
}