Bug #19504
closedDB Analyzer / Compare Tool can't handle the upgrade of the cache tables
0%
Description
Here're some findings from Ernesto:
when changing the SQL-definitions of cache_hash and cache_pagesection:
CREATE TABLE cache_hash (
- hash varchar(32) DEFAULT '' NOT NULL,
- content mediumblob,
- tstamp int(11) unsigned DEFAULT '0' NOT NULL,
- ident varchar(20) DEFAULT '' NOT NULL,
- PRIMARY KEY (hash)
+ id int(11) unsigned NOT NULL auto_increment,
+ identifier varchar(32) DEFAULT '' NOT NULL,
+ crdate int(11) unsigned DEFAULT '0' NOT NULL,
+ content mediumtext,
+ tags mediumtext,
+ lifetime int(11) unsigned DEFAULT '0' NOT NULL,
+ PRIMARY KEY (id),
+ KEY cache_id (identifier)
) ENGINE=InnoDB;
and:
CREATE TABLE cache_pagesection (
- page_id int(11) unsigned DEFAULT '0' NOT NULL,
- mpvar_hash int(11) unsigned DEFAULT '0' NOT NULL,
- content blob,
- tstamp int(11) unsigned DEFAULT '0' NOT NULL,
- PRIMARY KEY (page_id,mpvar_hash)
+ id int(11) unsigned NOT NULL auto_increment,
+ identifier varchar(32) DEFAULT '' NOT NULL,
+ crdate int(11) unsigned DEFAULT '0' NOT NULL,
+ content mediumtext,
+ tags mediumtext,
+ lifetime int(11) unsigned DEFAULT '0' NOT NULL,
+ PRIMARY KEY (id),
+ KEY cache_id (identifier)
) ENGINE=InnoDB;
The might work on a "fresh" TYPO3 install, but on an upgrade, this will
create the following SQL statements (COMPARE in Install Tool):
Add fields:
ALTER TABLE cache_hash ADD id int(11) unsigned NOT NULL auto_increment;
ALTER TABLE cache_hash ADD identifier varchar(32) NOT NULL default '';
ALTER TABLE cache_hash ADD crdate int(11) unsigned NOT NULL default '0';
ALTER TABLE cache_hash ADD tags mediumtext;
ALTER TABLE cache_hash ADD lifetime int(11) unsigned NOT NULL default '0';
ALTER TABLE cache_hash ADD KEY cache_id (identifier);
ALTER TABLE cache_pagesection ADD id int(11) unsigned NOT NULL
auto_increment;
ALTER TABLE cache_pagesection ADD PRIMARY KEY (id);
Changing fields:
ALTER TABLE cache_hash CHANGE content content mediumtext;
Current value: mediumblob
ALTER TABLE cache_hash DROP PRIMARY KEY;
ALTER TABLE cache_hash ADD PRIMARY KEY (id);
ALTER TABLE cache_hash ENGINE=InnoDB;
Current value: ENGINE=MyISAM
Executing that in that order will never add the "id" field, because of:
mysql> ALTER TABLE cache_hash ADD id int(11) unsigned NOT NULL
auto_increment;
ERROR 1075 (42000): Incorrect table definition; there can be only one
auto column and it must be defined as a key
This is clearly a limitation of our SQL-update-statement-generator, as
the correct order would be:
ALTER TABLE cache_hash DROP PRIMARY KEY;
ALTER TABLE cache_hash ADD id int(11) unsigned NOT NULL auto_increment
PRIMARY KEY;
(auto_increment has to be defined together with "PRIMARY KEY" for a field).
(issue imported from #M9639)
Files
Updated by Michael Stucki about 16 years ago
There are two reasons for this:
1. The table must be cleared to make sure that the keys are unique. This is no problem for cache_* tables.
2. auto_increment must be set after the primary key was created. However, the primary key can only be created if the field already exists. So the field must be created in two steps (first without the "auto_increment" option).
Attached is a patch that fixes both issues. However it will require to go through the update twice:
1st step:
- Remove all fields which are no longer used (drop them really, not just rename)
- Clear cache_* and index_* tables which are going to be modified
- Create new fields (without "auto_increment" option)
- Create keys
2nd step:
- Add "auto_increment" option
It seems this works pretty flawlessly, and I was also able to backport the same fix to 4.2 which may be worth a though, too.
Please test & give feedback.
Updated by Oliver Hader about 16 years ago
Committed to SVN Trunk (rev. 4459) - TYPO3 4.3-alpha1
The commit for TYPO3_4-2 is still pending!
Updated by Franz Holzinger over 15 years ago
Still present in TYPO3 4.3.0 alpha 3.
Add fields
ALTER TABLE cache_hash ADD PRIMARY KEY (id);
ALTER TABLE cache_pagesection ADD PRIMARY KEY (id);
Changing fields
ALTER TABLE cache_hash CHANGE id id int(11) unsigned;
Current value: int(11) unsigned default ''
ALTER TABLE cache_pagesection CHANGE id id int(11) unsigned;
Current value: int(11) unsigned default ''
Updated by Oliver Hader almost 15 years ago
Not required anymore since the caching framework uses new tables...