summaryrefslogtreecommitdiffstats
path: root/lib/private/DB
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2018-07-19 10:28:52 +0200
committerJoas Schilling <coding@schilljs.com>2018-07-27 14:45:21 +0200
commit960961148ed2bea4818ca1abf8484ef3bf238f64 (patch)
tree9d498d10a6b4b3bf038b3b468745702df6f20878 /lib/private/DB
parent14682dfa7c1f846e3094b4f6bcd558681b8f5b9f (diff)
downloadnextcloud-server-960961148ed2bea4818ca1abf8484ef3bf238f64.tar.gz
nextcloud-server-960961148ed2bea4818ca1abf8484ef3bf238f64.zip
Fix calculation of default name
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/DB')
-rw-r--r--lib/private/DB/MigrationService.php26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php
index b2ec3c13ba1..99b8575cd97 100644
--- a/lib/private/DB/MigrationService.php
+++ b/lib/private/DB/MigrationService.php
@@ -23,6 +23,10 @@
namespace OC\DB;
+use Doctrine\DBAL\Platforms\OraclePlatform;
+use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
+use Doctrine\DBAL\Schema\Column;
+use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException;
use OC\IntegrityCheck\Helpers\AppLocator;
@@ -490,9 +494,25 @@ class MigrationService {
}
}
- $thing = $table->getPrimaryKey();
- if ($thing && (\strlen($table->getName()) > 26 || \strlen($thing->getName()) > 30)) {
- throw new \InvalidArgumentException('Primary index name on "' . $table->getName() . '" is too long.');
+ $primaryKey = $table->getPrimaryKey();
+ if ($primaryKey instanceof Index) {
+ $indexName = strtolower($primaryKey->getName());
+ $isUsingDefaultName = $indexName === 'primary';
+
+ if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
+ $defaultName = $table->getName() . '_' . implode('_', $primaryKey->getColumns()) . '_seq';
+ $isUsingDefaultName = strtolower($defaultName) === $indexName;
+ } else if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
+ $defaultName = $table->getName() . '_seq';
+ $isUsingDefaultName = strtolower($defaultName) === $indexName;
+ }
+
+ if (!$isUsingDefaultName && \strlen($indexName) > 30) {
+ throw new \InvalidArgumentException('Primary index name on "' . $table->getName() . '" is too long.');
+ }
+ if ($isUsingDefaultName && \strlen($table->getName()) > 26) {
+ throw new \InvalidArgumentException('Primary index name on "' . $table->getName() . '" is too long.');
+ }
}
}