From 129bae62d42d58166f51d8f7167b00b4761d60c5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 23 Mar 2022 15:04:18 +0100 Subject: [PATCH 1/3] Ensure string column limit of 4.000 characters 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 --- lib/private/DB/MigrationService.php | 4 +++ tests/lib/DB/MigrationsTest.php | 40 +++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index 5e146112120..bc3168bb5a8 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -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) { diff --git a/tests/lib/DB/MigrationsTest.php b/tests/lib/DB/MigrationsTest.php index b00b094b4aa..206fe1a3798 100644 --- a/tests/lib/DB/MigrationsTest.php +++ b/tests/lib/DB/MigrationsTest.php @@ -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]); + } } From 9d2536e49eeaa2c71a10f5c0a2289a614da039b4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 24 Mar 2022 16:59:02 +0100 Subject: [PATCH 2/3] Fix files_external column length Signed-off-by: Joas Schilling --- apps/files_external/appinfo/info.xml | 2 +- .../Version1011Date20200630192246.php | 2 +- .../Version1016Date20220324154536.php | 62 +++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 apps/files_external/lib/Migration/Version1016Date20220324154536.php diff --git a/apps/files_external/appinfo/info.xml b/apps/files_external/appinfo/info.xml index ea8e29c0166..f9b2b8341ce 100644 --- a/apps/files_external/appinfo/info.xml +++ b/apps/files_external/appinfo/info.xml @@ -9,7 +9,7 @@ This application enables administrators to configure connections to external sto External storage can be configured using the GUI or at the command line. This second option provides the advanced user with more flexibility for configuring bulk external storage mounts and setting mount priorities. More information is available in the external storage GUI documentation and the external storage Configuration File documentation. - 1.16.0 + 1.16.1 agpl Robin Appelman Michael Gapczynski diff --git a/apps/files_external/lib/Migration/Version1011Date20200630192246.php b/apps/files_external/lib/Migration/Version1011Date20200630192246.php index 5ec289428fb..c2a53e346f1 100644 --- a/apps/files_external/lib/Migration/Version1011Date20200630192246.php +++ b/apps/files_external/lib/Migration/Version1011Date20200630192246.php @@ -116,7 +116,7 @@ class Version1011Date20200630192246 extends SimpleMigrationStep { ]); $table->addColumn('value', Types::STRING, [ 'notnull' => false, - 'length' => 4096, + 'length' => 4000, ]); $table->setPrimaryKey(['config_id']); $table->addUniqueIndex(['mount_id', 'key'], 'config_mount_key'); diff --git a/apps/files_external/lib/Migration/Version1016Date20220324154536.php b/apps/files_external/lib/Migration/Version1016Date20220324154536.php new file mode 100644 index 00000000000..0f3b5522094 --- /dev/null +++ b/apps/files_external/lib/Migration/Version1016Date20220324154536.php @@ -0,0 +1,62 @@ + + * + * @author Joas Schilling + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCA\Files_External\Migration; + +use Closure; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +class Version1016Date20220324154536 extends SimpleMigrationStep { + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + */ + public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { + // FIXME do we need to check for 4000+ values? + } + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('external_config'); + $column = $table->getColumn('value'); + + if ($column->getLength() > 4000) { + $column->setLength(4000); + } + + return $schema; + } +} From ddfa2f221ec454447f607c5b0fd3034b5f5a2d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 31 Mar 2022 10:19:48 +0200 Subject: [PATCH 3/3] Remove unneeded preSchemaChange and return null if no changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../lib/Migration/Version1016Date20220324154536.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/apps/files_external/lib/Migration/Version1016Date20220324154536.php b/apps/files_external/lib/Migration/Version1016Date20220324154536.php index 0f3b5522094..a2a7ecaff17 100644 --- a/apps/files_external/lib/Migration/Version1016Date20220324154536.php +++ b/apps/files_external/lib/Migration/Version1016Date20220324154536.php @@ -31,15 +31,6 @@ use OCP\Migration\SimpleMigrationStep; class Version1016Date20220324154536 extends SimpleMigrationStep { - /** - * @param IOutput $output - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options - */ - public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { - // FIXME do we need to check for 4000+ values? - } - /** * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` @@ -55,8 +46,9 @@ class Version1016Date20220324154536 extends SimpleMigrationStep { if ($column->getLength() > 4000) { $column->setLength(4000); + return $schema; } - return $schema; + return null; } }