Skip to content

Commit

Permalink
Fixed issue: Database update fails due to invalid database engine and…
Browse files Browse the repository at this point in the history
… collation being set on new tables

Fixed issue: Database update fails due to labels without code
  • Loading branch information
c-schmitz committed Mar 18, 2020
1 parent fb9e9af commit 06bb593
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion application/helpers/update/updatedb_helper.php
Expand Up @@ -71,8 +71,12 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false)
$oDB->schemaCachingDuration = 0; // Deactivate schema caching
Yii::app()->setConfig('Updating', true);
$options = "";
// The engine has to be explicitely set because MYSQL 8 switches the default engine to INNODB
if ( Yii::app()->db->driverName == 'mysql' ) {
$options = 'ROW_FORMAT=DYNAMIC'; // Same than create-database
$options='ENGINE='.Yii::app()->getConfig('mysqlEngine').' DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci';
if (Yii::app()->getConfig('mysqlEngine')=='INNODB') {
$options .= ' ROW_FORMAT=DYNAMIC'; // Same than create-database
}
}
try {

Expand Down Expand Up @@ -2600,6 +2604,8 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false)
'language' => "string(20) NOT NULL DEFAULT 'en'"
), $options);
$oDB->createCommand()->createIndex('{{idx1_label_l10ns}}', '{{label_l10ns}}', ['label_id', 'language'], true);
// Remove invalid labels, otherwise update will fail because of index duplicates in the next query

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Mar 19, 2020

Collaborator

A things to do on checkintegrity ? I don't know if it's a good solution to have a minimal checkintegrity before upgrade ...

$oDB->createCommand("delete from {{labels_update400}} WHERE code=''")->execute();
$oDB->createCommand("INSERT INTO {{label_l10ns}}
(label_id, title, language)
SELECT {{labels}}.id ,{{labels_update400}}.title,{{labels_update400}}.language
Expand Down

0 comments on commit 06bb593

Please sign in to comment.