Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop the ownCloud migration table instead of reusing it #7699

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions lib/private/DB/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OC\DB;

use Doctrine\DBAL\Schema\SchemaException;
use OC\IntegrityCheck\Helpers\AppLocator;
use OC\Migration\SimpleOutput;
use OCP\AppFramework\App;
Expand Down Expand Up @@ -96,9 +97,41 @@ private function createMigrationTable() {
return false;
}

if ($this->connection->tableExists('migrations')) {
$this->migrationTableCreated = true;
return false;
$schema = new SchemaWrapper($this->connection);

/**
* We drop the table when it has different columns or the definition does not
* match. E.g. ownCloud uses a length of 177 for app and 14 for version.
*/
try {
$table = $schema->getTable('migrations');
$columns = $table->getColumns();

if (count($columns) === 2) {
try {
$column = $table->getColumn('app');
$schemaMismatch = $column->getLength() !== 255;

if (!$schemaMismatch) {
$column = $table->getColumn('version');
$schemaMismatch = $column->getLength() !== 255;
}
} catch (SchemaException $e) {
// One of the columns is missing
$schemaMismatch = true;
}

if (!$schemaMismatch) {
// Table exists and schema matches: return back!
$this->migrationTableCreated = true;
return false;
}
}

// Drop the table, when it didn't match our expectations.
$this->connection->dropTable($this->connection->getPrefix() . 'migrations');
} catch (SchemaException $e) {
// Table not found, no need to panic, we will create it.
}

$tableName = $this->connection->getPrefix() . 'migrations';
Expand Down