Some databases that came from old Drupal installations seem to have a small {system}.weight. For example, on Drupal.org:

weight tinyint(3) unsigned

This breaks the upgrade process from Drupal 6 to Drupal 7 where we bump some modules to a weight > 1000.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ctmattice1’s picture

I have a patch that fixes this problem. Here is the text for further discussion as it may not be optimized.

The database I use is mysql v5.1.33 with php 5.2.9 which is a standard install of xampp 1.7.1 on vista. It get's through the system updates ok till the point where it attempts to update contrib modules. At this point I run into errors with registry.inc and non-existent paths.

Index: includes/update.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/update.inc,v
retrieving revision 1.12
diff -u -p -r1.12 update.inc
--- includes/update.inc 3 Oct 2009 20:17:46 -0000 1.12
+++ includes/update.inc 11 Oct 2009 20:06:05 -0000
@@ -123,6 +123,21 @@ function update_fix_d7_requirements() {
file_put_contents(conf_path() . '/settings.php', "\n" . '$databases = ' . var_export($databases, TRUE) . ';', FILE_APPEND);
}
if (drupal_get_installed_schema_version('system') < 7000 && !variable_get('update_d7_requirements', FALSE)) {
+
+ // Change 6.x system table field lenght values to 7.x equivelent
+ db_change_field('system', 'status', 'status',
+ array('type' => 'int', 'length' => 11, 'not null' => TRUE, 'default' => 0));
+ db_change_field('system', 'bootstrap', 'bootstrap',
+ array('type' => 'int', 'length' => 11, 'not null' => TRUE, 'default' => 0));
+ db_change_field('system', 'weight', 'weight',
+ array('type' => 'int', 'length' => 11, 'not null' => TRUE, 'default' => 0));
+ db_change_field('system', 'schema_version', 'schema_version',
+ array('type' => 'int',
+ 'size' => 'small',
+ 'length' => 6,
+ 'not null' => TRUE,
+ 'default' => -1));
+
// Add the cache_path table.
$schema['cache_path'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_path']['description'] = 'Cache table used for path alias lookups.';
@@ -133,6 +148,13 @@ function update_fix_d7_requirements() {
db_add_field('locales_source', 'context', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => 'The context this string applies to.'));
}

+ // role_premissions table is required now by user.modlue
+ update_fix_d7_role_permissions();
+
+ //registry is also required now
+ update_fix_d7_registry();
+
+
// Rename 'site_offline_message' variable to 'maintenance_mode_message'.
// Old variable is removed in update for system.module.
// @see system_update_7036().
@@ -213,6 +235,72 @@ function update_fix_d7_install_profile()
}
}

+function update_fix_d7_role_permissions() {
+ $schema['role_permission'] = array(
+ 'fields' => array(
+ 'rid' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ ),
+ 'permission' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ ),
+ 'primary key' => array('rid', 'permission'),
+ 'indexes' => array(
+ 'permission' => array('permission'),
+ ),
+ );
+
+ db_create_table('role_permission', $schema['role_permission']);
+
+}
+
+function update_fix_d7_registry() {
+ $schema['registry'] = array(
+ 'fields' => array(
+ 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'type' => array('type' => 'varchar', 'length' => 9, 'not null' => TRUE, 'default' => ''),
+ 'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'module' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+ ),
+ 'primary key' => array('name', 'type'),
+ 'indexes' => array(
+ 'hook' => array('type', 'weight', 'module'),
+ ),
+ );
+ $schema['registry_file'] = array(
+ 'fields' => array(
+ 'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
+ 'filectime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+ 'filemtime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+ ),
+ 'primary key' => array('filename'),
+ );
+ $schema['cache_registry'] = array(
+ 'fields' => array(
+ 'cid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'data' => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'),
+ 'expire' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+ 'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+ 'headers' => array('type' => 'text', 'not null' => FALSE),
+ 'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)
+ ),
+ 'indexes' => array('expire' => array('expire')),
+ 'primary key' => array('cid'),
+ );
+ db_create_table('cache_registry', $schema['cache_registry']);
+ db_create_table('registry', $schema['registry']);
+ db_create_table('registry_file', $schema['registry_file']);
+}
+
+
+
/**
* Parse database connection URLs (in the old, pre-Drupal 7 format) and
* return them as an array of database connection information.
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.395
diff -u -p -r1.395 system.install
--- modules/system/system.install 5 Oct 2009 04:34:04 -0000 1.395
+++ modules/system/system.install 11 Oct 2009 20:49:20 -0000
@@ -1782,45 +1782,53 @@ function system_update_7005() {
* longer needed.
*/
function system_update_7006() {
- $schema['registry'] = array(
- 'fields' => array(
- 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
- 'type' => array('type' => 'varchar', 'length' => 9, 'not null' => TRUE, 'default' => ''),
- 'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
- 'module' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
- 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
- ),
- 'primary key' => array('name', 'type'),
- 'indexes' => array(
- 'hook' => array('type', 'weight', 'module'),
- ),
- );
- $schema['registry_file'] = array(
- 'fields' => array(
- 'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
- 'filectime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
- 'filemtime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
- ),
- 'primary key' => array('filename'),
- );
- $schema['cache_registry'] = array(
- 'fields' => array(
- 'cid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
- 'data' => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'),
- 'expire' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
- 'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
- 'headers' => array('type' => 'text', 'not null' => FALSE),
- 'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)
- ),
- 'indexes' => array('expire' => array('expire')),
- 'primary key' => array('cid'),
- );
- db_create_table('cache_registry', $schema['cache_registry']);
- db_create_table('registry', $schema['registry']);
- db_create_table('registry_file', $schema['registry_file']);
+ // Check to see if it was already run by update_fix_d7_requirements()
+ if (!db_table_exists('registry')) {
+ $schema['registry'] = array(
+ 'fields' => array(
+ 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'type' => array('type' => 'varchar', 'length' => 9, 'not null' => TRUE, 'default' => ''),
+ 'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'module' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+ ),
+ 'primary key' => array('name', 'type'),
+ 'indexes' => array(
+ 'hook' => array('type', 'weight', 'module'),
+ ),
+ );
+ db_create_table('registry', $schema['registry']);
+ }
+ if (!db_table_exists('registry_file')) {
+ $schema['registry_file'] = array(
+ 'fields' => array(
+ 'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
+ 'filectime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+ 'filemtime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+ ),
+ 'primary key' => array('filename'),
+ );
+ db_create_table('registry_file', $schema['registry_file']);
+ }
+ if (!db_table_exists('cache_registry')) {
+ $schema['cache_registry'] = array(
+ 'fields' => array(
+ 'cid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'data' => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'),
+ 'expire' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+ 'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+ 'headers' => array('type' => 'text', 'not null' => FALSE),
+ 'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)
+ ),
+ 'indexes' => array('expire' => array('expire')),
+ 'primary key' => array('cid'),
+ );
+ db_create_table('cache_registry', $schema['cache_registry']);
+ }
registry_rebuild();
}

+
/**
* Convert to new method of storing permissions.
*
@@ -1828,27 +1836,30 @@ function system_update_7006() {
* all modules can use the updated permission scheme during their updates.
*/
function system_update_7007() {
- $schema['role_permission'] = array(
- 'fields' => array(
- 'rid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
+ // Check to see if it was already run by update_fix_d7_requirements()
+ if (!db_table_exists('role_permission')) {
+ $schema['role_permission'] = array(
+ 'fields' => array(
+ 'rid' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ ),
+ 'permission' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ ),
+ 'primary key' => array('rid', 'permission'),
+ 'indexes' => array(
+ 'permission' => array('permission'),
),
- 'permission' => array(
- 'type' => 'varchar',
- 'length' => 64,
- 'not null' => TRUE,
- 'default' => '',
- ),
- ),
- 'primary key' => array('rid', 'permission'),
- 'indexes' => array(
- 'permission' => array('permission'),
- ),
- );
+ );

- db_create_table('role_permission', $schema['role_permission']);
+ db_create_table('role_permission', $schema['role_permission']);
+ }

// Copy the permissions from the old {permission} table to the new {role_permission} table.
$messages = array();
Index: modules/upload/upload.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload/upload.install,v
retrieving revision 1.15
diff -u -p -r1.15 upload.install
--- modules/upload/upload.install 29 Sep 2009 15:13:57 -0000 1.15
+++ modules/upload/upload.install 11 Oct 2009 20:28:26 -0000
@@ -97,7 +97,7 @@ function upload_update_7000(&$sandbox) {

// As a batch operation move records from {files} into the {file} table.
$limit = 500;
- $result = db_query_range("SELECT DISTINCT u.fid FROM {upload} u ORDER BY u.vid", array(), 0, $limit);
+ $result = db_query_range("SELECT DISTINCT u.fid FROM {upload} u ORDER BY u.vid", 0, $limit, array());
foreach ($result as $record) {
$old_file = db_query('SELECT f.* FROM {files} f WHERE f.fid = :fid', array(':fid' => $record->fid))->fetch(PDO::FETCH_OBJ);
if (!$old_file) {

mikey_p’s picture

Issue tags: +D7 upgrade path

tagging

sun.core’s picture

Issue tags: +Novice

.

ctmattice1’s picture

Status: Active » Needs review
FileSize
1.49 KB

Ideally what should be done is to convert the 6.x system field values to match those of D7. What reason would there be on an upgrade not to do this. This will not break any 6.x sites doing this in case the update fails down stream.

Please review the following code, it does not use $schema as the table only need modification. I'm wonder though why D7 carries a int 11 in weights this seems a little high and would probably make more sense to use a small init 6 as in the schema_version field.

Index: includes/update.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/update.inc,v
retrieving revision 1.31
diff -u -p -r1.31 update.inc
--- includes/update.inc 25 Jan 2010 10:38:34 -0000 1.31
+++ includes/update.inc 27 Jan 2010 00:45:47 -0000
@@ -266,6 +266,19 @@ function update_fix_d7_requirements() {
file_put_contents(conf_path() . '/settings.php', "\n" . '$databases = ' . var_export($databases, TRUE) . ";\n\$drupal_hash_salt = '$salt';", FILE_APPEND);
}
if (drupal_get_installed_schema_version('system') < 7000 && !variable_get('update_d7_requirements', FALSE)) {
+ // Change 6.x system table field values to 7.x equivelent
+ db_change_field('system', 'status', 'status',
+ array('type' => 'int', 'length' => 11, 'not null' => TRUE, 'default' => 0));
+ db_change_field('system', 'bootstrap', 'bootstrap',
+ array('type' => 'int', 'length' => 11, 'not null' => TRUE, 'default' => 0));
+ db_change_field('system', 'weight', 'weight',
+ array('type' => 'int', 'length' => 11, 'not null' => TRUE, 'default' => 0));
+ db_change_field('system', 'schema_version', 'schema_version',
+ array('type' => 'int',
+ 'size' => 'small',
+ 'length' => 6,
+ 'not null' => TRUE,
+ 'default' => -1));
// Add the cache_path table.
$schema['cache_path'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_path']['description'] = 'Cache table used for path alias lookups.';

Patch attached based on yesterday's HEAD

Status: Needs review » Needs work

The last submitted patch, fixsystemweight.patch, failed testing.

chx’s picture

Status: Needs work » Closed (duplicate)
ctmattice1’s picture

Status: Closed (duplicate) » Needs review
FileSize
2.17 KB

I see where there is similarities with #612870: Weight fields should be int, not tinyint and it has been committed. however, there is one table that still needs correction in addition to those, the system table, without fixing it there are some upgrades from d6 to d7 that will fail immediately. I've attached a corrected patch to fix it.

catch’s picture

Status: Needs review » Needs work

Yes system was missing from the other patch.

+++ includes/update.inc   30 Jan 2010 19:30:48 -0000
@@ -266,7 +266,33 @@ function update_fix_d7_requirements() {
+  // Change 6.x system table field values to 7.x equivelent
+  db_change_field('system', 'schema_version', 'schema_version',
...
+     'default' => -1)
+  );
+  db_drop_index('system' ,'modules'); // D6 index

Should be "equivalent", also comments should be sentence case and include a period, and above the code they describe rather than inline on the same line - see http://drupal.org/coding-standards

Additionally, where we're dropping and recreating the same index - could we put those statements next to each other?

Looks like the path index comment appears twice in the patch?

Powered by Dreditor.

ctmattice1’s picture

Status: Needs work » Needs review
FileSize
2.23 KB

Corrected patch as catch suggested. Fixed modules index where bootstrap field should not have been present.

Magnity’s picture

Status: Needs review » Needs work
+++ includes/update.inc   31 Jan 2010 21:39:31 -0000
@@ -266,7 +266,39 @@ function update_fix_d7_requirements() {
+
+  // Add the cache_path table.
+     $schema['cache_path'] = drupal_get_schema_unprocessed('system', 'cache');
+     $schema['cache_path']['description'] = 'Cache table used for path alias lookups.';
+  // Add the cache_path table.
     $schema['cache_path'] = drupal_get_schema_unprocessed('system', 'cache');
     $schema['cache_path']['description'] = 'Cache table used for path alias lookups.';

Duplicated code?

Powered by Dreditor.

ctmattice1’s picture

Status: Needs work » Needs review
FileSize
2.03 KB

Hmmm, missed that one. Stupid copy and paste error a couple patches ago. My Bad

catch’s picture

Status: Needs review » Reviewed & tested by the community

Looks good now.

aaron’s picture

subscribe

webchick’s picture

Priority: Critical » Normal
Status: Reviewed & tested by the community » Needs work

This seems to have some comment indentation issues, and also warns me about fuzz when I apply it. I can haz re-roll?

catch’s picture

Priority: Normal » Critical
Status: Needs work » Reviewed & tested by the community
FileSize
2.06 KB

You can haz.

Also this really is critical - no Drupal 5 site can upgrade to Drupal 7 without this patch afaik.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Awesome, thanks. Committed to HEAD!

andypost’s picture

Status: Fixed » Needs review
FileSize
1.27 KB

What's 'lenght' parameter means for INT data-type? Is this mysql specific? Suppose no!
Here is a patch to remove length from schema definition.

webchick’s picture

Status: Needs review » Fixed

Oops. :P

Thanks, committed to HEAD. :)

Status: Fixed » Closed (fixed)
Issue tags: -Novice, -D7 upgrade path

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