From 723db4b4a3f5b80f72eccefc515ac2e61885c8ab Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 11 Aug 2026 11:26:24 +0200 Subject: [PATCH 1/2] feat(dbal): Add missing stuff in DBAL wrapper Signed-off-by: Carl Schwan --- .../Version1034Date20250605132605.php | 1 + lib/composer/composer/autoload_classmap.php | 3 + lib/composer/composer/autoload_static.php | 3 + lib/private/DB/Schema/Column.php | 12 +- .../DB/Schema/ForeignKeyConstraint.php | 30 ++++ lib/private/DB/Schema/Index.php | 5 + lib/private/DB/Schema/Table.php | 33 +++- lib/public/AppFramework/Db/Entity.php | 60 ++++--- lib/public/DB/Schema/ColumnType.php | 166 ++++++++++++++++++ lib/public/DB/Schema/IColumn.php | 12 +- .../DB/Schema/IForeignKeyConstraint.php | 26 +++ lib/public/DB/Schema/IIndex.php | 8 + lib/public/DB/Schema/ITable.php | 57 +++--- 13 files changed, 362 insertions(+), 54 deletions(-) create mode 100644 lib/private/DB/Schema/ForeignKeyConstraint.php create mode 100644 lib/public/DB/Schema/ColumnType.php create mode 100644 lib/public/DB/Schema/IForeignKeyConstraint.php diff --git a/apps/dav/lib/Migration/Version1034Date20250605132605.php b/apps/dav/lib/Migration/Version1034Date20250605132605.php index 9bb7f4fe71873..930968a39c708 100644 --- a/apps/dav/lib/Migration/Version1034Date20250605132605.php +++ b/apps/dav/lib/Migration/Version1034Date20250605132605.php @@ -60,6 +60,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt 'notnull' => true, 'length' => 255, ]); + /** @psalm-suppress InvalidArgument legacy column */ $federatedCalendarsTable->addColumn('remote_Url', Types::STRING, [ 'notnull' => true, 'length' => 255, diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 8e2cdfc266db6..f556057caaa7c 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -372,7 +372,9 @@ 'OCP\\DB\\QueryBuilder\\IQueryFunction' => $baseDir . '/lib/public/DB/QueryBuilder/IQueryFunction.php', 'OCP\\DB\\QueryBuilder\\ITypedQueryBuilder' => $baseDir . '/lib/public/DB/QueryBuilder/ITypedQueryBuilder.php', 'OCP\\DB\\QueryBuilder\\Sharded\\IShardMapper' => $baseDir . '/lib/public/DB/QueryBuilder/Sharded/IShardMapper.php', + 'OCP\\DB\\Schema\\ColumnType' => $baseDir . '/lib/public/DB/Schema/ColumnType.php', 'OCP\\DB\\Schema\\IColumn' => $baseDir . '/lib/public/DB/Schema/IColumn.php', + 'OCP\\DB\\Schema\\IForeignKeyConstraint' => $baseDir . '/lib/public/DB/Schema/IForeignKeyConstraint.php', 'OCP\\DB\\Schema\\IIndex' => $baseDir . '/lib/public/DB/Schema/IIndex.php', 'OCP\\DB\\Schema\\ITable' => $baseDir . '/lib/public/DB/Schema/ITable.php', 'OCP\\DB\\Schema\\IType' => $baseDir . '/lib/public/DB/Schema/IType.php', @@ -1785,6 +1787,7 @@ 'OC\\DB\\SQLiteSessionInit' => $baseDir . '/lib/private/DB/SQLiteSessionInit.php', 'OC\\DB\\SchemaWrapper' => $baseDir . '/lib/private/DB/SchemaWrapper.php', 'OC\\DB\\Schema\\Column' => $baseDir . '/lib/private/DB/Schema/Column.php', + 'OC\\DB\\Schema\\ForeignKeyConstraint' => $baseDir . '/lib/private/DB/Schema/ForeignKeyConstraint.php', 'OC\\DB\\Schema\\Index' => $baseDir . '/lib/private/DB/Schema/Index.php', 'OC\\DB\\Schema\\Table' => $baseDir . '/lib/private/DB/Schema/Table.php', 'OC\\DB\\Schema\\Type' => $baseDir . '/lib/private/DB/Schema/Type.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 5ae915263d482..875ff36b5840e 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -413,7 +413,9 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\DB\\QueryBuilder\\IQueryFunction' => __DIR__ . '/../../..' . '/lib/public/DB/QueryBuilder/IQueryFunction.php', 'OCP\\DB\\QueryBuilder\\ITypedQueryBuilder' => __DIR__ . '/../../..' . '/lib/public/DB/QueryBuilder/ITypedQueryBuilder.php', 'OCP\\DB\\QueryBuilder\\Sharded\\IShardMapper' => __DIR__ . '/../../..' . '/lib/public/DB/QueryBuilder/Sharded/IShardMapper.php', + 'OCP\\DB\\Schema\\ColumnType' => __DIR__ . '/../../..' . '/lib/public/DB/Schema/ColumnType.php', 'OCP\\DB\\Schema\\IColumn' => __DIR__ . '/../../..' . '/lib/public/DB/Schema/IColumn.php', + 'OCP\\DB\\Schema\\IForeignKeyConstraint' => __DIR__ . '/../../..' . '/lib/public/DB/Schema/IForeignKeyConstraint.php', 'OCP\\DB\\Schema\\IIndex' => __DIR__ . '/../../..' . '/lib/public/DB/Schema/IIndex.php', 'OCP\\DB\\Schema\\ITable' => __DIR__ . '/../../..' . '/lib/public/DB/Schema/ITable.php', 'OCP\\DB\\Schema\\IType' => __DIR__ . '/../../..' . '/lib/public/DB/Schema/IType.php', @@ -1826,6 +1828,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\DB\\SQLiteSessionInit' => __DIR__ . '/../../..' . '/lib/private/DB/SQLiteSessionInit.php', 'OC\\DB\\SchemaWrapper' => __DIR__ . '/../../..' . '/lib/private/DB/SchemaWrapper.php', 'OC\\DB\\Schema\\Column' => __DIR__ . '/../../..' . '/lib/private/DB/Schema/Column.php', + 'OC\\DB\\Schema\\ForeignKeyConstraint' => __DIR__ . '/../../..' . '/lib/private/DB/Schema/ForeignKeyConstraint.php', 'OC\\DB\\Schema\\Index' => __DIR__ . '/../../..' . '/lib/private/DB/Schema/Index.php', 'OC\\DB\\Schema\\Table' => __DIR__ . '/../../..' . '/lib/private/DB/Schema/Table.php', 'OC\\DB\\Schema\\Type' => __DIR__ . '/../../..' . '/lib/private/DB/Schema/Type.php', diff --git a/lib/private/DB/Schema/Column.php b/lib/private/DB/Schema/Column.php index 1d9a126240615..daea23545da69 100644 --- a/lib/private/DB/Schema/Column.php +++ b/lib/private/DB/Schema/Column.php @@ -12,6 +12,7 @@ use Doctrine\DBAL\Schema\Column as DBALColumn; use Doctrine\DBAL\Schema\SchemaException as DBALSchemaException; use Doctrine\DBAL\Types\Type as DBALType; +use OCP\DB\Schema\ColumnType; use OCP\DB\Schema\IColumn; use OCP\DB\Schema\IType; use OCP\DB\Schema\SchemaException; @@ -33,11 +34,15 @@ public function getWrappedColumn(): DBALColumn { } #[\Override] - public function setType(string|IType|DBALType $type): self { + public function setType(string|IType|DBALType|ColumnType $type): self { if ($type instanceof IType) { $type = $type->getName(); } + if ($type instanceof ColumnType) { + $type = $type->value; + } + $this->column->setType($type instanceof DBALType ? $type : DBALType::getType($type)); return $this; @@ -97,6 +102,11 @@ public function getType(): IType { return new Type($this->column->getType()); } + #[\Override] + public function getColumnType(): ColumnType { + return ColumnType::from(DBALType::lookupName($this->column->getType())); + } + #[\Override] public function getLength(): ?int { return $this->column->getLength(); diff --git a/lib/private/DB/Schema/ForeignKeyConstraint.php b/lib/private/DB/Schema/ForeignKeyConstraint.php new file mode 100644 index 0000000000000..1424c3fc4a756 --- /dev/null +++ b/lib/private/DB/Schema/ForeignKeyConstraint.php @@ -0,0 +1,30 @@ +keyConstraint->getName(); + return $value; + } +} diff --git a/lib/private/DB/Schema/Index.php b/lib/private/DB/Schema/Index.php index dc3ea40328ede..37a613c0d0dc1 100644 --- a/lib/private/DB/Schema/Index.php +++ b/lib/private/DB/Schema/Index.php @@ -53,6 +53,11 @@ public function isSimpleIndex(): bool { return $this->index->isSimpleIndex(); } + #[\Override] + public function hasColumnAtPosition(string $name, int $position = 0): bool { + return $this->index->hasColumnAtPosition($name, $position); + } + /** * Forwards any method not declared on IIndex to the wrapped Doctrine * DBAL index, e.g. mutators like `addFlag()` or `removeFlag()` that are diff --git a/lib/private/DB/Schema/Table.php b/lib/private/DB/Schema/Table.php index 25c3c7f6413c7..7f3e6db8015c7 100644 --- a/lib/private/DB/Schema/Table.php +++ b/lib/private/DB/Schema/Table.php @@ -10,10 +10,14 @@ namespace OC\DB\Schema; use Doctrine\DBAL\Schema\Column as DBALColumn; +use Doctrine\DBAL\Schema\ForeignKeyConstraint as DBALForeignKeyConstraint; use Doctrine\DBAL\Schema\Index as DBALIndex; use Doctrine\DBAL\Schema\SchemaException as DBALSchemaException; use Doctrine\DBAL\Schema\Table as DBALTable; +use Doctrine\DBAL\Types\Type as DBALType; +use OCP\DB\Schema\ColumnType; use OCP\DB\Schema\IColumn; +use OCP\DB\Schema\IForeignKeyConstraint; use OCP\DB\Schema\IIndex; use OCP\DB\Schema\ITable; use OCP\DB\Schema\SchemaException; @@ -36,7 +40,9 @@ public function getWrappedTable(): DBALTable { #[\Override] public function getName(): string { - return $this->table->getName(); + /** @var non-empty-lowercase-string $name */ + $name = $this->table->getName(); + return $name; } #[\Override] @@ -134,8 +140,11 @@ public function renameIndex(string $oldName, ?string $newName = null): self { } #[\Override] - public function addColumn(string $name, string $typeName, array $options = []): IColumn { + public function addColumn(string $name, string|ColumnType $typeName, array $options = []): IColumn { try { + if ($typeName instanceof ColumnType) { + $typeName = $typeName->value; + } return new Column($this->table->addColumn($name, $typeName, $options)); } catch (DBALSchemaException $e) { throw new SchemaException($e->getMessage(), $e->getCode(), $e); @@ -145,6 +154,14 @@ public function addColumn(string $name, string $typeName, array $options = []): #[\Override] public function modifyColumn(string $name, array $options): self { try { + if (isset($options['type'])) { + if ($options['type'] instanceof ColumnType) { + $options['type'] = $options['type']->value; + } + if (is_string($options['type'])) { + $options['type'] = DBALType::getType($options['type']); + } + } $this->table->modifyColumn($name, $options); } catch (DBALSchemaException $e) { throw new SchemaException($e->getMessage(), $e->getCode(), $e); @@ -210,8 +227,8 @@ public function __call(string $name, array $arguments): mixed { } #[\Override] - public function hasColumn(string $string): bool { - return $this->table->hasColumn($string); + public function hasColumn(string $name): bool { + return $this->table->hasColumn($name); } #[\Override] @@ -238,4 +255,12 @@ public function getIndexes(): array { $this->table->getIndexes(), )); } + + #[\Override] + public function getForeignKeys(): array { + return array_values(array_map( + static fn (DBALForeignKeyConstraint $keyConstraint): IForeignKeyConstraint => new ForeignKeyConstraint($keyConstraint), + $this->table->getForeignKeys(), + )); + } } diff --git a/lib/public/AppFramework/Db/Entity.php b/lib/public/AppFramework/Db/Entity.php index fe7c1414fe3f4..d49150ae2a440 100644 --- a/lib/public/AppFramework/Db/Entity.php +++ b/lib/public/AppFramework/Db/Entity.php @@ -8,6 +8,7 @@ namespace OCP\AppFramework\Db; +use OCP\DB\Schema\ColumnType; use OCP\DB\Types; use function lcfirst; use function substr; @@ -23,8 +24,8 @@ abstract class Entity { public $id; /** @var array $_updatedFields */ private array $_updatedFields = []; - /** @var array $_fieldTypes */ - protected array $_fieldTypes = ['id' => 'integer']; + /** @var array $_fieldTypes */ + protected array $_fieldTypes = ['id' => ColumnType::Integer]; /** * Simple alternative constructor for building entities from a request @@ -66,7 +67,7 @@ public static function fromRow(array $row): static { * @since 7.0.0 */ public function getFieldTypes(): array { - return $this->_fieldTypes; + return array_map(fn (ColumnType $type) => $type->value, $this->_fieldTypes); } /** @@ -98,47 +99,47 @@ protected function setter(string $name, array $args): void { // if type definition exists, cast to correct type if ($args[0] !== null && array_key_exists($name, $this->_fieldTypes)) { $type = $this->_fieldTypes[$name]; - if ($type === Types::BLOB) { + if ($type === ColumnType::Blob) { // (B)LOB is treated as string when we read from the DB if (is_resource($args[0])) { $args[0] = stream_get_contents($args[0]); } - $type = Types::STRING; + $type = ColumnType::String; } switch ($type) { - case Types::BIGINT: - case Types::SMALLINT: + case ColumnType::Bigint: + case ColumnType::Smallint: settype($args[0], Types::INTEGER); break; - case Types::BINARY: - case Types::DECIMAL: - case Types::TEXT: + case ColumnType::Binary: + case ColumnType::Decimal: + case ColumnType::Text: settype($args[0], Types::STRING); break; - case Types::TIME: - case Types::DATE: - case Types::DATETIME: - case Types::DATETIME_TZ: + case ColumnType::Time: + case ColumnType::Date: + case ColumnType::Datetime: + case ColumnType::DatetimeTz: if (!$args[0] instanceof \DateTime) { $args[0] = new \DateTime($args[0]); } break; - case Types::TIME_IMMUTABLE: - case Types::DATE_IMMUTABLE: - case Types::DATETIME_IMMUTABLE: - case Types::DATETIME_TZ_IMMUTABLE: + case ColumnType::TimeImmutable: + case ColumnType::DateImmutable: + case ColumnType::DatetimeImmutable: + case ColumnType::DatetimeTzImmutable: if (!$args[0] instanceof \DateTimeImmutable) { $args[0] = new \DateTimeImmutable($args[0]); } break; - case Types::JSON: + case ColumnType::Json: if (!is_array($args[0])) { $args[0] = json_decode($args[0], true); } break; default: - settype($args[0], $type); + settype($args[0], $type->value); } } $this->$name = $args[0]; @@ -187,7 +188,7 @@ public function __call(string $methodName, array $args) { protected function isGetterForBoolProperty(string $methodName): bool { if (str_starts_with($methodName, 'is')) { $fieldName = lcfirst(substr($methodName, 2)); - return isset($this->_fieldTypes[$fieldName]) && str_starts_with($this->_fieldTypes[$fieldName], 'bool'); + return isset($this->_fieldTypes[$fieldName]) && str_starts_with($this->_fieldTypes[$fieldName]->value, 'bool'); } return false; } @@ -258,23 +259,28 @@ public function getUpdatedFields(): array { * that value once its being returned from the database * * @param string $fieldName the name of the attribute - * @param Types::* $type the type which will be used to match a cast + * @param Types::*|ColumnType $type the type which will be used to match a cast * @since 31.0.0 Parameter $type is now restricted to {@see Types} constants. The formerly accidentally supported types 'int'|'bool'|'double' are mapped to Types::INTEGER|Types::BOOLEAN|Types::FLOAT accordingly. + * @since 35.0.0 Parameter $type now prefers using one of the {@see ColumnType} enum values. * @since 7.0.0 */ - protected function addType(string $fieldName, string $type): void { + protected function addType(string $fieldName, string|ColumnType $type): void { /** @psalm-suppress TypeDoesNotContainType */ if (in_array($type, ['bool', 'double', 'int', 'array', 'object'], true)) { // Mapping legacy strings to the actual types $type = match ($type) { - 'int' => Types::INTEGER, - 'bool' => Types::BOOLEAN, - 'double' => Types::FLOAT, + 'int' => ColumnType::Integer, + 'bool' => ColumnType::Boolean, + 'double' => ColumnType::Float, 'array', - 'object' => Types::STRING, + 'object' => ColumnType::String, }; } + if (is_string($type)) { + $type = ColumnType::from($type); + } + $this->_fieldTypes[$fieldName] = $type; } diff --git a/lib/public/DB/Schema/ColumnType.php b/lib/public/DB/Schema/ColumnType.php new file mode 100644 index 0000000000000..f335c5e76c26b --- /dev/null +++ b/lib/public/DB/Schema/ColumnType.php @@ -0,0 +1,166 @@ + $columnNames + * @param list $columnNames * @param string|false $indexName * * @throws SchemaException @@ -37,9 +39,9 @@ public function getName(): string; public function setPrimaryKey(array $columnNames, string|false $indexName = false): self; /** - * @param list $columnNames - * @param list $flags - * @param array $options + * @param list $columnNames + * @param list $flags + * @param array $options * * @throws SchemaException * @since 35.0.0 @@ -77,7 +79,7 @@ public function getPrimaryKey(): ?IIndex; /** * Drops an index from this table. * - * @param string $name The index name. + * @param non-empty-lowercase-string $name The index name. * * @throws SchemaException If the index does not exist. * @since 35.0.0 @@ -87,7 +89,7 @@ public function dropIndex(string $name): self; /** * Returns whether this table has an index with the given name. * - * @param string $name The index name. + * @param non-empty-lowercase-string $name The index name. * @since 35.0.0 */ public function hasIndex(string $name): bool; @@ -105,9 +107,9 @@ public function addUniqueIndex(array $columnNames, ?string $indexName = null, ar /** * Renames an index. * - * @param string $oldName The name of the index to rename from. - * @param string|null $newName The name of the index to rename to. - * If null is given, the index name will be auto-generated. + * @param non-empty-lowercase-string $oldName The name of the index to rename from. + * @param non-empty-lowercase-string|null $newName The name of the index to rename to. + * If null is given, the index name will be auto-generated. * * @return self This table instance. * @@ -118,8 +120,8 @@ public function addUniqueIndex(array $columnNames, ?string $indexName = null, ar public function renameIndex(string $oldName, ?string $newName = null): self; /** - * @param string $name - * @param string $typeName + * @param non-empty-lowercase-string $name + * @param Types::*|ColumnType $typeName * @param array{ * notnull?: bool, * length?: ?int, @@ -127,15 +129,17 @@ public function renameIndex(string $oldName, ?string $newName = null): self; * unsigned?: bool, * autoincrement?: bool, * fixed?: bool, + * precision?: int, + * scale?: int, * } $options * * @throws SchemaException * @since 35.0.0 */ - public function addColumn(string $name, string $typeName, array $options = []): IColumn; + public function addColumn(string $name, string|ColumnType $typeName, array $options = []): IColumn; /** - * @param string $name + * @param non-empty-lowercase-string $name * @param array{ * notnull?: bool, * length?: ?int, @@ -143,6 +147,9 @@ public function addColumn(string $name, string $typeName, array $options = []): * unsigned?: bool, * autoincrement?: bool, * fixed?: bool, + * precision?: int, + * scale?: int, + * type?: Types::*|ColumnType, * } $options * * @throws SchemaException @@ -152,6 +159,8 @@ public function modifyColumn(string $name, array $options): self; /** * Drops a Column from the Table. + * + * @param non-empty-lowercase-string $name * @since 35.0.0 */ public function dropColumn(string $name): self; @@ -159,15 +168,15 @@ public function dropColumn(string $name): self; /** * Returns whether this table has a Column with the given name. * - * @param string $name The column name. + * @param non-empty-lowercase-string $name The column name. * @since 35.0.0 */ - public function hasColumn(string $string): bool; + public function hasColumn(string $name): bool; /** * Returns the Column with the given name. * - * @param string $name The column name. + * @param non-empty-lowercase-string $name The column name. * * @throws SchemaException If the column does not exist. * @since 35.0.0 @@ -195,9 +204,9 @@ public function getIndexes(): array; * * Name is inferred from the local columns. * - * @param ITable|string $foreignTable Table schema instance or table name - * @param list $localColumnNames - * @param list $foreignColumnNames + * @param ITable|non-empty-lowercase-string $foreignTable Table schema instance or table name + * @param list $localColumnNames + * @param list $foreignColumnNames * @param array $options * * @throws SchemaException @@ -213,6 +222,8 @@ public function addForeignKeyConstraint( /** * Returns whether this table has a foreign key constraint with the given name. + * + * @param non-empty-string $name The foreign key name. * @since 35.0.0 */ public function hasForeignKey(string $name): bool; @@ -220,10 +231,16 @@ public function hasForeignKey(string $name): bool; /** * Removes the foreign key constraint with the given name. * - * @param string $name The constraint name. + * @param non-empty-string $name The constraint name. * * @throws SchemaException * @since 35.0.0 */ public function removeForeignKey(string $name): void; + + /** + * @since 35.0.0 + * @return list + */ + public function getForeignKeys(): array; } From f9bcbd3f9f13795f0ebedf4bf4f33945a508dbc9 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 11 Aug 2026 15:42:39 +0200 Subject: [PATCH 2/2] refactor(dbal): Merge ColumnType and IType Just make sure ColumnType has a method getName for compatibility purpose Signed-off-by: Carl Schwan --- lib/composer/composer/autoload_classmap.php | 2 - lib/composer/composer/autoload_static.php | 2 - lib/private/DB/Schema/Column.php | 16 ++----- .../DB/Schema/ForeignKeyConstraint.php | 3 +- lib/private/DB/Schema/Type.php | 42 ------------------- lib/public/DB/Schema/ColumnType.php | 7 ++++ lib/public/DB/Schema/IColumn.php | 16 ++----- lib/public/DB/Schema/ITable.php | 1 + lib/public/DB/Schema/IType.php | 28 ------------- 9 files changed, 16 insertions(+), 101 deletions(-) delete mode 100644 lib/private/DB/Schema/Type.php delete mode 100644 lib/public/DB/Schema/IType.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index f556057caaa7c..60f514f693d03 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -377,7 +377,6 @@ 'OCP\\DB\\Schema\\IForeignKeyConstraint' => $baseDir . '/lib/public/DB/Schema/IForeignKeyConstraint.php', 'OCP\\DB\\Schema\\IIndex' => $baseDir . '/lib/public/DB/Schema/IIndex.php', 'OCP\\DB\\Schema\\ITable' => $baseDir . '/lib/public/DB/Schema/ITable.php', - 'OCP\\DB\\Schema\\IType' => $baseDir . '/lib/public/DB/Schema/IType.php', 'OCP\\DB\\Schema\\SchemaException' => $baseDir . '/lib/public/DB/Schema/SchemaException.php', 'OCP\\DB\\Types' => $baseDir . '/lib/public/DB/Types.php', 'OCP\\Dashboard\\IAPIWidget' => $baseDir . '/lib/public/Dashboard/IAPIWidget.php', @@ -1790,7 +1789,6 @@ 'OC\\DB\\Schema\\ForeignKeyConstraint' => $baseDir . '/lib/private/DB/Schema/ForeignKeyConstraint.php', 'OC\\DB\\Schema\\Index' => $baseDir . '/lib/private/DB/Schema/Index.php', 'OC\\DB\\Schema\\Table' => $baseDir . '/lib/private/DB/Schema/Table.php', - 'OC\\DB\\Schema\\Type' => $baseDir . '/lib/private/DB/Schema/Type.php', 'OC\\DB\\SetTransactionIsolationLevel' => $baseDir . '/lib/private/DB/SetTransactionIsolationLevel.php', 'OC\\Dashboard\\Manager' => $baseDir . '/lib/private/Dashboard/Manager.php', 'OC\\DatabaseException' => $baseDir . '/lib/private/DatabaseException.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 875ff36b5840e..dc998ebb27523 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -418,7 +418,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\DB\\Schema\\IForeignKeyConstraint' => __DIR__ . '/../../..' . '/lib/public/DB/Schema/IForeignKeyConstraint.php', 'OCP\\DB\\Schema\\IIndex' => __DIR__ . '/../../..' . '/lib/public/DB/Schema/IIndex.php', 'OCP\\DB\\Schema\\ITable' => __DIR__ . '/../../..' . '/lib/public/DB/Schema/ITable.php', - 'OCP\\DB\\Schema\\IType' => __DIR__ . '/../../..' . '/lib/public/DB/Schema/IType.php', 'OCP\\DB\\Schema\\SchemaException' => __DIR__ . '/../../..' . '/lib/public/DB/Schema/SchemaException.php', 'OCP\\DB\\Types' => __DIR__ . '/../../..' . '/lib/public/DB/Types.php', 'OCP\\Dashboard\\IAPIWidget' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IAPIWidget.php', @@ -1831,7 +1830,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\DB\\Schema\\ForeignKeyConstraint' => __DIR__ . '/../../..' . '/lib/private/DB/Schema/ForeignKeyConstraint.php', 'OC\\DB\\Schema\\Index' => __DIR__ . '/../../..' . '/lib/private/DB/Schema/Index.php', 'OC\\DB\\Schema\\Table' => __DIR__ . '/../../..' . '/lib/private/DB/Schema/Table.php', - 'OC\\DB\\Schema\\Type' => __DIR__ . '/../../..' . '/lib/private/DB/Schema/Type.php', 'OC\\DB\\SetTransactionIsolationLevel' => __DIR__ . '/../../..' . '/lib/private/DB/SetTransactionIsolationLevel.php', 'OC\\Dashboard\\Manager' => __DIR__ . '/../../..' . '/lib/private/Dashboard/Manager.php', 'OC\\DatabaseException' => __DIR__ . '/../../..' . '/lib/private/DatabaseException.php', diff --git a/lib/private/DB/Schema/Column.php b/lib/private/DB/Schema/Column.php index daea23545da69..01dbd7845464e 100644 --- a/lib/private/DB/Schema/Column.php +++ b/lib/private/DB/Schema/Column.php @@ -14,7 +14,6 @@ use Doctrine\DBAL\Types\Type as DBALType; use OCP\DB\Schema\ColumnType; use OCP\DB\Schema\IColumn; -use OCP\DB\Schema\IType; use OCP\DB\Schema\SchemaException; /** @@ -22,7 +21,7 @@ */ class Column implements IColumn { public function __construct( - private DBALColumn $column, + private readonly DBALColumn $column, ) { } @@ -34,11 +33,7 @@ public function getWrappedColumn(): DBALColumn { } #[\Override] - public function setType(string|IType|DBALType|ColumnType $type): self { - if ($type instanceof IType) { - $type = $type->getName(); - } - + public function setType(string|DBALType|ColumnType $type): self { if ($type instanceof ColumnType) { $type = $type->value; } @@ -98,12 +93,7 @@ public function setDefault(mixed $default): self { } #[\Override] - public function getType(): IType { - return new Type($this->column->getType()); - } - - #[\Override] - public function getColumnType(): ColumnType { + public function getType(): ColumnType { return ColumnType::from(DBALType::lookupName($this->column->getType())); } diff --git a/lib/private/DB/Schema/ForeignKeyConstraint.php b/lib/private/DB/Schema/ForeignKeyConstraint.php index 1424c3fc4a756..85240019717ea 100644 --- a/lib/private/DB/Schema/ForeignKeyConstraint.php +++ b/lib/private/DB/Schema/ForeignKeyConstraint.php @@ -3,8 +3,7 @@ declare(strict_types=1); /** - * SPDX-FileCopyrightText: 2025 Nextcloud GmbH - * SPDX-FileContributor: Carl Schwan + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ diff --git a/lib/private/DB/Schema/Type.php b/lib/private/DB/Schema/Type.php deleted file mode 100644 index 3792bd2219b46..0000000000000 --- a/lib/private/DB/Schema/Type.php +++ /dev/null @@ -1,42 +0,0 @@ -getType()->getName()` (the Doctrine DBAL API) working, without - * committing to the rest of Doctrine's Type API as public API. - */ -class Type implements IType { - public function __construct( - private DBALType $type, - ) { - } - - /** - * Returns the wrapped Doctrine DBAL type. - */ - public function getWrappedType(): DBALType { - return $this->type; - } - - #[\Override] - public function getName(): string { - /** @var Types::* $type */ - $type = $this->type->getName(); - return $type; - } -} diff --git a/lib/public/DB/Schema/ColumnType.php b/lib/public/DB/Schema/ColumnType.php index f335c5e76c26b..2a2cd1d633816 100644 --- a/lib/public/DB/Schema/ColumnType.php +++ b/lib/public/DB/Schema/ColumnType.php @@ -163,4 +163,11 @@ enum ColumnType: string { * @since 35.0.0 */ case Json = 'json'; + + /** + * @since 35.0.0 + */ + public function getName(): string { + return $this->value; + } } diff --git a/lib/public/DB/Schema/IColumn.php b/lib/public/DB/Schema/IColumn.php index bb6d99e0f724e..6a6ccfc298dab 100644 --- a/lib/public/DB/Schema/IColumn.php +++ b/lib/public/DB/Schema/IColumn.php @@ -19,10 +19,10 @@ #[Consumable(since: '35.0.0')] interface IColumn { /** - * @param \OCP\DB\Types::*|IType|ColumnType $type + * @param \OCP\DB\Types::*|ColumnType $type * @since 35.0.0 */ - public function setType(string|IType|ColumnType $type): self; + public function setType(string|ColumnType $type): self; /** * @since 35.0.0 @@ -62,19 +62,11 @@ public function setDefault(mixed $default): self; /** * Returns the type of this column. * - * Note that {@see IType::getName()} returns a `\OCP\DB\Types::*` value. + * Note that {@see ColumnType::getName()} returns a `\OCP\DB\Types::*` value. * * @since 35.0.0 - * @note Prefer using getColumnType, this method is here for legacy compatibility. */ - public function getType(): IType; - - /** - * Returns the type of this column. - * - * @since 35.0.0 - */ - public function getColumnType(): ColumnType; + public function getType(): ColumnType; /** * @return int|null diff --git a/lib/public/DB/Schema/ITable.php b/lib/public/DB/Schema/ITable.php index 16f54d3c1c0a8..12f762c799517 100644 --- a/lib/public/DB/Schema/ITable.php +++ b/lib/public/DB/Schema/ITable.php @@ -131,6 +131,7 @@ public function renameIndex(string $oldName, ?string $newName = null): self; * fixed?: bool, * precision?: int, * scale?: int, + * type?: Types::*|ColumnType, * } $options * * @throws SchemaException diff --git a/lib/public/DB/Schema/IType.php b/lib/public/DB/Schema/IType.php deleted file mode 100644 index 8b27872959fe5..0000000000000 --- a/lib/public/DB/Schema/IType.php +++ /dev/null @@ -1,28 +0,0 @@ -