Skip to content

Commit 691409c

Browse files
authored
Merge pull request #24062 from nextcloud/revert-24060-revert-24039-faster-installation
Revert "Revert "Installation goes brrrr""
2 parents 7fd7601 + 9a3ce2f commit 691409c

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

lib/private/DB/MigrationService.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ private function createMigrationTable() {
124124
return false;
125125
}
126126

127+
if ($this->connection->tableExists('migrations')) {
128+
$this->migrationTableCreated = true;
129+
return false;
130+
}
131+
127132
$schema = new SchemaWrapper($this->connection);
128133

129134
/**
@@ -408,13 +413,54 @@ public function setOutput(IOutput $output) {
408413
* @throws \InvalidArgumentException
409414
*/
410415
public function migrate($to = 'latest', $schemaOnly = false) {
416+
if ($schemaOnly) {
417+
$this->migrateSchemaOnly($to);
418+
return;
419+
}
420+
411421
// read known migrations
412422
$toBeExecuted = $this->getMigrationsToExecute($to);
413423
foreach ($toBeExecuted as $version) {
414424
$this->executeStep($version, $schemaOnly);
415425
}
416426
}
417427

428+
/**
429+
* Applies all not yet applied versions up to $to
430+
*
431+
* @param string $to
432+
* @throws \InvalidArgumentException
433+
*/
434+
public function migrateSchemaOnly($to = 'latest') {
435+
// read known migrations
436+
$toBeExecuted = $this->getMigrationsToExecute($to);
437+
438+
if (empty($toBeExecuted)) {
439+
return;
440+
}
441+
442+
$toSchema = null;
443+
foreach ($toBeExecuted as $version) {
444+
$instance = $this->createInstance($version);
445+
446+
$toSchema = $instance->changeSchema($this->output, function () use ($toSchema) {
447+
return $toSchema ?: new SchemaWrapper($this->connection);
448+
}, ['tablePrefix' => $this->connection->getPrefix()]) ?: $toSchema;
449+
450+
$this->markAsExecuted($version);
451+
}
452+
453+
if ($toSchema instanceof SchemaWrapper) {
454+
$targetSchema = $toSchema->getWrappedSchema();
455+
if ($this->checkOracle) {
456+
$beforeSchema = $this->connection->createSchema();
457+
$this->ensureOracleIdentifierLengthLimit($beforeSchema, $targetSchema, strlen($this->connection->getPrefix()));
458+
}
459+
$this->connection->migrateToSchema($targetSchema);
460+
$toSchema->performDropTableCalls();
461+
}
462+
}
463+
418464
/**
419465
* Get the human readable descriptions for the migration steps to run
420466
*

lib/private/DB/SchemaWrapper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public function hasTable($tableName) {
111111
* @return \Doctrine\DBAL\Schema\Table
112112
*/
113113
public function createTable($tableName) {
114+
unset($this->tablesToDelete[$tableName]);
114115
return $this->schema->createTable($this->connection->getPrefix() . $tableName);
115116
}
116117

lib/private/Installer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function installApp(string $appId, bool $forceEnable = false): string {
158158
}
159159
} else {
160160
$ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection());
161-
$ms->migrate();
161+
$ms->migrate('latest', true);
162162
}
163163
if ($previousVersion) {
164164
OC_App::executeRepairSteps($appId, $info['repair-steps']['post-migration']);
@@ -593,7 +593,7 @@ public static function installShippedApp($app) {
593593
}
594594
} else {
595595
$ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection());
596-
$ms->migrate();
596+
$ms->migrate('latest', true);
597597
}
598598

599599
//run appinfo/install.php

lib/private/Setup/AbstractDatabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,6 @@ public function runMigrations() {
150150
return;
151151
}
152152
$ms = new MigrationService('core', \OC::$server->getDatabaseConnection());
153-
$ms->migrate();
153+
$ms->migrate('latest', true);
154154
}
155155
}

0 commit comments

Comments
 (0)