Skip to content

Commit

Permalink
Merge pull request #28086 from owncloud/migration-col-length
Browse files Browse the repository at this point in the history
Fix column lengths on migrations table to fix index
  • Loading branch information
Vincent Petry authored Jun 21, 2017
2 parents a9a27d1 + 1877285 commit 684518d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
27 changes: 27 additions & 0 deletions core/Migrations/Version20170605143658.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace OC\Migrations;

use Doctrine\DBAL\Schema\Schema;
use OCP\Migration\ISchemaMigration;

/**
* Updates the column lengths for the migrations table to reflect changes in its schema
*/
class Version20170605143658 implements ISchemaMigration {

public function changeSchema(Schema $schema, array $options) {
// Get the table
$prefix = $options['tablePrefix'];
$table = $schema->getTable("{$prefix}migrations");

// Check column length to see if migration is necessary necessary
if($table->getColumn('app')->getLength() === 177) {
// then this server was installed after the fix
return;
}

// Need to shorten columns
$table->getColumn('app')->setLength(177);
$table->getColumn('version')->setLength(14);
}
}
6 changes: 4 additions & 2 deletions lib/private/DB/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ private function createMigrationTable() {
$tableName = $this->connection->getDatabasePlatform()->quoteIdentifier($tableName);

$columns = [
'app' => new Column($this->connection->getDatabasePlatform()->quoteIdentifier('app'), Type::getType('string'), ['length' => 255]),
'version' => new Column($this->connection->getDatabasePlatform()->quoteIdentifier('version'), Type::getType('string'), ['length' => 255]),
// Length = max indexable char length - length of other columns = 191 - 14
'app' => new Column($this->connection->getDatabasePlatform()->quoteIdentifier('app'), Type::getType('string'), ['length' => 177]),
// Datetime string. Eg: 20172605104128
'version' => new Column($this->connection->getDatabasePlatform()->quoteIdentifier('version'), Type::getType('string'), ['length' => 14]),
];
$table = new Table($tableName, $columns);
$table->setPrimaryKey([
Expand Down

0 comments on commit 684518d

Please sign in to comment.