Hello. I've got a trouble with update to migrate version 2.5. When i tried to migrate new data from source, used earlier, i've got an error message

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'rollback_action' in 'field list':

The problem was a prefixed database (i use a "drupal_" table prefix in my database), as i understand.
As i've seen in code (migrate.install), migrate_update_7202 uses a "db_find_tables" function, which does not work with prefixes.

I've made an "ugly hack", using a schema module (schema_unprefix_table) and tablePrefix() function.

Below is a my version of update code.
i am not a professional drupal-programmer, so if someone will find a more "pro"-way to solve this, it would be great.

Hope this will be helpful.

/**
 * Add rollback_action field to all map tables
 */
function migrate_update_7202() {
  $ret = array();
  foreach (db_find_tables(Database::getConnection()->tablePrefix() . 'migrate_map_%') as $tablename) {
    if (!db_field_exists(schema_unprefix_table($tablename), 'rollback_action')) {
      db_add_field(schema_unprefix_table($tablename), 'rollback_action', array(
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Flag indicating what to do for this item on rollback',
      ));
    }
  }
  $ret[] = t('Added rollback_action column to all map tables');
  return $ret;
}

Comments

mikeryan’s picture

Unfortunately, there's not much that can be done at this point. I suppose if we fixed it in -dev now, anyone going from, say, 2.4 to 2.6 in the future in a prefixed db would be spared some trouble. But we're certainly not going to introduce a dependency on the schema module just for the sake of an update function.

I'm thinking a better approach would be to pass %migrate_map_% to db_find_tables, then strip anything before migrate_map_ in the resulting table names... I don't have a prefixed environment to test on, though.

drewish’s picture

Ran into a problem with this if you store the map tables in another schema with the source tables. It didn't uploaddate them.

mikeryan’s picture

Status: Active » Fixed

Better late than never... I put the code to add a missing rollback_action column into MigrateSQLMap::ensureTables(), so it will get added before any attempt is made to use it.

jkruppa’s picture

StatusFileSize
new699 bytes

Same problem here.
Here is a patch inspired from #1, without dependency on the schema module. I'm using a MySQL database, so I couldn't test it with others.

Maybe it can be helpful for someone.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.