summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-01-04 16:52:52 +0100
committerGitHub <noreply@github.com>2018-01-04 16:52:52 +0100
commite7aebcfd6b25813a4559372a101348be53999733 (patch)
tree600273bc9e8c17a9a24e223fd424c42e08dfd3de /lib
parente6557324580e4f76107a059f9fe84b03fbae2b71 (diff)
parent715405020154bba3c979652a7985c63a697b3cbb (diff)
downloadnextcloud-server-e7aebcfd6b25813a4559372a101348be53999733.tar.gz
nextcloud-server-e7aebcfd6b25813a4559372a101348be53999733.zip
Merge pull request #7699 from nextcloud/bugfix/7528/drop-owncloud-migrations-table-and-recreate-it
Drop the ownCloud migration table instead of reusing it
Diffstat (limited to 'lib')
-rw-r--r--lib/private/DB/MigrationService.php39
1 files changed, 36 insertions, 3 deletions
diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php
index a021f00a922..729f9753dfb 100644
--- a/lib/private/DB/MigrationService.php
+++ b/lib/private/DB/MigrationService.php
@@ -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;
@@ -96,9 +97,41 @@ class MigrationService {
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';