"changed by" on nodes mysql&gt; select nid, uid, created, changed from node;
+-----+-----+------------+------------+
| nid | uid | created    | changed    |
+-----+-----+------------+------------+
|   1 |   8 | 1336040166 | 1336046390 |
+-----+-----+------------+------------+


I'd like to have an "changed by" column on the node table, exactly as we have a "created by" (the uid field). This would keep track of who made the last change on that node. I know that this could be derived from the node_revision table but this depends on the revisions being enabled for the content types I'm interested.

So, what is the best way to do this? And why doesn't Drupal core offer this by default? I thought that "changed by" is a pretty standard piece of information that a CMS should attach to content.
I thought this would be quite tough to do, but as it turns out it's fairly easy.

You just need to create a custom module that adds a column to the node table on install, implement hook_schema_alter() so Drupal knows about the new column, and add some logic to provide a value before the node is saved.

Here's a small module that will do the trick:

File: node_table_alter.info

name = Node Table Alter
core = 7.x


File: node_table_alter.install

function node_table_alter_install() {
  // Add the new field to the node table
  $field = array(
    'description' =&gt; 'Stores the user id of the last user to alter the node',
    'type' =&gt; 'int',
    'unsigned' =&gt; TRUE
  );

  db_add_field('node', 'changed_by', $field);
}


File: node_table_alter.module

function node_table_alter_schema_alter(&amp;$schema) {
  // Add the new field to the schema cache
  $schema['node']['fields']['changed_by'] = array(
    'description' =&gt; 'Stores the user id of the last user to alter the node',
    'type' =&gt; 'int',
    'unsigned' =&gt; TRUE
  );
}

function node_table_alter_node_presave($node) {
  // Populate the changed_by column with current user's id
  $node-&gt;changed_by = $GLOBALS['user']-&gt;uid;
}


You may want to add logic to remove the field again on uninstall, and add an index to the table for the changed_by column (see db_add_index()), but this should give you a good place to start.

The beauty of this method is that you have effectively added a new property to the node. You'll be able to use node_load(), EntityFieldQuerys, etc. with it as if it were any of the other standard properties for a node.

God bless Drupal for being so extendable!