Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,8 @@
'OC\\DB\\Schema\\Index' => $baseDir . '/lib/private/DB/Schema/Index.php',
'OC\\DB\\Schema\\Table' => $baseDir . '/lib/private/DB/Schema/Table.php',
'OC\\DB\\SetTransactionIsolationLevel' => $baseDir . '/lib/private/DB/SetTransactionIsolationLevel.php',
'OC\\DB\\Types\\TimestampImmutableType' => $baseDir . '/lib/private/DB/Types/TimestampImmutableType.php',
'OC\\DB\\Types\\TinyIntType' => $baseDir . '/lib/private/DB/Types/TinyIntType.php',
'OC\\Dashboard\\Manager' => $baseDir . '/lib/private/Dashboard/Manager.php',
'OC\\DatabaseException' => $baseDir . '/lib/private/DatabaseException.php',
'OC\\DatabaseSetupException' => $baseDir . '/lib/private/DatabaseSetupException.php',
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\DB\\Schema\\Index' => __DIR__ . '/../../..' . '/lib/private/DB/Schema/Index.php',
'OC\\DB\\Schema\\Table' => __DIR__ . '/../../..' . '/lib/private/DB/Schema/Table.php',
'OC\\DB\\SetTransactionIsolationLevel' => __DIR__ . '/../../..' . '/lib/private/DB/SetTransactionIsolationLevel.php',
'OC\\DB\\Types\\TimestampImmutableType' => __DIR__ . '/../../..' . '/lib/private/DB/Types/TimestampImmutableType.php',
'OC\\DB\\Types\\TinyIntType' => __DIR__ . '/../../..' . '/lib/private/DB/Types/TinyIntType.php',
'OC\\Dashboard\\Manager' => __DIR__ . '/../../..' . '/lib/private/Dashboard/Manager.php',
'OC\\DatabaseException' => __DIR__ . '/../../..' . '/lib/private/DatabaseException.php',
'OC\\DatabaseSetupException' => __DIR__ . '/../../..' . '/lib/private/DatabaseSetupException.php',
Expand Down
11 changes: 11 additions & 0 deletions lib/private/DB/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;
use OC\App\InfoParser;
use OC\DB\Types\TimestampImmutableType;
use OC\DB\Types\TinyIntType;
use OC\Migration\SimpleOutput;
use OCP\App\IAppManager;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Schema\ColumnType;
use OCP\DB\Schema\SchemaException;
use OCP\DB\Types;
use OCP\IConfig;
Expand Down Expand Up @@ -56,6 +59,14 @@ public function __construct(
$this->output = $output;
}

// Set custom Nextcloud types
if (!Type::hasType(ColumnType::TinyInt->value)) {
Type::addType(ColumnType::TinyInt->value, TinyIntType::class);
}
if (!Type::hasType(ColumnType::TimestampImmutable->value)) {
Type::addType(ColumnType::TimestampImmutable->value, TimestampImmutableType::class);
}

if ($this->appName === 'core') {
$this->migrationsPath = \OC::$SERVERROOT . '/core/Migrations';
$this->migrationsNamespace = 'OC\\Core\\Migrations';
Expand Down
35 changes: 35 additions & 0 deletions lib/private/DB/Types/TimestampImmutableType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC\DB\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Types\DateTimeImmutableType;
use OCP\DB\Schema\ColumnType;
use Override;

class TimestampImmutableType extends DateTimeImmutableType {
#[Override]
public function getName(): string {
return ColumnType::TimestampImmutable->value;
}

#[Override]
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string {
$declaration = parent::getSQLDeclaration($column, $platform);

if ($platform instanceof MySQLPlatform || $platform instanceof MariaDBPlatform) {
$field = $column['notnull'] ?? true ? 'TIMESTAMP' : 'TIMESTAMP NULL';
$declaration = str_replace('DATETIME', $field, $declaration);
}
return $declaration;
}
}
32 changes: 32 additions & 0 deletions lib/private/DB/Types/TinyIntType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC\DB\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Types\SmallIntType;
use OCP\DB\Schema\ColumnType;
use Override;

class TinyIntType extends SmallIntType {
#[Override]
public function getName(): string {
return ColumnType::TinyInt->value;
}

#[Override]
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string {
$declaration = parent::getSQLDeclaration($column, $platform);
return $platform instanceof MySQLPlatform || $platform instanceof MariaDBPlatform
? str_replace('SMALLINT', 'TINYINT', $declaration)
: $declaration;
}
}
12 changes: 4 additions & 8 deletions lib/public/AppFramework/Db/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function fromRow(array $row): static {
}

/**
* @return array<string, Types::*> with attribute and type
* @return array<string, 'bigint'|'binary'|'blob'|'boolean'|'date'|'date_immutable'|'datetime'|'datetime_immutable'|'datetimetz'|'datetimetz_immutable'|'decimal'|'float'|'guid'|'integer'|'json'|'smallint'|'string'|'text'|'time'|'time_immutable'|'timestamp_immutable'|'tinyint'> with attribute and type
* @since 7.0.0
*/
public function getFieldTypes(): array {
Expand Down Expand Up @@ -143,7 +143,6 @@ protected function setter(string $name, array $args): void {
}
}
$this->$name = $args[0];

}

/**
Expand All @@ -155,8 +154,7 @@ protected function getter(string $name): mixed {
if (property_exists($this, $name)) {
return $this->$name;
} else {
throw new \BadFunctionCallException($name
. ' is not a valid attribute');
throw new \BadFunctionCallException($name . ' is not a valid attribute');
}
}

Expand All @@ -175,8 +173,7 @@ public function __call(string $methodName, array $args) {
} elseif ($this->isGetterForBoolProperty($methodName)) {
return $this->getter(lcfirst(substr($methodName, 2)));
} else {
throw new \BadFunctionCallException($methodName
. ' does not exist');
throw new \BadFunctionCallException($methodName . ' does not exist');
}
}

Expand Down Expand Up @@ -272,8 +269,7 @@ protected function addType(string $fieldName, string|ColumnType $type): void {
'int' => ColumnType::Integer,
'bool' => ColumnType::Boolean,
'double' => ColumnType::Float,
'array',
'object' => ColumnType::String,
'array', 'object' => ColumnType::String,
};
}

Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/ORM/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ private function hydrateRow(string $entityClass, mixed $row): object {

/** @psalm-suppress MixedAssignment $value is a raw DB driver value; each branch below settype()s or reconstructs it. */
$value = match ($type) {
ColumnType::Bigint, ColumnType::Smallint, ColumnType::Integer => (int)$value,
ColumnType::Bigint, ColumnType::Smallint, ColumnType::Integer, ColumnType::TinyInt => (int)$value,
ColumnType::Float => (float)$value,
ColumnType::Boolean => (bool)$value,
ColumnType::Binary, ColumnType::Decimal, ColumnType::Guid, ColumnType::Text, ColumnType::String => (string)$value,
ColumnType::Time, ColumnType::Date, ColumnType::Datetime, ColumnType::DatetimeTz => $value instanceof \DateTime
? $value
: new \DateTime((string)$value),
ColumnType::TimeImmutable, ColumnType::DateImmutable, ColumnType::DatetimeImmutable, ColumnType::DatetimeTzImmutable => $value instanceof \DateTimeImmutable
ColumnType::TimeImmutable, ColumnType::DateImmutable, ColumnType::DatetimeImmutable, ColumnType::DatetimeTzImmutable, ColumnType::TimestampImmutable => $value instanceof \DateTimeImmutable
? $value
: new \DateTimeImmutable((string)$value),
ColumnType::Json => is_array($value) ? $value : json_decode((string)$value, true),
Expand Down
16 changes: 16 additions & 0 deletions lib/public/DB/Schema/ColumnType.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,22 @@ enum ColumnType: string {
*/
case Guid = 'guid';

/**
* Tiny int
* It is recommended for small values like status
*
* @since 36.0.0
*/
case TinyInt = 'tinyint';

/**
* Unix timestamp returned as DateTimeImmutable
* It is recommended for dates that fits into a timestamp
*
* @since 36.0.0
*/
case TimestampImmutable = 'timestamp_immutable';

/**
* @since 35.0.0
*/
Expand Down
Loading