Skip to content

Instantly share code, notes, and snippets.

@brooke-heaton
Created June 19, 2018 20:50
Show Gist options
  • Save brooke-heaton/4c5751e701a3e3c9c043b8bc6303a5c8 to your computer and use it in GitHub Desktop.
Save brooke-heaton/4c5751e701a3e3c9c043b8bc6303a5c8 to your computer and use it in GitHub Desktop.
Add custom mapping tables for a migration process that merges terms - these tables will be used to import data from a csv file
<?php
/**
* Add legacy and new term name mapping for Section and Subject vocabularies
*/
function my_migration_update_8001() {
$section_schema = [
'description' => 'Legacy section term name to new section term name',
'fields' => [
'legacy_id' => [
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique person ID.',
],
'old_name' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Name of the person.',
],
'new_name' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Name of the person.',
],
],
'primary key' => ['legacy_id'],
'indexes' => [
'old_name' => ['old_name'],
'new_name' => ['new_name'],
],
];
db_create_table('my_migration_section', $section_schema);
$subject_schema = [
'description' => 'Legacy section term name to new section term name',
'fields' => [
'legacy_id' => [
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique person ID.',
],
'old_name' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Name of the person.',
],
'new_name' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Name of the person.',
],
],
'primary key' => ['legacy_id'],
'indexes' => [
'old_name' => ['old_name'],
'new_name' => ['new_name'],
]
];
db_create_table('my_migration_subject', $subject_schema);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment