Adding and modifying database tables in update hooks

  • To add a database in an update hook (may you not have to do that much) it appears you must borrow from the innards of drupal_install_schema().

    See http://drupal.org/node/150215

    In linkoutreadmore.install,

    <?php
    /**
     * Implements hook_update_N().
     */
    function linkoutreadmore_update_7001() {
     
    // See http://drupal.org/node/150220
     
    $schema['linkoutreadmore'] = array(
       
    'description' => 'A list of nodes which use a link URL for the Read More destination.',
       
    'fields' => array(
         
    'nid' => array(
           
    'description' => 'The node ID.',
           
    'type' => 'int',
           
    'unsigned' => TRUE,
           
    'not null' => TRUE,
          ),
         
    'field_name' => array(
           
    'type' => 'varchar',
           
    'length' => 32,
           
    'not null' => TRUE,
           
    'description' => 'The name of the link field.',
          ),
        ),
       
    'primary key' => array('nid'),
      );
     
    db_create_table('linkoutreadmore', $schema['linkoutreadmore']);
    }

    /**
     * Implements hook_schema().
     */
    function linkoutreadmore_schema() {
     
    $schema['linkoutreadmore'] = array(
       
    'description' => 'A list of nodes which use a link URL for the Read More destination.',
       
    'fields' => array(
         
    'nid' => array(
           
    'description' => 'The node ID.',
           
    'type' => 'int',
           
    'unsigned' => TRUE,
           
    'not null' => TRUE,
          ),
         
    'field_name' => array(
           
    'type' => 'varchar',
           
    'length' => 32,
           
    'not null' => TRUE,
           
    'description' => 'The name of the link field.',
          ),
        ),
       
    'primary key' => array('nid'),
      );

      return

    $schema;
    }
    ?>