]> source.dussan.org Git - nextcloud-server.git/commitdiff
Ensure string column limit of 4.000 characters
authorJoas Schilling <coding@schilljs.com>
Wed, 23 Mar 2022 14:04:18 +0000 (15:04 +0100)
committerJoas Schilling <coding@schilljs.com>
Fri, 25 Mar 2022 11:44:51 +0000 (12:44 +0100)
https://docs.oracle.com/en/database/oracle/oracle-database/19/refrn/datatype-limits.html#GUID-963C79C9-9303-49FE-8F2D-C8AAF04D3095

Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/DB/MigrationService.php
tests/lib/DB/MigrationsTest.php

index 5e146112120573c21c142afda554e6ac152ad5cf..bc3168bb5a8979365588048e6f9f45245a20a073 100644 (file)
@@ -594,6 +594,10 @@ class MigrationService {
                                if ((!$sourceTable instanceof Table || !$sourceTable->hasColumn($thing->getName())) && $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 ($thing->getLength() > 4000 && $thing->getType()->getName() === Types::STRING) {
+                                       throw new \InvalidArgumentException('Column "' . $table->getName() . '"."' . $thing->getName() . '" is type String, but exceeding the 4.000 length limit.');
+                               }
                        }
 
                        foreach ($table->getIndexes() as $thing) {
index b00b094b4aa1a2a307908f403313c8fae471c9ea..206fe1a3798ff04a940a4e62826d67ecd094fb9d 100644 (file)
@@ -716,4 +716,44 @@ class MigrationsTest extends \Test\TestCase {
 
                self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
        }
+
+
+       public function testEnsureOracleConstraintsStringLength4000() {
+               $this->expectException(\InvalidArgumentException::class);
+
+               $column = $this->createMock(Column::class);
+               $column->expects($this->any())
+                       ->method('getName')
+                       ->willReturn('aaaa');
+               $column->expects($this->any())
+                       ->method('getType')
+                       ->willReturn(Type::getType('string'));
+               $column->expects($this->any())
+                       ->method('getLength')
+                       ->willReturn(4001);
+
+               $table = $this->createMock(Table::class);
+               $table->expects($this->any())
+                       ->method('getName')
+                       ->willReturn(\str_repeat('a', 30));
+
+               $table->expects($this->once())
+                       ->method('getColumns')
+                       ->willReturn([$column]);
+
+               $schema = $this->createMock(Schema::class);
+               $schema->expects($this->once())
+                       ->method('getTables')
+                       ->willReturn([$table]);
+
+               $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]);
+       }
 }