Skip to content

Commit

Permalink
Ignore custom prefixes which are longer
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 27, 2018
1 parent 5e0bfe5 commit 008c8dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
18 changes: 9 additions & 9 deletions lib/private/DB/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public function executeStep($version, $schemaOnly = false) {

if ($toSchema instanceof SchemaWrapper) {
$targetSchema = $toSchema->getWrappedSchema();
$this->ensureOracleIdentifierLengthLimit($targetSchema);
$this->ensureOracleIdentifierLengthLimit($targetSchema, strlen($this->connection->getPrefix()));
$this->connection->migrateToSchema($targetSchema);
$toSchema->performDropTableCalls();
}
Expand All @@ -471,28 +471,28 @@ public function executeStep($version, $schemaOnly = false) {
$this->markAsExecuted($version);
}

public function ensureOracleIdentifierLengthLimit(Schema $schema) {
public function ensureOracleIdentifierLengthLimit(Schema $schema, int $prefixLength) {
$sequences = $schema->getSequences();

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

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

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

foreach ($table->getForeignKeys() as $thing) {
if (\strlen($thing->getName()) > 30) {
if (\strlen($thing->getName()) - $prefixLength > 27) {
throw new \InvalidArgumentException('Foreign key name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.');
}
}
Expand All @@ -516,17 +516,17 @@ public function ensureOracleIdentifierLengthLimit(Schema $schema) {
$isUsingDefaultName = strtolower($defaultName) === $indexName;
}

if (!$isUsingDefaultName && \strlen($indexName) > 30) {
if (!$isUsingDefaultName && \strlen($indexName) - $prefixLength > 27) {
throw new \InvalidArgumentException('Primary index name on "' . $table->getName() . '" is too long.');
}
if ($isUsingDefaultName && \strlen($table->getName()) > 26) {
if ($isUsingDefaultName && \strlen($table->getName()) - $prefixLength > 23) {
throw new \InvalidArgumentException('Primary index name on "' . $table->getName() . '" is too long.');
}
}
}

foreach ($sequences as $sequence) {
if (\strlen($sequence->getName()) > 30) {
if (\strlen($sequence->getName()) - $prefixLength > 27) {
throw new \InvalidArgumentException('Sequence name "' . $sequence->getName() . '" is too long.');
}
}
Expand Down
20 changes: 10 additions & 10 deletions tests/lib/DB/MigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function testEnsureOracleIdentifierLengthLimitValid() {
->method('getSequences')
->willReturn([$sequence]);

self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
}

public function testEnsureOracleIdentifierLengthLimitValidWithPrimaryKey() {
Expand Down Expand Up @@ -303,7 +303,7 @@ public function testEnsureOracleIdentifierLengthLimitValidWithPrimaryKey() {
->method('getSequences')
->willReturn([]);

self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
}

public function testEnsureOracleIdentifierLengthLimitValidWithPrimaryKeyDefault() {
Expand Down Expand Up @@ -348,7 +348,7 @@ public function testEnsureOracleIdentifierLengthLimitValidWithPrimaryKeyDefault(
->method('getSequences')
->willReturn([]);

self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
}

/**
Expand All @@ -365,7 +365,7 @@ public function testEnsureOracleIdentifierLengthLimitTooLongTableName() {
->method('getTables')
->willReturn([$table]);

self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
}

/**
Expand Down Expand Up @@ -410,7 +410,7 @@ public function testEnsureOracleIdentifierLengthLimitTooLongPrimaryWithDefault()
->method('getTables')
->willReturn([$table]);

self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
}

/**
Expand Down Expand Up @@ -445,7 +445,7 @@ public function testEnsureOracleIdentifierLengthLimitTooLongPrimaryWithName() {
->method('getTables')
->willReturn([$table]);

self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
}

/**
Expand All @@ -471,7 +471,7 @@ public function testEnsureOracleIdentifierLengthLimitTooLongColumnName() {
->method('getTables')
->willReturn([$table]);

self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
}

/**
Expand Down Expand Up @@ -500,7 +500,7 @@ public function testEnsureOracleIdentifierLengthLimitTooLongIndexName() {
->method('getTables')
->willReturn([$table]);

self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
}

/**
Expand Down Expand Up @@ -532,7 +532,7 @@ public function testEnsureOracleIdentifierLengthLimitTooLongForeignKeyName() {
->method('getTables')
->willReturn([$table]);

self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
}

/**
Expand All @@ -552,6 +552,6 @@ public function testEnsureOracleIdentifierLengthLimitTooLongSequenceName() {
->method('getSequences')
->willReturn([$sequence]);

self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
}
}

0 comments on commit 008c8dd

Please sign in to comment.