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?

(I originally posted this at https://drupal.org/node/1393082, but did not get any responses- it seems like a fairly major issue, so I am reposting here. Also, here are two actual examples of where this is a problem: #1393040: Upgrade path from 6.x to 7.x-2.x, #1426120: Error on upgrade from 6.x to 7.x)

Comments

danepowell’s picture

Issue summary: View changes

added links to existing issues

dcam’s picture

Issue summary: View changes
Status: Active » Closed (fixed)

Closing old issues.

If anyone else comes across this issue looking for the same information, in either case I would use db_table_exists() in the update function to check to see if the schema has already been installed, then return if it does.