Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/private/DB/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ public function ensureOracleConstraints(Schema $sourceSchema, Schema $targetSche
if ($isUsingDefaultName && \strlen($table->getName()) - $prefixLength >= 23) {
throw new \InvalidArgumentException('Primary index name on "' . $table->getName() . '" is too long.');
}
} elseif (!$primaryKey instanceof Index) {
throw new \InvalidArgumentException('Table "' . $table->getName() . '" has no primary key and therefor will not behave sane in clustered setups.');
}
}

Expand Down
44 changes: 43 additions & 1 deletion tests/lib/DB/MigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ public function testEnsureOracleConstraintsValid() {
->method('getName')
->willReturn(\str_repeat('a', 30));

$primaryKey = $this->createMock(Index::class);

$table->expects($this->once())
->method('getColumns')
->willReturn([$column]);
Expand All @@ -257,7 +259,7 @@ public function testEnsureOracleConstraintsValid() {
->willReturn([$foreignKey]);
$table->expects($this->once())
->method('getPrimaryKey')
->willReturn(null);
->willReturn($primaryKey);

$schema = $this->createMock(Schema::class);
$schema->expects($this->once())
Expand Down Expand Up @@ -607,6 +609,46 @@ public function testEnsureOracleConstraintsTooLongForeignKeyName() {
}


public function testEnsureOracleConstraintsNoPrimaryKey() {
$this->expectException(\InvalidArgumentException::class);

$table = $this->createMock(Table::class);
$table->expects($this->atLeastOnce())
->method('getName')
->willReturn(\str_repeat('a', 30));
$table->expects($this->once())
->method('getColumns')
->willReturn([]);
$table->expects($this->once())
->method('getIndexes')
->willReturn([]);
$table->expects($this->once())
->method('getForeignKeys')
->willReturn([]);
$table->expects($this->once())
->method('getPrimaryKey')
->willReturn(null);

$schema = $this->createMock(Schema::class);
$schema->expects($this->once())
->method('getTables')
->willReturn([$table]);
$schema->expects($this->once())
->method('getSequences')
->willReturn([]);

$sourceSchema = $this->createMock(Schema::class);
$sourceSchema->expects($this->any())
->method('getTable')
->willThrowException(new SchemaException());
$sourceSchema->expects($this->any())
->method('hasSequence')
->willReturn(false);

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


public function testEnsureOracleConstraintsTooLongSequenceName() {
$this->expectException(\InvalidArgumentException::class);

Expand Down