Site converted from D5 -> d6 and now testing conversion to D7 alpha2. Get the following message. After the failure there are no indexes on {block} outside the primary.
Update #7003
* Failed: SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'list'; check that column/key exists

Alpha2 with one patch from http://drupal.org/node/719730. I started wrapping db_index_exits around the drop in 7003 and found: http://drupal.org/node/722912

Comments

peterx’s picture

I changed 7003 to start with:

function block_update_7003() {
  if(db_index_exists('block', 'list'))
    {
    db_drop_index('block', 'list');
    }

It passed the first error then hit the following message because, with unicode support, all those fields are over 1150 bytes total.
Failed: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

peterx’s picture

MySQL can combine multiple indexes to find data so I tried again with the following test split of the index. The block updates worked.

  ), array(
    'indexes' => array(
      'theme' => array('theme'),
      'list' => array('status', 'region', 'weight', 'module'),
    ),
andypost’s picture

Version: 7.0-alpha2 » 7.x-dev

It seems very strange because system_update_6043()

// Change length of theme field in {blocks} to be consistent with module, and
  // to avoid a MySQL error regarding a too-long index.  Also add new indices.
  db_change_field($ret, 'blocks', 'theme', 'theme', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''),array(
                  'unique keys' => array('tmd' => array('theme', 'module', 'delta'),),
                  'indexes' => array('list' => array('theme', 'status', 'region', 'weight', 'module'),),));

So index should be here!

peterx’s picture

I checked a few sites and the D6 sites have the new format but the D5->D6 converted sites have the old format. I checked schema_version for block and they all show zero. Ah, the update is under system, not block. Ok, system is up to 6053. 6043 ran because other tables changed. I suspect having the field change and index add in the same step resulted in the index add occurring before the field changed and the update failed because of the 1000 byte limit. If the block change had been made into two steps, it would have worked.

peterx’s picture

I made an ugly change to get around the problem:

function block_update_7003() {
  if(db_index_exists('block', 'list'))
    {
    db_drop_index('block', 'list');
    }
  else
    {
    db_change_field('block', 'theme', 'theme', array(
      'type' => 'varchar',
      'length' => 64,
      'not null' => TRUE,
      'default' => ''
      ));
    db_add_unique_key('block', 'tmd', array('theme', 'module', 'delta'));
    }
  db_change_field('block', 'weight', 'weight', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => 'Block weight within region.',
  ), array(
    'indexes' => array(
      'list' => array('theme', 'status', 'region', 'weight', 'module'),
    ),
  ));
}

Now I get:
Update #7003 * Failed: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'bluemarine-block-1' for key 'tmd'

There are 133 duplicate rows. The only thing I can think of at this stage is to manually clean up my D5->D6 site and go back to testing the D7 conversion with the clean database.

andypost’s picture

It seems that we stopped until #722912: db_index_exists() must conform schemaAPI indexExists() fixed

Also I have random fail with block_cache table #603498: Book {blocks.cache} upgrade path

ctmattice1’s picture

@peterx "The only thing I can think of at this stage is to manually clean up my D5->D6 site and go back to testing the
D7 conversion with the clean database. "

If it helps the easiest way I've found to do this is with phpmyadmin. I create a copy of my D5->D6 database I use and create a testing database (copy) from it. When I blow the testing database, I delete it and use phpmyadmin's operations copy function to copy it over to create a new testing database. Saved me a bunch of time. I also just use a D7 tarball and patches on a dev platform so I don't have other issues from contrib modules.

Frustrating at times, other times it's nice to hit the delete key and blow away something you don't have to worry about and start over fresh

my2cents

peterx’s picture

@ctmattice1 I do use a test site. I run the backup module to produce a daily SQL file and back the SQL file up to other computers including my desktop. I then import the SQL into a test site along side tux paint and pictures of insects. Quicker than waiting for an upload to a server plus my neighbour's 4 year old helps me edit the code. When you have to indent with spaces instead of tabs, it is useful to have an assistant who is happy to bash on the spacebar with a lego brick.

My source site is now changed the way 6043 was supposed to change it. My SQL backups no longer create this issue. There is one filter problem to fix then the site should convert.

andypost’s picture

Status: Active » Needs review
StatusFileSize
new898 bytes

Seems more reasonable to drop this index before renaming table after mostly for pgsql/sqlite databases (no need to rename index)

andypost’s picture

StatusFileSize
new899 bytes

Table should be {blocks} no {block}

Also I think this is not issue anymore but this optimization could go in if anyone review it

EDIT: there's a more useful issue #735900: Deleting module's blocks when module is uninstalled

catch’s picture

Title: Update #7003 * Failed: SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'list' » Slightly optimize the block upgrade path
Priority: Normal » Minor
Status: Needs review » Reviewed & tested by the community

Looks fine.

catch’s picture

#10: 722920_block-index_d7.patch queued for re-testing.

dawehner’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7
dries’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Fixed

This patch does not to go in 8.x. It should in 7.x instead because we removed these update functions from 8.x. I've committed it to the 7.x branch so marking this 'fixed'. Also correcting the version field for future reference.

bfroehle’s picture

Issue tags: -Needs backport to D7

Untagging since it's been committed to 7.x

Status: Fixed » Closed (fixed)

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