Only check changed items

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2018-08-06 18:25:09 +02:00
parent e7950a5bd6
commit f265657bc6
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
1 changed files with 18 additions and 13 deletions

View File

@ -25,11 +25,11 @@ namespace OC\DB;
use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use OC\IntegrityCheck\Helpers\AppLocator; use OC\IntegrityCheck\Helpers\AppLocator;
use OC\Migration\SimpleOutput; use OC\Migration\SimpleOutput;
use OCP\AppFramework\App; use OCP\AppFramework\App;
@ -456,9 +456,9 @@ class MigrationService {
}, ['tablePrefix' => $this->connection->getPrefix()]); }, ['tablePrefix' => $this->connection->getPrefix()]);
if ($toSchema instanceof SchemaWrapper) { if ($toSchema instanceof SchemaWrapper) {
$sourceSchema = $this->connection->createSchema();
$targetSchema = $toSchema->getWrappedSchema(); $targetSchema = $toSchema->getWrappedSchema();
// TODO re-enable once stable14 is branched of: https://github.com/nextcloud/server/issues/10518 $this->ensureOracleIdentifierLengthLimit($sourceSchema, $targetSchema, strlen($this->connection->getPrefix()));
// $this->ensureOracleIdentifierLengthLimit($targetSchema, strlen($this->connection->getPrefix()));
$this->connection->migrateToSchema($targetSchema); $this->connection->migrateToSchema($targetSchema);
$toSchema->performDropTableCalls(); $toSchema->performDropTableCalls();
} }
@ -472,34 +472,39 @@ class MigrationService {
$this->markAsExecuted($version); $this->markAsExecuted($version);
} }
public function ensureOracleIdentifierLengthLimit(Schema $schema, int $prefixLength) { public function ensureOracleIdentifierLengthLimit(Schema $sourceSchema, Schema $targetSchema, int $prefixLength) {
$sequences = $schema->getSequences(); $sequences = $targetSchema->getSequences();
foreach ($schema->getTables() as $table) { foreach ($targetSchema->getTables() as $table) {
if (\strlen($table->getName()) - $prefixLength > 27) { try {
throw new \InvalidArgumentException('Table name "' . $table->getName() . '" is too long.'); $sourceTable = $sourceSchema->getTable($table->getName());
} catch (SchemaException $e) {
if (\strlen($table->getName()) - $prefixLength > 27) {
throw new \InvalidArgumentException('Table name "' . $table->getName() . '" is too long.');
}
$sourceTable = null;
} }
foreach ($table->getColumns() as $thing) { foreach ($table->getColumns() as $thing) {
if (\strlen($thing->getName()) - $prefixLength > 27) { if ((!$sourceTable instanceof Table || !$sourceTable->hasColumn($thing->getName())) && \strlen($thing->getName()) - $prefixLength > 27) {
throw new \InvalidArgumentException('Column name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.'); throw new \InvalidArgumentException('Column name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.');
} }
} }
foreach ($table->getIndexes() as $thing) { foreach ($table->getIndexes() as $thing) {
if (\strlen($thing->getName()) - $prefixLength > 27) { if ((!$sourceTable instanceof Table || !$sourceTable->hasIndex($thing->getName())) && \strlen($thing->getName()) - $prefixLength > 27) {
throw new \InvalidArgumentException('Index name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.'); throw new \InvalidArgumentException('Index name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.');
} }
} }
foreach ($table->getForeignKeys() as $thing) { foreach ($table->getForeignKeys() as $thing) {
if (\strlen($thing->getName()) - $prefixLength > 27) { if ((!$sourceTable instanceof Table || !$sourceTable->hasForeignKey($thing->getName())) && \strlen($thing->getName()) - $prefixLength > 27) {
throw new \InvalidArgumentException('Foreign key name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.'); throw new \InvalidArgumentException('Foreign key name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.');
} }
} }
$primaryKey = $table->getPrimaryKey(); $primaryKey = $table->getPrimaryKey();
if ($primaryKey instanceof Index) { if ($primaryKey instanceof Index && (!$sourceTable instanceof Table || !$sourceTable->hasPrimaryKey())) {
$indexName = strtolower($primaryKey->getName()); $indexName = strtolower($primaryKey->getName());
$isUsingDefaultName = $indexName === 'primary'; $isUsingDefaultName = $indexName === 'primary';
@ -528,7 +533,7 @@ class MigrationService {
} }
foreach ($sequences as $sequence) { foreach ($sequences as $sequence) {
if (\strlen($sequence->getName()) - $prefixLength > 27) { if (!$sourceSchema->hasSequence($sequence->getName()) && \strlen($sequence->getName()) - $prefixLength > 27) {
throw new \InvalidArgumentException('Sequence name "' . $sequence->getName() . '" is too long.'); throw new \InvalidArgumentException('Sequence name "' . $sequence->getName() . '" is too long.');
} }
} }