Skip to content

Commit dd357d7

Browse files
authored
Merge pull request #31679 from nextcloud/bugfix/noid/ensure-string-columns-to-be-maximum-of-4000
Ensure string column limit of 4.000 characters
2 parents f548548 + ddfa2f2 commit dd357d7

File tree

5 files changed

+100
-2
lines changed

5 files changed

+100
-2
lines changed

apps/files_external/appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This application enables administrators to configure connections to external sto
99

1010
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.
1111
</description>
12-
<version>1.16.0</version>
12+
<version>1.16.1</version>
1313
<licence>agpl</licence>
1414
<author>Robin Appelman</author>
1515
<author>Michael Gapczynski</author>

apps/files_external/lib/Migration/Version1011Date20200630192246.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
116116
]);
117117
$table->addColumn('value', Types::STRING, [
118118
'notnull' => false,
119-
'length' => 4096,
119+
'length' => 4000,
120120
]);
121121
$table->setPrimaryKey(['config_id']);
122122
$table->addUniqueIndex(['mount_id', 'key'], 'config_mount_key');
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2022 Joas Schilling <[email protected]>
6+
*
7+
* @author Joas Schilling <[email protected]>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
25+
namespace OCA\Files_External\Migration;
26+
27+
use Closure;
28+
use OCP\DB\ISchemaWrapper;
29+
use OCP\Migration\IOutput;
30+
use OCP\Migration\SimpleMigrationStep;
31+
32+
class Version1016Date20220324154536 extends SimpleMigrationStep {
33+
34+
/**
35+
* @param IOutput $output
36+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
37+
* @param array $options
38+
* @return null|ISchemaWrapper
39+
*/
40+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
41+
/** @var ISchemaWrapper $schema */
42+
$schema = $schemaClosure();
43+
44+
$table = $schema->getTable('external_config');
45+
$column = $table->getColumn('value');
46+
47+
if ($column->getLength() > 4000) {
48+
$column->setLength(4000);
49+
return $schema;
50+
}
51+
52+
return null;
53+
}
54+
}

lib/private/DB/MigrationService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,10 @@ public function ensureOracleConstraints(Schema $sourceSchema, Schema $targetSche
595595
if ((!$sourceTable instanceof Table || !$sourceTable->hasColumn($thing->getName())) && $thing->getNotnull() && $thing->getType()->getName() === Types::BOOLEAN) {
596596
throw new \InvalidArgumentException('Column "' . $table->getName() . '"."' . $thing->getName() . '" is type Bool and also NotNull, so it can not store "false".');
597597
}
598+
599+
if ($thing->getLength() > 4000 && $thing->getType()->getName() === Types::STRING) {
600+
throw new \InvalidArgumentException('Column "' . $table->getName() . '"."' . $thing->getName() . '" is type String, but exceeding the 4.000 length limit.');
601+
}
598602
}
599603

600604
foreach ($table->getIndexes() as $thing) {

tests/lib/DB/MigrationsTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,4 +716,44 @@ public function testEnsureOracleConstraintsBooleanNotNull() {
716716

717717
self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
718718
}
719+
720+
721+
public function testEnsureOracleConstraintsStringLength4000() {
722+
$this->expectException(\InvalidArgumentException::class);
723+
724+
$column = $this->createMock(Column::class);
725+
$column->expects($this->any())
726+
->method('getName')
727+
->willReturn('aaaa');
728+
$column->expects($this->any())
729+
->method('getType')
730+
->willReturn(Type::getType('string'));
731+
$column->expects($this->any())
732+
->method('getLength')
733+
->willReturn(4001);
734+
735+
$table = $this->createMock(Table::class);
736+
$table->expects($this->any())
737+
->method('getName')
738+
->willReturn(\str_repeat('a', 30));
739+
740+
$table->expects($this->once())
741+
->method('getColumns')
742+
->willReturn([$column]);
743+
744+
$schema = $this->createMock(Schema::class);
745+
$schema->expects($this->once())
746+
->method('getTables')
747+
->willReturn([$table]);
748+
749+
$sourceSchema = $this->createMock(Schema::class);
750+
$sourceSchema->expects($this->any())
751+
->method('getTable')
752+
->willThrowException(new SchemaException());
753+
$sourceSchema->expects($this->any())
754+
->method('hasSequence')
755+
->willReturn(false);
756+
757+
self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
758+
}
719759
}

0 commit comments

Comments
 (0)