Skip to content
Snippets Groups Projects
og.install 26.3 KiB
Newer Older
Amitaibu's avatar
Amitaibu committed
<?php
Amitaibu's avatar
Amitaibu committed
/**
 * @file
 * Install, update, and uninstall functions for the Organic groups module.
Amitaibu's avatar
Amitaibu committed
 */

 * Implements hook_install().
function og_install() {
  // Add "User request" to the default group membership type.
  $field_name = OG_MEMBERSHIP_REQUEST_FIELD;
  if (!field_info_field($field_name)) {
    $field = array(
      'field_name' => $field_name,
      'type' => 'text_long',
      'entity_types' => array('og_membership'),
      'cardinality' => 1,
      // Although we would prefer to not allow deleting this field, we can not
      // lock it, as it will not allow adding it to other bundles.
      'locked' => FALSE,
    );
    $field = field_create_field($field);
  }

  if (!field_info_instance('og_membership', $field_name, OG_MEMBERSHIP_TYPE_DEFAULT)) {
    $instance = array(
      'field_name' => $field_name,
      'bundle' => OG_MEMBERSHIP_TYPE_DEFAULT,
      'entity_type' => 'og_membership',
      'label' => t('Request message'),
      'description' => t('This is the text a user may send to the group administrators.'),
      'required' => FALSE,
    );
    field_create_instance($instance);
  }
Amitaibu's avatar
Amitaibu committed
/**
Amitaibu's avatar
Amitaibu committed
 * Implements hook_uninstall().
Amitaibu's avatar
Amitaibu committed
 */
function og_uninstall() {
  db_delete('variable')
    ->condition('name', 'og_group_manager_default_rids_%', 'LIKE')
    ->execute();

Amitaibu's avatar
Amitaibu committed
  $vars = array(
Amitaibu's avatar
Amitaibu committed
    'og_context',
    'og_group_manager_full_access',
    'og_skip_access',
Amitaibu's avatar
Amitaibu committed
  );
  foreach ($vars as $var) {
    variable_del($var);
  }
  // Remove all fields owned by organic groups.
  foreach (field_read_fields(array('module' => 'og'), array('include_inactive' => TRUE)) as $field){
    // We need to invoke the storage_delete hook and the field_delete_instance
    // here, even though this should be done by field_delete_field().
    // The current version of this function only works on active fields,
    // and during uninstall, the fields will be inactive.
    // Can be removed once
    // http://drupal.org/node/943772
    // is fixed.
    module_invoke($field['storage']['module'], 'field_storage_delete_field', $field);
    $instances = field_read_instances(array('field_id' => $field['id']), array('include_inactive' => TRUE));
    foreach ($instances as $instance) {
      field_delete_instance($instance, FALSE);
    }
    field_delete_field($field['field_name']);
  }
Amitaibu's avatar
Amitaibu committed
}

Amitaibu's avatar
Amitaibu committed
/**
Amitaibu's avatar
Amitaibu committed
 * Implements hook_schema().
Amitaibu's avatar
Amitaibu committed
 */
function og_schema() {
  return og_schema_info();
}

function og_schema_info() {
Amitaibu's avatar
Amitaibu committed
  $schema = array();

Amitaibu's avatar
Amitaibu committed
  $schema['og_role_permission'] = array(
Amitaibu's avatar
Amitaibu committed
    'description' => 'Stores the permissions assigned to user roles per group.',
    'fields' => array(
      'rid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Foreign Key: {role}.rid.',
      ),
      'permission' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => 'A single permission granted to the role identified by rid.',
      ),
      'module' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => "The module declaring the permission.",
      ),
Amitaibu's avatar
Amitaibu committed
    ),
    'primary key' => array('rid', 'permission'),
    'indexes' => array(
      'permission' => array('permission'),
    ),
    'foreign keys' => array(
Amitaibu's avatar
Amitaibu committed
      'og_role' => array(
        'table' => 'og_role',
        'columns' => array('rid' => 'rid'),
      ),
Amitaibu's avatar
Amitaibu committed
  $schema['og_role'] = array(
Amitaibu's avatar
Amitaibu committed
    'description' => 'Stores user roles per group.',
    'fields' => array(
      'rid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Unique role ID.',
      ),
      'gid'               => array(
        'description'     => "The group's unique ID.",
        'type'            => 'int',
        'size'            => 'normal',
        'not null'        => TRUE,
      ),
      'group_type' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => "The group's entity type.",
      ),
      'group_bundle' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => "The group's bundle name.",
      ),
Amitaibu's avatar
Amitaibu committed
      'name' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Unique role name per group.',
      ),
    ),
    'primary key' => array('rid'),
  );

Amitaibu's avatar
Amitaibu committed
  $schema['og_users_roles'] = array(
Amitaibu's avatar
Amitaibu committed
    'description' => 'Maps users to roles.',
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Primary Key: {users}.uid for user.',
      ),
      'rid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
Amitaibu's avatar
Amitaibu committed
        'description' => 'Primary Key: {og_role}.rid for role.',
Amitaibu's avatar
Amitaibu committed
      ),
      'gid'               => array(
        'description'     => "The group's unique ID.",
        'type'            => 'int',
        'size'            => 'normal',
        'not null'        => TRUE,
      ),
      'group_type' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => "The group's entity type.",
      ),
Amitaibu's avatar
Amitaibu committed
    ),
    'primary key' => array('uid', 'rid', 'gid'),
Amitaibu's avatar
Amitaibu committed
    'indexes' => array(
      'rid' => array('rid'),
    ),
    'foreign keys' => array(
Amitaibu's avatar
Amitaibu committed
      'user' => array(
        'table' => 'users',
        'columns' => array('uid' => 'uid'),
      ),
      'og_role' => array(
        'table' => 'og_role',
        'columns' => array('rid' => 'rid'),
      ),
  $schema['og_membership_type'] = array(
    'description' => 'The group membership type.',
    'fields' => array(
      // Although the "name" should be enough as the primary key, the numeric ID
      // is required for the internal use of entity API.
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Numeric group membership type ID.',
      ),
      'name' => array(
        'description' => 'The unified identifier for a group membership type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => 'Description for this group membership type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        // This is equivilent to ENTITY_CUSTOM.
        'default' =>  0x01,
        'size' => 'tiny',
        'description' => 'The exportable status of the entity.',
      ),
      'module' => array(
        'description' => 'The name of the providing module if the entity has been defined in code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array('id'),
    'unique keys' => array(
      'name' => array('name'),
    ),
  );

  $schema['og_membership'] = array(
    'description' => 'The group membership table.',
    'fields' => array(
      'id' => array(
Amitaibu's avatar
Amitaibu committed
        'description' => "The group membership's unique ID.",
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
        'description' => 'Reference to a group membership type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'etid' => array(
        'description' => "The entity ID.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'entity_type' => array(
        'description' => "The entity type (e.g. node, comment, etc').",
        'type' => 'varchar',
        'length' => '32',
        'not null' => TRUE,
        'default' => '',
      ),
      'gid'               => array(
        'description'     => "The group's unique ID.",
        'type'            => 'int',
        'size'            => 'normal',
        'not null'        => TRUE,
      ),
      'group_type' => array(
        'description' => "The group's entity type (e.g. node, comment, etc').",
        'type' => 'varchar',
        'length' => '32',
        'not null' => TRUE,
        'default' => '',
      ),
      'state' => array(
        'description' => 'The state of the group content.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default' => '',
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the group content was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'field_name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => "The name of the field holding the group ID, the OG memebership is associated with.",
      ),
Amitaibu's avatar
Amitaibu committed
    'primary key' => array('id'),
    'indexes' => array(
      // Entity index; When searching for an entity, we use both the id and type.
      'entity' => array('etid', 'entity_type'),
      'group' => array('gid', 'group_type'),
    'foreign keys' => array(
      'og_membership_type' => array(
        'table' => 'og_membership_type',
        'columns' => array('name' => 'name'),
      ),
      'group' => array(
        'table' => 'og',
        'columns' => array('gid' => 'gid'),
      ),
    ),
  );

Amitaibu's avatar
Amitaibu committed
  return $schema;
/**
 * Return the schema for upgrade 7000.
 */
function og_schema_7000_info() {
  $schema = array();

  $schema['og'] = array(
    'description'     => 'Store information related to the groups.',
    'fields'          => array(
      'gid' => array(
        'description' => "The group's unique ID.",
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'etid' => array(
        'description' => "The entity ID.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'entity_type' => array(
        'description' => "The entity type (e.g. node, comment, etc').",
        'type' => 'varchar',
        'length' => '32',
        'not null' => TRUE,
        'default' => '',
      ),
      'label' => array(
        'description' => "The entity label (e.g. node's title).",
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
      ),
      'state' => array(
        'description' => 'The state of the group (i.e. active or disabled).',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the group was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('gid'),
  );

  $schema['og_role_permission'] = array(
    'description' => 'Stores the permissions assigned to user roles per group.',
    'fields' => array(
      'rid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Foreign Key: {role}.rid.',
      ),
      'permission' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => 'A single permission granted to the role identified by rid.',
      ),
      'module' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => "The module declaring the permission.",
      ),
    ),
    'primary key' => array('rid', 'permission'),
    'indexes' => array(
      'permission' => array('permission'),
    ),
    'foreign keys' => array(
      'og_role' => array(
        'table' => 'og_role',
        'columns' => array('rid' => 'rid'),
      ),
    ),
  );

  $schema['og_role'] = array(
    'description' => 'Stores user roles per group.',
    'fields' => array(
      'rid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Unique role ID.',
      ),
      'gid'               => array(
        'description'     => "The group's unique ID.",
        'type'            => 'int',
        'size'            => 'normal',
        'not null'        => TRUE,
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Unique role name per group.',
      ),
    ),
    'primary key' => array('rid'),
  );

  $schema['og_users_roles'] = array(
    'description' => 'Maps users to roles.',
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Primary Key: {users}.uid for user.',
      ),
      'rid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Primary Key: {og_role}.rid for role.',
      ),
      'gid'               => array(
        'description'     => "The group's unique ID.",
        'type'            => 'int',
        'size'            => 'normal',
        'not null'        => TRUE,
      ),
    ),
    'primary key' => array('uid', 'rid', 'gid'),
    'indexes' => array(
      'rid' => array('rid'),
    ),
    'foreign keys' => array(
      'user' => array(
        'table' => 'users',
        'columns' => array('uid' => 'uid'),
      ),
      'og_role' => array(
        'table' => 'og_role',
        'columns' => array('rid' => 'rid'),
      ),
    ),
  );

  $schema['og_membership_type'] = array(
    'description' => 'The group membership type.',
    'fields' => array(
      // Although the "name" should be enough as the primary key, the numeric ID
      // is required for the internal use of entity API.
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Numeric group membership type ID.',
      ),
      'name' => array(
        'description' => 'The unified identifier for a group membership type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => 'Description for this group membership type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        // This is equivilent to ENTITY_CUSTOM.
        'default' =>  0x01,
        'size' => 'tiny',
        'description' => 'The exportable status of the entity.',
      ),
      'module' => array(
        'description' => 'The name of the providing module if the entity has been defined in code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array('id'),
    'unique keys' => array(
      'name' => array('name'),
    ),
  );

  $schema['og_membership'] = array(
    'description' => 'The group membership table.',
    'fields' => array(
      'id' => array(
        'description' => "The group membership's unique ID.",
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'Reference to a group membership type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'etid' => array(
        'description' => "The entity ID.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'entity_type' => array(
        'description' => "The entity type (e.g. node, comment, etc').",
        'type' => 'varchar',
        'length' => '32',
        'not null' => TRUE,
        'default' => '',
      ),
      'gid'               => array(
        'description'     => "The group's unique ID.",
        'type'            => 'int',
        'size'            => 'normal',
        'not null'        => TRUE,
      ),
      'state' => array(
        'description' => 'The state of the group content.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default' => '',
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the group content was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('id'),
    'foreign keys' => array(
      'og_membership_type' => array(
        'table' => 'og_membership_type',
        'columns' => array('name' => 'name'),
      ),
      'group' => array(
        'table' => 'og',
        'columns' => array('gid' => 'gid'),
      ),
    ),
  );

  return $schema;
}

/**
 * Return the schema for upgrade 7001.
 */
function og_schema_7001_info() {
  $schema = array();
  $schema['og_membership_type'] = array(
    'description' => 'The group membership type.',
    'fields' => array(
      // Although the "name" should be enough as the primary key, the numeric ID
      // is required for the internal use of entity API.
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Numeric group membership type ID.',
      ),
      'name' => array(
        'description' => 'The unified identifier for a group membership type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => 'Description for this group membership type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        // This is equivilent to ENTITY_CUSTOM.
        'default' =>  0x01,
        'size' => 'tiny',
        'description' => 'The exportable status of the entity.',
      ),
      'module' => array(
        'description' => 'The name of the providing module if the entity has been defined in code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array('id'),
    'unique keys' => array(
      'name' => array('name'),
    ),
  );

  $schema['og_membership'] = array(
    'description' => 'The group membership table.',
    'fields' => array(
      'id' => array(
        'description' => "The group membership's unique ID.",
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'type' => array(
        'description' => 'Reference to a group membership type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'etid' => array(
        'description' => "The entity ID.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'entity_type' => array(
        'description' => "The entity type (e.g. node, comment, etc').",
        'type' => 'varchar',
        'length' => '32',
        'not null' => TRUE,
        'default' => '',
      ),
      'gid'               => array(
        'description'     => "The group's unique ID.",
        'type'            => 'int',
        'size'            => 'normal',
        'not null'        => TRUE,
      ),
      'state' => array(
        'description' => 'The state of the group content.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default' => '',
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the group content was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('id'),
    'indexes' => array(
      // Entity index; When searching for an entity, we use both the id and type.
      'entity' => array('etid', 'entity_type'),
      'gid' => array('gid'),
    ),
    'foreign keys' => array(
      'og_membership_type' => array(
        'table' => 'og_membership_type',
        'columns' => array('name' => 'name'),
      ),
      'group' => array(
        'table' => 'og',
        'columns' => array('gid' => 'gid'),
      ),
    ),
  );

  return $schema;
}

/**
 * Implements hook_field_schema().
 */
function og_field_schema($field) {
  $columns = array(
    'gid' => array(
      'description' => 'The group unique ID.',
      'type' => 'float',
      'unsigned' => TRUE,
      'not null' => FALSE,
    ),
    // This columns should be deprecated and removed, as the group membership
    // entity takes care of it. However, there is currently no way to remove
    // them.
    'state' => array(
      'description' => 'The state of the group content.',
      'type' => 'varchar',
      'length' => 255,
      'not null' => FALSE,
      'default' => '',
    ),
    'created' => array(
      'description' => 'The Unix timestamp when the group content was created.',
      'type' => 'int',
      'not null' => TRUE,
      'default' => 0,
    ),
  );
  return array(
    'columns' => $columns,
    'indexes' => array(
      'gid' => array('gid'),
    ),
    'foreign keys' => array(
      'og' => array(
        'table' => 'og',
        'columns' => array('gid' => 'gid'),
      ),
    ),
  );
}

Amitaibu's avatar
Amitaibu committed
/**
 * Upgrade from Organic groups 6 to 7.
 */
function og_update_7000(&$sandbox) {
  if (db_field_exists('og', 'nid') && !db_table_exists('d6_og')) {
    // Rename the old table, so we can populate the new {og} table using API
    // functions, that assume the new DB structure.
    db_rename_table('og', 'd6_og');
    db_rename_table('og_ancestry', 'd6_og_ancestry');
    db_rename_table('og_uid', 'd6_og_uid');

    // Add serial ID to d6_og* tables so we can keep track of records that were
    // processed.
    foreach (array('d6_og', 'd6_og_ancestry', 'd6_og_uid') as $table) {
      // Drop the current primary key, as we are adding a serial column.
      db_drop_primary_key($table);
      db_add_field($table, 'upgrade_id', array(
        'description' => 'This a serial ID that keeps track of records that were processed.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      array('primary key' => array('upgrade_id')));
    }

    foreach (array('og', 'og_role_permission', 'og_role', 'og_users_roles') as $table) {
      db_create_table($table, $schema[$table]);
    // We can't call og_needs_migrate() directly, so just set the variable.
    variable_set('og_needs_migrate', TRUE);
    return t('Renamed Organic groups 6 tables. Enable Organic groups migrate module to continue the migration of data.');
  return t('No change needed in Organic groups schema.');
 * Add group membership entities instead of field data.
 */
function og_update_7001(&$sandbox) {
  // Due to changes in the upgrade path (e.g. moving data migration to
  // og-migrate) some users already have the tables, so be careful about
  // the creation of these tables.
  $schema = og_schema_7001_info();
  if (!db_table_exists('og_membership')) {
    db_create_table('og_membership', $schema['og_membership']);
  }

  if (!db_table_exists('og_membership_type')) {
    db_create_table('og_membership_type', $schema['og_membership_type']);
  }
  // We can't call og_needs_migrate() directly, so just set the variable.
  variable_set('og_needs_migrate', TRUE);
}

/**
 * Add indexes to og and og_membership tables.
 */
function og_update_7100(&$sandbox) {
  // Make sure we don't try to re-add an index that was added in previous
  // updates.
  if (!db_index_exists('og_membership', 'entity')) {
    db_add_index('og_membership', 'entity', array('etid', 'entity_type'));
  }
  if (!db_index_exists('og_membership', 'gid')) {
    db_add_index('og_membership', 'gid', array('gid'));
  }
  return t('Added table indexes to {og_membership} table.');

/**
 * Rename the 'name' column to 'type' in {OG membership}.
 */
function og_update_7101() {
  if (db_field_exists('og_membership', 'type')) {
    // Return early if field already created in og_update_7000().
    return;
  }
  $column = array(
    'description' => 'Reference to a group membership type.',
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  );
  db_change_field('og_membership', 'name', 'type', $column);
}

 * Deprecate OG group entity, and add per-bundle roles.
function og_update_7200() {
  if (!module_enable(array('entityreference'))) {
    throw new DrupalUpdateException('This version of OG requires Entity reference, but it could not be enabled.');
  $column = array(
    'description' => "The group's entity type (e.g. node, comment, etc').",
    'type' => 'varchar',
    'length' => '32',
    'not null' => TRUE,
    'default' => '',
  );

  db_add_field('og_membership', 'group_type', $column);

  // Re-add index.
  db_drop_index('og_membership', 'gid');
  db_add_index('og_membership', 'group', array('gid', 'group_type'));

  $column = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
    'description' => "The group's entity type.",
  );

  db_add_field('og_role', 'group_type', $column);
  db_add_field('og_users_roles', 'group_type', $column);

  $column = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
    'description' => "The group's bundle name.",
  );
  db_add_field('og_role', 'group_bundle', $column);

  $column = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
    'description' => "The name of the field holding the group ID, the OG memebership is associated with.",
  );
  db_add_field('og_membership', 'field_name', $column);

  // Delete the old group-audience field. The OG membership is not
  // affected by this.
  field_delete_field('group_audience');

  // Variable cleanup.
  variable_del('og_skip_access');

  // We can't call og_needs_migrate() directly, so just set the variable.
  variable_set('og_needs_migrate', TRUE);

  // See http://drupal.org/node/996236
  entity_info_cache_clear();