Newer
Older
Mike Ryan
committed
<?php
/**
Mike Ryan
committed
function migrate_schema() {
$schema = array();
$schema['migrate_status'] = migrate_schema_status();
return $schema;
}
function migrate_schema_status() {
return array(
'description' => 'Status information for migrations',
Mike Ryan
committed
'fields' => array(
Mike Ryan
committed
'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',
),
'type' => 'int',
'size' => 'tiny',
'description' => 'Current status of migration',
'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',
),
),
'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(
'type' => 'int',
'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',
'unsigned' => TRUE,
'description' => 'End time of a migration process, times 1000',
Mike Ryan
committed
),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'finalhighwater' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Final highwater mark',
),
'numprocessed' => array(
'type' => 'int',
'not null' => FALSE,
Mike Ryan
committed
),
Mike Ryan
committed
);
}
/**
* Implementation of hook_uninstall().
* Drop map/message tables, in case implementing classes did not.
Mike Ryan
committed
function migrate_uninstall() {
// 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');
/**
* 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,
'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');
return $ret;
}
/**
* 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;
}
/**
* 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;
}
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/**
* 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;
}