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
6 changes: 6 additions & 0 deletions core/Command/Db/Migrations/ExecuteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

namespace OC\Core\Command\Db\Migrations;

use Doctrine\DBAL\Types\Type;
use OC\DB\Connection;
use OC\DB\MigrationService;
use OC\DB\Types\TimestampImmutableType;
use OC\DB\Types\TinyIntType;
use OC\Migration\ConsoleOutput;
use OCP\App\IAppManager;
use OCP\DB\Types;
use OCP\IConfig;
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
Expand All @@ -27,6 +31,8 @@ public function __construct(
private IAppManager $appManager,
) {
parent::__construct();
Type::addType(Types::TINYINT, TinyIntType::class);
Type::addType(Types::TIMESTAMP_IMMUTABLE, TimestampImmutableType::class);
}

#[\Override]
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,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 @@ -1880,6 +1880,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
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\Types;
use Override;

class TimestampImmutableType extends DateTimeImmutableType {
#[Override]
public function getName(): string {
return Types::TIMESTAMP_IMMUTABLE;
}

#[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\Types;
use Override;

class TinyIntType extends SmallIntType {
#[Override]
public function getName(): string {
return Types::TINYINT;
}

#[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;
}
}
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
17 changes: 17 additions & 0 deletions lib/public/DB/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,21 @@ final class Types {
* @since 35.0.0
*/
public const GUID = 'guid';

/**
* 1 byte int (0 to 255 when unsigned, -126 to 127 otherwise)
* Fallback on smallint when not supported by the database.
*
* @since 36.0.0
*/
public const TINYINT = 'tinyint';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ihmo we should deprecate this whole class and not add more stuff

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? You think we should rely on DBAL types instead?


/**
* Unix timestamp returned as DateTimeImmutable
* Fallback on datetime_immutable when not supported by the database.
*
* @see self::DATETIME_IMMUTABLE
* @since 36.0.0
*/
public const TIMESTAMP_IMMUTABLE = 'timestamp_immutable';
}
Loading