Skip to content
migrate.install 7.38 KiB
Newer Older
 * Migrate module installation
  $schema = array();
  $schema['migrate_status'] = migrate_schema_status();
Mike Ryan's avatar
Mike Ryan committed
  $schema['migrate_log'] = migrate_schema_log();
  return $schema;
}

function migrate_schema_status() {
  return array(
    'description' => 'Status information for migrations',
      'machine_name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'Unique machine name for migration',
      'class_name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'Name of class to instantiate for this migration',
      ),
      'status' => array(
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Current status of migration',
Mike Ryan's avatar
Mike Ryan committed
      'highwater' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Highwater mark for detecting updated content',
      ),
      'arguments' => array(
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'A serialized array of arguments to the migration constructor',
      ),
Mike Ryan's avatar
Mike Ryan committed
    ),
    'primary key' => array('machine_name'),
  );
}

function migrate_schema_log() {
  return array(
    'description' => 'History of migration processes',
    'fields' => array(
      'mlid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary key for migrate_log table',
      ),
      'machine_name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'Unique machine name for migration',
      ),
      'process_type' => array(
Mike Ryan's avatar
Mike Ryan committed
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Type of migration process - 1 for import, 2 for rollback',
      ),
      'starttime' => array(
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Begin time of a migration process, times 1000',
      ),
      'endtime' => array(
        'type' => 'int',
        'size' => 'big',
Mike Ryan's avatar
Mike Ryan committed
        'not null' => FALSE,
Mike Ryan's avatar
Mike Ryan committed
        'description' => 'End time of a migration process, times 1000',
Mike Ryan's avatar
Mike Ryan committed
      'initialhighwater' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
Mike Ryan's avatar
Mike Ryan committed
        'description' => 'Initial highwater mark',
Mike Ryan's avatar
Mike Ryan committed
      'finalhighwater' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'description' => 'Final highwater mark',
      ),
      'numprocessed' => array(
Mike Ryan's avatar
Mike Ryan committed
        'unsigned' => TRUE,
Mike Ryan's avatar
Mike Ryan committed
        'description' => 'Number of items processed',
Mike Ryan's avatar
Mike Ryan committed
    'primary key' => array('mlid'),
 * Implementation of hook_uninstall().
 * Drop map/message tables, in case implementing classes did not.
  // Note: If a derived Migration class defined its own map or message
  // table name not fitting this pattern, that class is solely responsible for
  // cleaning up
  // TODO: Prefix table names (db_find_tables does not do it)
  foreach (db_find_tables('migrate_map_%') as $tablename) {
    db_drop_table($tablename);
  foreach (db_find_tables('migrate_message_%') as $tablename) {
    db_drop_table($tablename);
  }
}

/**
 * Add highwater mark
 */
function migrate_update_7001() {
  $ret = array();
  db_add_field('migrate_status', 'highwater', array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Highwater mark for detecting updated content',
      )
  );

  $ret[] = t('Added highwater column to migrate_status table');
  return $ret;
}

/**
 * Add last_imported field to all map tables
 */
function migrate_update_7002() {
  $ret = array();
  foreach (db_find_tables('migrate_map_%') as $tablename) {
    if (!db_column_exists($tablename, 'last_imported')) {
      db_add_field($tablename, 'last_imported', array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
Mike Ryan's avatar
Mike Ryan committed
        'default' => 0,
        'description' => 'UNIX timestamp of the last time this row was imported',
      ));
    }
  }
  $ret[] = t('Added last_imported column to all map tables');
  return $ret;
}

/**
 * Add lastthroughput column to migrate_status
 */
function migrate_update_7003() {
  $ret = array();
  db_add_field('migrate_status', 'lastthroughput', array(
      'type' => 'int',
      'length' => 11,
      'not null' => FALSE,
      'description' => 'Rate of success during most recent completed import (# per minute)',
    )
  );

  $ret[] = t('Added lastthroughput column to migrate_status table');

/**
 * Convert lastimported datetime field to lastimportedtime int field.
 */
function migrate_update_7004() {
  $ret = array();
  db_add_field('migrate_status', 'lastimportedtime', array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => FALSE,
      'description' => 'Date and time of last completed import',
    )
  );

  $result = db_select('migrate_status', 'ms')
            ->fields('ms', array('machine_name', 'lastimported'))
            ->execute();
  foreach ($result as $row) {
    $lastimportedtime = strtotime($row->lastimported);
    db_update('migrate_status')
      ->fields(array('lastimportedtime' => $lastimportedtime))
      ->condition('machine_name', $row->machine_name)
      ->execute();
  }

  db_drop_field('migrate_status', 'lastimported');

  $ret[] = t('Converted lastimported datetime field to lastimportedtime int field');
  return $ret;
}
Mike Ryan's avatar
Mike Ryan committed

/**
 * Add support for history logging
 */
function migrate_update_7005() {
  $ret = array();
  $ret[] = t('Create migrate_log table');
  db_create_table('migrate_log', migrate_schema_log());
  $ret[] = t('Remove historic columns from migrate_status table');
  db_drop_field('migrate_status', 'lastthroughput');
  db_drop_field('migrate_status', 'lastimportedtime');
  return $ret;
}

/**
 * Add and populate class_name field. Any existing migration code using
 * dependencies or sourceMigration() must be changed! See CHANGELOG.txt.
 */
function migrate_update_7006() {
  $ret = array();
  db_add_field('migrate_status', 'class_name', array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Name of class to instantiate for this migration',
      )
  );

  db_query("UPDATE {migrate_status}
            SET class_name = CONCAT(machine_name, 'Migration')
           ");
  $ret[] = t('Added class_name column to migrate_status table');
  return $ret;
}

/**
 * Add arguments field to migrate_status table.
 */
function migrate_update_7007() {
  $ret = array();
  db_add_field('migrate_status', 'arguments', array(
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'A serialized array of arguments to the migration constructor',
        )
  );

  $ret[] = t('Added arguments column to migrate_status table');
  return $ret;
}