diff --git a/core/lib/Drupal/Core/Database/database.api.php b/core/lib/Drupal/Core/Database/database.api.php index 4cf34f8dd3..9c68d6b31f 100644 --- a/core/lib/Drupal/Core/Database/database.api.php +++ b/core/lib/Drupal/Core/Database/database.api.php @@ -249,17 +249,15 @@ * The following keys are defined: * - 'description': A string in non-markup plain text describing this table * and its purpose. References to other tables should be enclosed in - * curly-brackets. For example, the node_field_revision table - * description field might contain "Stores per-revision title and - * body data for each {node}." + * curly-brackets. For example, a description for the tracker_node table + * could be "Tracks when {nodes} were last changed or commented on." * - 'fields': An associative array ('fieldname' => specification) * that describes the table's database columns. The specification * is also an array. The following specification parameters are defined: * - 'description': A string in non-markup plain text describing this field * and its purpose. References to other tables should be enclosed in - * curly-brackets. For example, the node table vid field - * description might contain "Always holds the largest (most - * recent) {node_field_revision}.vid value for this nid." + * curly-brackets. For example, the tracker_node table nid field + * description could contain "The {node}.nid this record tracks." * - 'type': The generic datatype: 'char', 'varchar', 'text', 'blob', 'int', * 'float', 'numeric', or 'serial'. Most types just map to the according * database engine specific data types. Use 'serial' for auto incrementing @@ -326,60 +324,49 @@ * array of two elements, column name and length, specifying a prefix * of the named column. * - * As an example, here is a SUBSET of the schema definition for - * Drupal's 'node' table. It show four fields (nid, vid, type, and - * title), the primary key on field 'nid', a unique key named 'vid' on - * field 'vid', and two indexes, one named 'nid' on field 'nid' and - * one named 'node_title_type' on the field 'title' and the first four - * bytes of the field 'type': + * As an example, this is the schema definition for Drupal's tracker_node table. + * It show three fields (nid, published, and changed), the primary key on fields + * (nid), and one index (tracker, on the published and changed fields). * * @code - * $schema['node'] = array( - * 'description' => 'The base table for nodes.', - * 'fields' => array( - * 'nid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), - * 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,'default' => 0), - * 'type' => array('type' => 'varchar','length' => 32,'not null' => TRUE, 'default' => ''), - * 'language' => array('type' => 'varchar','length' => 12,'not null' => TRUE,'default' => ''), - * 'title' => array('type' => 'varchar','length' => 255,'not null' => TRUE, 'default' => ''), - * 'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), - * 'status' => array('type' => 'int', 'not null' => TRUE, 'default' => 1), - * 'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), - * 'changed' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), - * 'comment' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), - * 'promote' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), - * 'moderate' => array('type' => 'int', 'not null' => TRUE,'default' => 0), - * 'sticky' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), - * 'translate' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), - * ), - * 'indexes' => array( - * 'node_changed' => array('changed'), - * 'node_created' => array('created'), - * 'node_moderate' => array('moderate'), - * 'node_frontpage' => array('promote', 'status', 'sticky', 'created'), - * 'node_status_type' => array('status', 'type', 'nid'), - * 'node_title_type' => array('title', array('type', 4)), - * 'node_type' => array(array('type', 4)), - * 'uid' => array('uid'), - * 'translate' => array('translate'), - * ), - * 'unique keys' => array( - * 'vid' => array('vid'), - * ), + * $schema['tracker_node'] = [ + * 'description' => 'Tracks when {nodes} were last changed or commented on.', + * 'fields' => [ + * 'nid' => [ + * 'description' => 'The {node}.nid this record tracks.', + * 'type' => 'int', + * 'unsigned' => TRUE, + * 'not null' => TRUE, + * 'default' => 0, + * ], + * 'published' => [ + * 'description' => 'Boolean indicating whether the node is published.', + * 'type' => 'int', + * 'not null' => FALSE, + * 'default' => 0, + * 'size' => 'tiny', + * ], + * 'changed' => [ + * 'description' => 'The Unix timestamp when the node was most recently saved or commented on.', + * 'type' => 'int', + * 'unsigned' => TRUE, + * 'not null' => TRUE, + * 'default' => 0, + * ], + * ], + * 'indexes' => [ + * 'tracker' => ['published', 'changed'], + * ], + * 'primary key' => ['nid'], * // For documentation purposes only; foreign keys are not created in the * // database. - * 'foreign keys' => array( - * 'node_revision' => array( - * 'table' => 'node_field_revision', - * 'columns' => array('vid' => 'vid'), - * ), - * 'node_author' => array( - * 'table' => 'users', - * 'columns' => array('uid' => 'uid'), - * ), - * ), - * 'primary key' => array('nid'), - * ); + * 'foreign keys' => [ + * 'tracked_node' => [ + * 'table' => 'node', + * 'columns' => ['nid' => 'nid'], + * ], + * ], + * ]; * @endcode * * @see drupal_install_schema() @@ -490,59 +477,43 @@ function hook_query_TAG_alter(Drupal\Core\Database\Query\AlterableInterface $que * @ingroup schemaapi */ function hook_schema() { - $schema['node'] = [ - // Example (partial) specification for table "node". - 'description' => 'The base table for nodes.', + $schema['tracker_node'] = [ + 'description' => 'Tracks when {nodes} were last changed or commented on.', 'fields' => [ 'nid' => [ - 'description' => 'The primary identifier for a node.', - 'type' => 'serial', - 'unsigned' => TRUE, - 'not null' => TRUE, - ], - 'vid' => [ - 'description' => 'The current {node_field_revision}.vid version identifier.', + 'description' => 'The {node}.nid this record tracks.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ], - 'type' => [ - 'description' => 'The type of this node.', - 'type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - 'default' => '', + 'published' => [ + 'description' => 'Boolean indicating whether the node is published.', + 'type' => 'int', + 'not null' => FALSE, + 'default' => 0, + 'size' => 'tiny', ], - 'title' => [ - 'description' => 'The node title.', - 'type' => 'varchar', - 'length' => 255, + 'changed' => [ + 'description' => 'The Unix timestamp when the node was most recently saved or commented on.', + 'type' => 'int', + 'unsigned' => TRUE, 'not null' => TRUE, - 'default' => '', + 'default' => 0, ], ], 'indexes' => [ - 'node_changed' => ['changed'], - 'node_created' => ['created'], - ], - 'unique keys' => [ - 'nid_vid' => ['nid', 'vid'], - 'vid' => ['vid'], + 'tracker' => ['published', 'changed'], ], + 'primary key' => ['nid'], // For documentation purposes only; foreign keys are not created in the // database. 'foreign keys' => [ - 'node_revision' => [ - 'table' => 'node_field_revision', - 'columns' => ['vid' => 'vid'], - ], - 'node_author' => [ - 'table' => 'users', - 'columns' => ['uid' => 'uid'], + 'tracked_node' => [ + 'table' => 'node', + 'columns' => ['nid' => 'nid'], ], ], - 'primary key' => ['nid'], ]; return $schema; }