Skip to content
Merged
Show file tree
Hide file tree
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
46 changes: 46 additions & 0 deletions lib/private/DB/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ private function createMigrationTable() {
return false;
}

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

$schema = new SchemaWrapper($this->connection);

/**
Expand Down Expand Up @@ -408,13 +413,54 @@ public function setOutput(IOutput $output) {
* @throws \InvalidArgumentException
*/
public function migrate($to = 'latest', $schemaOnly = false) {
if ($schemaOnly) {
$this->migrateSchemaOnly($to);
return;
}

// read known migrations
$toBeExecuted = $this->getMigrationsToExecute($to);
foreach ($toBeExecuted as $version) {
$this->executeStep($version, $schemaOnly);
}
}

/**
* Applies all not yet applied versions up to $to
*
* @param string $to
* @throws \InvalidArgumentException
*/
public function migrateSchemaOnly($to = 'latest') {
// read known migrations
$toBeExecuted = $this->getMigrationsToExecute($to);

if (empty($toBeExecuted)) {
return;
}

$toSchema = null;
foreach ($toBeExecuted as $version) {
$instance = $this->createInstance($version);

$toSchema = $instance->changeSchema($this->output, function () use ($toSchema) {
return $toSchema ?: new SchemaWrapper($this->connection);
}, ['tablePrefix' => $this->connection->getPrefix()]) ?: $toSchema;

$this->markAsExecuted($version);
}

if ($toSchema instanceof SchemaWrapper) {
$targetSchema = $toSchema->getWrappedSchema();
if ($this->checkOracle) {
$beforeSchema = $this->connection->createSchema();
$this->ensureOracleIdentifierLengthLimit($beforeSchema, $targetSchema, strlen($this->connection->getPrefix()));
}
$this->connection->migrateToSchema($targetSchema);
$toSchema->performDropTableCalls();
}
}

/**
* Get the human readable descriptions for the migration steps to run
*
Expand Down
1 change: 1 addition & 0 deletions lib/private/DB/SchemaWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function hasTable($tableName) {
* @return \Doctrine\DBAL\Schema\Table
*/
public function createTable($tableName) {
unset($this->tablesToDelete[$tableName]);
return $this->schema->createTable($this->connection->getPrefix() . $tableName);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/private/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function installApp(string $appId, bool $forceEnable = false): string {
}
} else {
$ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection());
$ms->migrate();
$ms->migrate('latest', true);
}
if ($previousVersion) {
OC_App::executeRepairSteps($appId, $info['repair-steps']['post-migration']);
Expand Down Expand Up @@ -589,7 +589,7 @@ public static function installShippedApp($app) {
}
} else {
$ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection());
$ms->migrate();
$ms->migrate('latest', true);
}

//run appinfo/install.php
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Setup/AbstractDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ public function runMigrations() {
return;
}
$ms = new MigrationService('core', \OC::$server->getDatabaseConnection());
$ms->migrate();
$ms->migrate('latest', true);
}
}