From e88bad4b0a02dbbd5d77518d3b73ff870a1cef95 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 14 Apr 2021 14:11:06 +0200 Subject: [PATCH 1/3] Run migrator tests on OCI Signed-off-by: Joas Schilling --- tests/lib/DB/MigratorTest.php | 36 ++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php index 1d2afaa405..b2d1f13631 100644 --- a/tests/lib/DB/MigratorTest.php +++ b/tests/lib/DB/MigratorTest.php @@ -10,6 +10,7 @@ namespace Test\DB; use Doctrine\DBAL\Exception; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\MySQLPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; @@ -21,6 +22,7 @@ use OC\DB\MySQLMigrator; use OC\DB\OracleMigrator; use OC\DB\PostgreSqlMigrator; use OC\DB\SQLiteMigrator; +use OCP\DB\Types; use OCP\IConfig; /** @@ -52,9 +54,6 @@ class MigratorTest extends \Test\TestCase { $this->config = \OC::$server->getConfig(); $this->connection = \OC::$server->get(\OC\DB\Connection::class); - if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { - $this->markTestSkipped('DB migration tests are not supported on OCI'); - } $this->tableName = $this->getUniqueTableName(); $this->tableNameTmp = $this->getUniqueTableName(); @@ -257,4 +256,35 @@ class MigratorTest extends \Test\TestCase { $this->assertTrue($startSchema->getTable($this->tableNameTmp)->hasForeignKey($fkName)); } + + public function testNotNullBoolean() { + $startSchema = new Schema([], [], $this->getSchemaConfig()); + $table = $startSchema->createTable($this->tableName); + $table->addColumn('id', Types::BIGINT); + $table->addColumn('will_it_blend', Types::BOOLEAN, [ + 'notnull' => true, + ]); + $table->addIndex(['id'], $this->tableName . '_id'); + + $migrator = $this->getMigrator(); + $migrator->migrate($startSchema); + + $this->connection->insert( + $this->tableName, + ['id' => 1, 'will_it_blend' => true], + ['id' => ParameterType::INTEGER, 'will_it_blend' => ParameterType::BOOLEAN], + ); + $this->connection->insert( + $this->tableName, + ['id' => 2, 'will_it_blend' => false], + ['id' => ParameterType::INTEGER, 'will_it_blend' => ParameterType::BOOLEAN], + ); + $this->connection->insert( + $this->tableName, + ['id' => 3, 'will_it_blend' => true], + ['id' => ParameterType::INTEGER, 'will_it_blend' => ParameterType::BOOLEAN], + ); + + $this->addToAssertionCount(1); + } } From 8b4ecdcc88c0f14217fa6c64380646bda6f774cd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 14 Apr 2021 14:53:16 +0200 Subject: [PATCH 2/3] Test that oracle throws on EmptyValues in a NotNull columns Signed-off-by: Joas Schilling --- tests/lib/DB/MigratorTest.php | 42 +++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php index b2d1f13631..75c1243bf8 100644 --- a/tests/lib/DB/MigratorTest.php +++ b/tests/lib/DB/MigratorTest.php @@ -257,11 +257,30 @@ class MigratorTest extends \Test\TestCase { $this->assertTrue($startSchema->getTable($this->tableNameTmp)->hasForeignKey($fkName)); } - public function testNotNullBoolean() { + public function dataNotNullEmptyValuesFailOracle(): array { + return [ + [ParameterType::BOOLEAN, true, Types::BOOLEAN, false], + [ParameterType::BOOLEAN, false, Types::BOOLEAN, true], + [ParameterType::STRING, 'foo', Types::STRING, false], + [ParameterType::STRING, '', Types::STRING, true], + [ParameterType::INTEGER, 1234, Types::INTEGER, false], + [ParameterType::INTEGER, 0, Types::INTEGER, true], + ]; + } + + /** + * @dataProvider dataNotNullEmptyValuesFailOracle + * + * @param int $parameterType + * @param bool|int|string $value + * @param string $columnType + * @param bool $oracleThrows + */ + public function testNotNullEmptyValuesFailOracle(int $parameterType, $value, string $columnType, bool $oracleThrows): void { $startSchema = new Schema([], [], $this->getSchemaConfig()); $table = $startSchema->createTable($this->tableName); $table->addColumn('id', Types::BIGINT); - $table->addColumn('will_it_blend', Types::BOOLEAN, [ + $table->addColumn('will_it_blend', $columnType, [ 'notnull' => true, ]); $table->addIndex(['id'], $this->tableName . '_id'); @@ -269,20 +288,15 @@ class MigratorTest extends \Test\TestCase { $migrator = $this->getMigrator(); $migrator->migrate($startSchema); + if ($oracleThrows && $this->connection->getDatabasePlatform() instanceof OraclePlatform) { + // Oracle can not store false|empty string in notnull columns + $this->expectException(\Doctrine\DBAL\Exception\NotNullConstraintViolationException::class); + } + $this->connection->insert( $this->tableName, - ['id' => 1, 'will_it_blend' => true], - ['id' => ParameterType::INTEGER, 'will_it_blend' => ParameterType::BOOLEAN], - ); - $this->connection->insert( - $this->tableName, - ['id' => 2, 'will_it_blend' => false], - ['id' => ParameterType::INTEGER, 'will_it_blend' => ParameterType::BOOLEAN], - ); - $this->connection->insert( - $this->tableName, - ['id' => 3, 'will_it_blend' => true], - ['id' => ParameterType::INTEGER, 'will_it_blend' => ParameterType::BOOLEAN], + ['id' => 1, 'will_it_blend' => $value], + ['id' => ParameterType::INTEGER, 'will_it_blend' => $parameterType], ); $this->addToAssertionCount(1); From 1670d004529e5e17e0028394c4696baee21e2a53 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Apr 2021 09:53:11 +0200 Subject: [PATCH 3/3] Integer 0 is not stored as Null and therefor works Signed-off-by: Joas Schilling --- tests/lib/DB/MigratorTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php index 75c1243bf8..114cf03d7b 100644 --- a/tests/lib/DB/MigratorTest.php +++ b/tests/lib/DB/MigratorTest.php @@ -261,10 +261,12 @@ class MigratorTest extends \Test\TestCase { return [ [ParameterType::BOOLEAN, true, Types::BOOLEAN, false], [ParameterType::BOOLEAN, false, Types::BOOLEAN, true], + [ParameterType::STRING, 'foo', Types::STRING, false], [ParameterType::STRING, '', Types::STRING, true], + [ParameterType::INTEGER, 1234, Types::INTEGER, false], - [ParameterType::INTEGER, 0, Types::INTEGER, true], + [ParameterType::INTEGER, 0, Types::INTEGER, false], // Integer 0 is not stored as Null and therefor works ]; }