Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2022-04-07 15:52:57 +0300
committerGitHub <noreply@github.com>2022-04-07 15:52:57 +0300
commit8b53b6dc9ef15c37a8c05d4ea2afee28506f0383 (patch)
treedf50f3c1fb18618e2356db2c9c88fdd4ab813181 /lib
parent0e29dc8c76a379b7f34f63303ae831e52bb62801 (diff)
parent82c33be744b1e9d85c780bce277c783c6d38e7bf (diff)
Merge pull request #31872 from nextcloud/fix/oracle-contrainst
Ensure schema change before checking OracleConstraints
Diffstat (limited to 'lib')
-rw-r--r--lib/private/DB/MigrationService.php35
1 files changed, 22 insertions, 13 deletions
diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php
index 046e3a4924b..fb7b6b7472f 100644
--- a/lib/private/DB/MigrationService.php
+++ b/lib/private/DB/MigrationService.php
@@ -27,7 +27,6 @@
*/
namespace OC\DB;
-use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Schema\Index;
@@ -424,10 +423,10 @@ class MigrationService {
foreach ($toBeExecuted as $version) {
try {
$this->executeStep($version, $schemaOnly);
- } catch (DriverException $e) {
+ } catch (\Exception $e) {
// The exception itself does not contain the name of the migration,
// so we wrap it here, to make debugging easier.
- throw new \Exception('Database error when running migration ' . $to . ' for app ' . $this->getApp(), 0, $e);
+ throw new \Exception('Database error when running migration ' . $version . ' for app ' . $this->getApp() . PHP_EOL. $e->getMessage(), 0, $e);
}
}
}
@@ -583,20 +582,30 @@ class MigrationService {
}
foreach ($table->getColumns() as $thing) {
- if ((!$sourceTable instanceof Table || !$sourceTable->hasColumn($thing->getName())) && \strlen($thing->getName()) > 30) {
- throw new \InvalidArgumentException('Column name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.');
- }
+ // If the table doesn't exist OR if the column doesn't exist in the table
+ if (!$sourceTable instanceof Table || !$sourceTable->hasColumn($thing->getName())) {
+ if (\strlen($thing->getName()) > 30) {
+ throw new \InvalidArgumentException('Column name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.');
+ }
- if ((!$sourceTable instanceof Table || !$sourceTable->hasColumn($thing->getName())) && $thing->getNotnull() && $thing->getDefault() === ''
- && $sourceTable instanceof Table && !$sourceTable->hasColumn($thing->getName())) {
- throw new \InvalidArgumentException('Column "' . $table->getName() . '"."' . $thing->getName() . '" is NotNull, but has empty string or null as default.');
- }
+ if ($thing->getNotnull() && $thing->getDefault() === ''
+ && $sourceTable instanceof Table && !$sourceTable->hasColumn($thing->getName())) {
+ throw new \InvalidArgumentException('Column "' . $table->getName() . '"."' . $thing->getName() . '" is NotNull, but has empty string or null as default.');
+ }
+
+ if ($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 ((!$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".');
+ $sourceColumn = null;
+ } else {
+ $sourceColumn = $sourceTable->getColumn($thing->getName());
}
- if ($thing->getLength() > 4000 && $thing->getType()->getName() === Types::STRING) {
+ // If the column was just created OR the length changed OR the type changed
+ // we will NOT detect invalid length if the column is not modified
+ if (($sourceColumn === null || $sourceColumn->getLength() !== $thing->getLength() || $sourceColumn->getType()->getName() !== Types::STRING)
+ && $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.');
}
}