|
248 | 248 | * |
249 | 249 | * The following keys are defined: |
250 | 250 | * - 'description': A string in non-markup plain text describing this table |
251 | | - * and its purpose. References to other tables should be enclosed in |
252 | | - * curly-brackets. For example, the node_field_revision table |
253 | | - * description field might contain "Stores per-revision title and |
254 | | - * body data for each {node}." |
| 251 | + * and its purpose. References to other tables should be enclosed in curly |
| 252 | + * brackets. |
255 | 253 | * - 'fields': An associative array ('fieldname' => specification) |
256 | 254 | * that describes the table's database columns. The specification |
257 | 255 | * is also an array. The following specification parameters are defined: |
258 | 256 | * - 'description': A string in non-markup plain text describing this field |
259 | | - * and its purpose. References to other tables should be enclosed in |
260 | | - * curly-brackets. For example, the node table vid field |
261 | | - * description might contain "Always holds the largest (most |
262 | | - * recent) {node_field_revision}.vid value for this nid." |
| 257 | + * and its purpose. References to other tables should be enclosed in curly |
| 258 | + * brackets. For example, the users_data table 'uid' field description |
| 259 | + * might contain "The {users}.uid this record affects." |
263 | 260 | * - 'type': The generic datatype: 'char', 'varchar', 'text', 'blob', 'int', |
264 | 261 | * 'float', 'numeric', or 'serial'. Most types just map to the according |
265 | 262 | * database engine specific data types. Use 'serial' for auto incrementing |
|
322 | 319 | * key column specifiers (see below) that form an index on the |
323 | 320 | * table. |
324 | 321 | * |
325 | | - * A key column specifier is either a string naming a column or an |
326 | | - * array of two elements, column name and length, specifying a prefix |
327 | | - * of the named column. |
| 322 | + * A key column specifier is either a string naming a column or an array of two |
| 323 | + * elements, column name and length, specifying a prefix of the named column. |
328 | 324 | * |
329 | | - * As an example, here is a SUBSET of the schema definition for |
330 | | - * Drupal's 'node' table. It show four fields (nid, vid, type, and |
331 | | - * title), the primary key on field 'nid', a unique key named 'vid' on |
332 | | - * field 'vid', and two indexes, one named 'nid' on field 'nid' and |
333 | | - * one named 'node_title_type' on the field 'title' and the first four |
334 | | - * bytes of the field 'type': |
| 325 | + * As an example, this is the schema definition for the 'users_data' table. It |
| 326 | + * shows five fields ('uid', 'module', 'name', 'value', and 'serialized'), the |
| 327 | + * primary key (on the 'uid', 'module', and 'name' fields), and two indexes (the |
| 328 | + * 'module' index on the 'module' field and the 'name' index on the 'name' |
| 329 | + * field). |
335 | 330 | * |
336 | 331 | * @code |
337 | | - * $schema['node'] = array( |
338 | | - * 'description' => 'The base table for nodes.', |
339 | | - * 'fields' => array( |
340 | | - * 'nid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), |
341 | | - * 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,'default' => 0), |
342 | | - * 'type' => array('type' => 'varchar','length' => 32,'not null' => TRUE, 'default' => ''), |
343 | | - * 'language' => array('type' => 'varchar','length' => 12,'not null' => TRUE,'default' => ''), |
344 | | - * 'title' => array('type' => 'varchar','length' => 255,'not null' => TRUE, 'default' => ''), |
345 | | - * 'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), |
346 | | - * 'status' => array('type' => 'int', 'not null' => TRUE, 'default' => 1), |
347 | | - * 'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), |
348 | | - * 'changed' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), |
349 | | - * 'comment' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), |
350 | | - * 'promote' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), |
351 | | - * 'moderate' => array('type' => 'int', 'not null' => TRUE,'default' => 0), |
352 | | - * 'sticky' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), |
353 | | - * 'translate' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), |
354 | | - * ), |
355 | | - * 'indexes' => array( |
356 | | - * 'node_changed' => array('changed'), |
357 | | - * 'node_created' => array('created'), |
358 | | - * 'node_moderate' => array('moderate'), |
359 | | - * 'node_frontpage' => array('promote', 'status', 'sticky', 'created'), |
360 | | - * 'node_status_type' => array('status', 'type', 'nid'), |
361 | | - * 'node_title_type' => array('title', array('type', 4)), |
362 | | - * 'node_type' => array(array('type', 4)), |
363 | | - * 'uid' => array('uid'), |
364 | | - * 'translate' => array('translate'), |
365 | | - * ), |
366 | | - * 'unique keys' => array( |
367 | | - * 'vid' => array('vid'), |
368 | | - * ), |
| 332 | + * $schema['users_data'] = [ |
| 333 | + * 'description' => 'Stores module data as key/value pairs per user.', |
| 334 | + * 'fields' => [ |
| 335 | + * 'uid' => [ |
| 336 | + * 'description' => 'The {users}.uid this record affects.', |
| 337 | + * 'type' => 'int', |
| 338 | + * 'unsigned' => TRUE, |
| 339 | + * 'not null' => TRUE, |
| 340 | + * 'default' => 0, |
| 341 | + * ], |
| 342 | + * 'module' => [ |
| 343 | + * 'description' => 'The name of the module declaring the variable.', |
| 344 | + * 'type' => 'varchar_ascii', |
| 345 | + * 'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH, |
| 346 | + * 'not null' => TRUE, |
| 347 | + * 'default' => '', |
| 348 | + * ], |
| 349 | + * 'name' => [ |
| 350 | + * 'description' => 'The identifier of the data.', |
| 351 | + * 'type' => 'varchar_ascii', |
| 352 | + * 'length' => 128, |
| 353 | + * 'not null' => TRUE, |
| 354 | + * 'default' => '', |
| 355 | + * ], |
| 356 | + * 'value' => [ |
| 357 | + * 'description' => 'The value.', |
| 358 | + * 'type' => 'blob', |
| 359 | + * 'not null' => FALSE, |
| 360 | + * 'size' => 'big', |
| 361 | + * ], |
| 362 | + * 'serialized' => [ |
| 363 | + * 'description' => 'Whether value is serialized.', |
| 364 | + * 'type' => 'int', |
| 365 | + * 'size' => 'tiny', |
| 366 | + * 'unsigned' => TRUE, |
| 367 | + * 'default' => 0, |
| 368 | + * ], |
| 369 | + * ], |
| 370 | + * 'primary key' => ['uid', 'module', 'name'], |
| 371 | + * 'indexes' => [ |
| 372 | + * 'module' => ['module'], |
| 373 | + * 'name' => ['name'], |
| 374 | + * ], |
369 | 375 | * // For documentation purposes only; foreign keys are not created in the |
370 | 376 | * // database. |
371 | | - * 'foreign keys' => array( |
372 | | - * 'node_revision' => array( |
373 | | - * 'table' => 'node_field_revision', |
374 | | - * 'columns' => array('vid' => 'vid'), |
375 | | - * ), |
376 | | - * 'node_author' => array( |
| 377 | + * 'foreign keys' => [ |
| 378 | + * 'data_user' => [ |
377 | 379 | * 'table' => 'users', |
378 | | - * 'columns' => array('uid' => 'uid'), |
379 | | - * ), |
380 | | - * ), |
381 | | - * 'primary key' => array('nid'), |
382 | | - * ); |
| 380 | + * 'columns' => [ |
| 381 | + * 'uid' => 'uid', |
| 382 | + * ], |
| 383 | + * ], |
| 384 | + * ], |
| 385 | + * ]; |
383 | 386 | * @endcode |
384 | 387 | * |
385 | 388 | * @see drupal_install_schema() |
@@ -490,60 +493,61 @@ function hook_query_TAG_alter(Drupal\Core\Database\Query\AlterableInterface $que |
490 | 493 | * @ingroup schemaapi |
491 | 494 | */ |
492 | 495 | function hook_schema() { |
493 | | - $schema['node'] = [ |
494 | | - // Example (partial) specification for table "node". |
495 | | - 'description' => 'The base table for nodes.', |
| 496 | + $schema['users_data'] = [ |
| 497 | + 'description' => 'Stores module data as key/value pairs per user.', |
496 | 498 | 'fields' => [ |
497 | | - 'nid' => [ |
498 | | - 'description' => 'The primary identifier for a node.', |
499 | | - 'type' => 'serial', |
500 | | - 'unsigned' => TRUE, |
501 | | - 'not null' => TRUE, |
502 | | - ], |
503 | | - 'vid' => [ |
504 | | - 'description' => 'The current {node_field_revision}.vid version identifier.', |
| 499 | + 'uid' => [ |
| 500 | + 'description' => 'The {users}.uid this record affects.', |
505 | 501 | 'type' => 'int', |
506 | 502 | 'unsigned' => TRUE, |
507 | 503 | 'not null' => TRUE, |
508 | 504 | 'default' => 0, |
509 | 505 | ], |
510 | | - 'type' => [ |
511 | | - 'description' => 'The type of this node.', |
512 | | - 'type' => 'varchar', |
513 | | - 'length' => 32, |
| 506 | + 'module' => [ |
| 507 | + 'description' => 'The name of the module declaring the variable.', |
| 508 | + 'type' => 'varchar_ascii', |
| 509 | + 'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH, |
514 | 510 | 'not null' => TRUE, |
515 | 511 | 'default' => '', |
516 | 512 | ], |
517 | | - 'title' => [ |
518 | | - 'description' => 'The node title.', |
519 | | - 'type' => 'varchar', |
520 | | - 'length' => 255, |
| 513 | + 'name' => [ |
| 514 | + 'description' => 'The identifier of the data.', |
| 515 | + 'type' => 'varchar_ascii', |
| 516 | + 'length' => 128, |
521 | 517 | 'not null' => TRUE, |
522 | 518 | 'default' => '', |
523 | 519 | ], |
| 520 | + 'value' => [ |
| 521 | + 'description' => 'The value.', |
| 522 | + 'type' => 'blob', |
| 523 | + 'not null' => FALSE, |
| 524 | + 'size' => 'big', |
| 525 | + ], |
| 526 | + 'serialized' => [ |
| 527 | + 'description' => 'Whether value is serialized.', |
| 528 | + 'type' => 'int', |
| 529 | + 'size' => 'tiny', |
| 530 | + 'unsigned' => TRUE, |
| 531 | + 'default' => 0, |
| 532 | + ], |
524 | 533 | ], |
| 534 | + 'primary key' => ['uid', 'module', 'name'], |
525 | 535 | 'indexes' => [ |
526 | | - 'node_changed' => ['changed'], |
527 | | - 'node_created' => ['created'], |
528 | | - ], |
529 | | - 'unique keys' => [ |
530 | | - 'nid_vid' => ['nid', 'vid'], |
531 | | - 'vid' => ['vid'], |
| 536 | + 'module' => ['module'], |
| 537 | + 'name' => ['name'], |
532 | 538 | ], |
533 | 539 | // For documentation purposes only; foreign keys are not created in the |
534 | 540 | // database. |
535 | 541 | 'foreign keys' => [ |
536 | | - 'node_revision' => [ |
537 | | - 'table' => 'node_field_revision', |
538 | | - 'columns' => ['vid' => 'vid'], |
539 | | - ], |
540 | | - 'node_author' => [ |
| 542 | + 'data_user' => [ |
541 | 543 | 'table' => 'users', |
542 | | - 'columns' => ['uid' => 'uid'], |
| 544 | + 'columns' => [ |
| 545 | + 'uid' => 'uid', |
| 546 | + ], |
543 | 547 | ], |
544 | 548 | ], |
545 | | - 'primary key' => ['nid'], |
546 | 549 | ]; |
| 550 | + |
547 | 551 | return $schema; |
548 | 552 | } |
549 | 553 |
|
|
0 commit comments