Skip to content

Commit

Permalink
Fixes #127 error.
Browse files Browse the repository at this point in the history
Drop indexes before renaming instead of after. Otherwise this causes errors on mariadb.
  • Loading branch information
Roel van Hintum committed Oct 12, 2018
1 parent d26e2dd commit b711b87
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/migrations/m180219_000000_sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ public function safeUp()

foreach ($this->db->getSchema()->getTableNames() as $tableName) {
if (StringHelper::startsWith($tableName, $superTableTablePrefix)) {
// Rename column
if ($this->db->columnExists($tableName, 'locale__siteId')) {
$this->renameColumn($tableName, 'locale__siteId', 'siteId');
}

// There's actually an issue here in the MigrationHelper::dropAllIndexesOnTable class, not using the current migration
// as context to find existing indexes. This is important, because the indexes have changed from their current names
$this->dropAllForeignKeysOnTable($tableName);
$this->dropAllIndexesOnTable($tableName);

// Rename column
if ($this->db->columnExists($tableName, 'locale__siteId')) {
$this->renameColumn($tableName, 'locale__siteId', 'siteId');
}

// Add them back (like creating a new Matrix would)
$this->createIndex(null, $tableName, ['elementId', 'siteId'], true);
$this->addForeignKey(null, $tableName, ['elementId'], '{{%elements}}', ['id'], 'CASCADE', null);
Expand Down

0 comments on commit b711b87

Please sign in to comment.