Let's say that you maintain two branches of a module simultaneously, 6.x-1.x and 7.x-1.x. Initially, the module is simple and doesn't require a schema. Later on though, you decide to add a schema, so you add hook_update_6101 and hook_update_7101, which install the schema. No problem, right?

Conundrum: how do you support upgrades from 6.x-1.x to 7.x-1.x? Users upgrading from 6101 to 7101 will get the 7101 update, which will throw errors because the schema is already installed, right?

Furthermore, I know that you should probably implement hook_update_7100 to install the 'initial' schema for the 7.x-1.x branch, which in this case is no schema at all. If you do this, you will effectively be wiping all of the module's data, just so you can recreate the schema in a later update! So how can you preserve the data through the upgrade?

Comments

danepowell’s picture

This seems like a fairly major issue; because I was not able to get any responses here, I have posted it in the core issue queue: https://drupal.org/node/1547590

jaypan’s picture

You could wrap db_create_table() in your D7 module inside a conditional that checks if the table exists or not:

function MY_MODULE_update_7001()
{
  if(!db_table_exists('my_table'))
  {
    db_create_table('my_table', ....);
  }
}

Contact me to contract me for D7 -> D10/11 migrations.

colemanw’s picture

Just use MY_MODULE_update_6101() in both branches. Works fine.