Ignore custom prefixes which are longer
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
5e0bfe5c16
commit
008c8dde1a
|
@ -457,7 +457,7 @@ class MigrationService {
|
|||
|
||||
if ($toSchema instanceof SchemaWrapper) {
|
||||
$targetSchema = $toSchema->getWrappedSchema();
|
||||
$this->ensureOracleIdentifierLengthLimit($targetSchema);
|
||||
$this->ensureOracleIdentifierLengthLimit($targetSchema, strlen($this->connection->getPrefix()));
|
||||
$this->connection->migrateToSchema($targetSchema);
|
||||
$toSchema->performDropTableCalls();
|
||||
}
|
||||
|
@ -471,28 +471,28 @@ class MigrationService {
|
|||
$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.');
|
||||
}
|
||||
}
|
||||
|
@ -516,17 +516,17 @@ class MigrationService {
|
|||
$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.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ class MigrationsTest extends \Test\TestCase {
|
|||
->method('getSequences')
|
||||
->willReturn([$sequence]);
|
||||
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
|
||||
}
|
||||
|
||||
public function testEnsureOracleIdentifierLengthLimitValidWithPrimaryKey() {
|
||||
|
@ -303,7 +303,7 @@ class MigrationsTest extends \Test\TestCase {
|
|||
->method('getSequences')
|
||||
->willReturn([]);
|
||||
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
|
||||
}
|
||||
|
||||
public function testEnsureOracleIdentifierLengthLimitValidWithPrimaryKeyDefault() {
|
||||
|
@ -348,7 +348,7 @@ class MigrationsTest extends \Test\TestCase {
|
|||
->method('getSequences')
|
||||
->willReturn([]);
|
||||
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -365,7 +365,7 @@ class MigrationsTest extends \Test\TestCase {
|
|||
->method('getTables')
|
||||
->willReturn([$table]);
|
||||
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -410,7 +410,7 @@ class MigrationsTest extends \Test\TestCase {
|
|||
->method('getTables')
|
||||
->willReturn([$table]);
|
||||
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -445,7 +445,7 @@ class MigrationsTest extends \Test\TestCase {
|
|||
->method('getTables')
|
||||
->willReturn([$table]);
|
||||
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -471,7 +471,7 @@ class MigrationsTest extends \Test\TestCase {
|
|||
->method('getTables')
|
||||
->willReturn([$table]);
|
||||
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -500,7 +500,7 @@ class MigrationsTest extends \Test\TestCase {
|
|||
->method('getTables')
|
||||
->willReturn([$table]);
|
||||
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -532,7 +532,7 @@ class MigrationsTest extends \Test\TestCase {
|
|||
->method('getTables')
|
||||
->willReturn([$table]);
|
||||
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -552,6 +552,6 @@ class MigrationsTest extends \Test\TestCase {
|
|||
->method('getSequences')
|
||||
->willReturn([$sequence]);
|
||||
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
|
||||
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue