Skip to content

Commit

Permalink
Prevent too long identifier names
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jul 13, 2018
1 parent f2b92c4 commit 5a9d517
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion 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\Schema;
use Doctrine\DBAL\Schema\SchemaException;
use OC\IntegrityCheck\Helpers\AppLocator;
use OC\Migration\SimpleOutput;
Expand Down Expand Up @@ -446,7 +447,9 @@ public function executeStep($version) {
}, ['tablePrefix' => $this->connection->getPrefix()]);

if ($toSchema instanceof SchemaWrapper) {
$this->connection->migrateToSchema($toSchema->getWrappedSchema());
$targetSchema = $toSchema->getWrappedSchema();
$this->ensureOracleIdentifierLengthLimit($targetSchema);
$this->connection->migrateToSchema($targetSchema);
$toSchema->performDropTableCalls();
}

Expand All @@ -457,6 +460,43 @@ public function executeStep($version) {
$this->markAsExecuted($version);
}

public function ensureOracleIdentifierLengthLimit(Schema $schema) {
foreach ($schema->getTables() as $table) {
if (\strlen($table->getName()) > 30) {
throw new \InvalidArgumentException('Table name "' . $table->getName() . '" is too long.');
}

foreach ($table->getColumns() as $thing) {
if (\strlen($thing->getName()) > 30) {
throw new \InvalidArgumentException('Column name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.');
}
}

foreach ($table->getIndexes() as $thing) {
if (\strlen($thing->getName()) > 30) {
throw new \InvalidArgumentException('Index name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.');
}
}

foreach ($table->getForeignKeys() as $thing) {
if (\strlen($thing->getName()) > 30) {
throw new \InvalidArgumentException('Foreign key name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.');
}
}

$thing = $table->getPrimaryKey();
if ($thing && (\strlen($table->getName()) > 26 || \strlen($thing->getName()) > 30)) {
throw new \InvalidArgumentException('Primary index name on "' . $table->getName() . '" is too long.');
}
}

foreach ($schema->getSequences() as $sequence) {
if (\strlen($sequence->getName()) > 30) {
throw new \InvalidArgumentException('Sequence name "' . $sequence->getName() . '" is too long.');
}
}
}

private function ensureMigrationsAreLoaded() {
if (empty($this->migrations)) {
$this->migrations = $this->findMigrations();
Expand Down

0 comments on commit 5a9d517

Please sign in to comment.