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
8 changes: 6 additions & 2 deletions lib/private/DB/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace OC\DB;

use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException;
Expand Down Expand Up @@ -576,8 +577,11 @@ public function ensureOracleConstraints(Schema $sourceSchema, Schema $targetSche
throw new \InvalidArgumentException('Column "' . $table->getName() . '"."' . $thing->getName() . '" is NotNull, but has empty string or null as default.');
}

if ($thing->getNotnull() && $thing->getType()->getName() === Types::BOOLEAN) {
throw new \InvalidArgumentException('Column "' . $table->getName() . '"."' . $thing->getName() . '" is type Bool and also NotNull, so it can not store "false".');
if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
// Oracle doesn't support boolean column with non-null value
if ($thing->getNotnull() && $thing->getType()->getName() === Types::BOOLEAN) {
$thing->setNotnull(false);
}
}

$sourceColumn = null;
Expand Down
18 changes: 16 additions & 2 deletions tests/lib/DB/MigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Test\DB;

use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index;
Expand All @@ -34,6 +35,7 @@
use OCP\Migration\Attributes\ModifyColumn;
use OCP\Migration\IMigrationStep;
use OCP\Server;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\MockObject\MockObject;

/**
Expand Down Expand Up @@ -703,8 +705,11 @@ public function testEnsureOracleConstraintsTooLongSequenceName(): void {
}


public function testEnsureOracleConstraintsBooleanNotNull(): void {
$this->expectException(\InvalidArgumentException::class);
#[TestWith([true])]
#[TestWith([false])]
public function testEnsureOracleConstraintsBooleanNotNull(bool $isOracle): void {
$this->db->method('getDatabasePlatform')
->willReturn($isOracle ? $this->createMock(OraclePlatform::class) : null);

$column = $this->createMock(Column::class);
$column->expects($this->any())
Expand Down Expand Up @@ -739,6 +744,15 @@ public function testEnsureOracleConstraintsBooleanNotNull(): void {
->method('hasSequence')
->willReturn(false);

if ($isOracle) {
$column->expects($this->once())
->method('setNotnull')
->with(false);
} else {
$column->expects($this->never())
->method('setNotnull');
}

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

Expand Down
Loading