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 .scoper-production-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ psr/http-client
psr/http-factory
psr/http-message
psr/simple-cache
symfony/uid
symfony/polyfill-uuid
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Share your tables and views with users and groups within your cloud.
Have a good time and manage whatever you want.

]]></description>
<version>2.1.1</version>
<version>2.2.0-dev.0</version>
<licence>AGPL-3.0-or-later</licence>
<author mail="florian.steffens@nextcloud.com">Florian Steffens</author>
<namespace>Tables</namespace>
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"require": {
"phpoffice/phpspreadsheet": "^5.1",
"ext-json": "*",
"bamarni/composer-bin-plugin": "^1.9.1"
"bamarni/composer-bin-plugin": "^1.9.1",
"symfony/uid": "^6.4"
}
}
163 changes: 162 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions lib/Db/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
use OCA\Tables\Dto\Column as ColumnDto;
use OCA\Tables\ResponseDefinitions;
use OCA\Tables\Service\ValueObject\ViewColumnInformation;
use OCA\Tables\Vendor\Symfony\Component\Uid\Uuid;
use ValueError;

/**
* @psalm-suppress PropertyNotSetInConstructor
*
* @psalm-import-type TablesColumn from ResponseDefinitions
*
* @method string getUuid()
* @method getTitle(): string
* @method setTitle(string $title)
* @method getTableId(): int
Expand Down Expand Up @@ -59,13 +61,11 @@
* @method setTextDefault(?string $textDefault)
* @method getTextAllowedPattern(): string
* @method setTextAllowedPattern(?string $textAllowedPattern)
* @method getTextAllowedPattern(): ?string
* @method getTextMaxLength(): int
* @method setTextMaxLength(?int $textMaxLength)
* @method getTextUnique(): bool
* @method setTextUnique(?bool $textUnique)
* @method getSelectionOptions(): string
* @method getSelectionDefault(): string
* @method setSelectionOptions(?string $selectionOptionsArray)
* @method setSelectionDefault(?string $selectionDefault)
* @method getSelectionDefault(): ?string
Expand Down Expand Up @@ -114,6 +114,7 @@ class Column extends EntitySuper implements JsonSerializable {

public const META_ID_TITLE = 'id';

protected ?string $uuid = null;
protected ?string $title = null;
protected ?int $tableId = null;
protected ?string $createdBy = null;
Expand Down Expand Up @@ -165,6 +166,7 @@ class Column extends EntitySuper implements JsonSerializable {

public function __construct() {
$this->addType('id', 'integer');
$this->addType('uuid', 'string');
$this->addType('tableId', 'integer');
$this->addType('mandatory', 'boolean');

Expand Down Expand Up @@ -198,8 +200,23 @@ public static function isValidMetaTypeId(int $metaTypeId): bool {
], true);
}

private function assignUuid(): void {
if ($this->uuid !== null) {
throw new \RuntimeException('This column already has a UUID, they are immutable');
}
$this->uuid = Uuid::v7()->toRfc4122();
}

protected function setUuid(string $uuid): void {
if ($this->uuid !== null) {
throw new \RuntimeException('This column already has a UUID, they are immutable');
}
$this->uuid = $uuid;
}

public static function fromDto(ColumnDto $data): self {
$column = new self();
$column->assignUuid();
$column->setTitle($data->getTitle());
$column->setType($data->getType());
$column->setSubtype($data->getSubtype() ?? '');
Expand Down Expand Up @@ -262,6 +279,7 @@ public function setSelectionOptionsArray(array $array):void {
public function jsonSerialize(): array {
return [
'id' => $this->id,
'uuid' => $this->uuid,
'tableId' => $this->tableId,
'title' => $this->title,
'createdBy' => $this->createdBy,
Expand Down
96 changes: 96 additions & 0 deletions lib/Migration/Version2020Date20260513185340.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

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

namespace OCA\Tables\Migration;

use Closure;
use OCA\Tables\Vendor\Symfony\Component\Uid\Uuid;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use Override;

class Version2020Date20260513185340 extends SimpleMigrationStep {
private const TARGET_TABLE = 'tables_columns';
private const COL_ID = 'id';
private const COL_UUID = 'uuid';

public function __construct(
private readonly IDBConnection $db,
) {
}

#[Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$schema = $schemaClosure();

if (!$schema->hasTable(self::TARGET_TABLE)) {
return null;
}

$columnsTable = $schema->getTable(self::TARGET_TABLE);
if (!$columnsTable->hasColumn(self::COL_UUID)) {
$columnsTable->addColumn(self::COL_UUID, Types::STRING, [
'notnull' => false,
'default' => null,
'length' => 36,
Comment thread
Koc marked this conversation as resolved.
'comment' => 'UUIDv7 identifier to support structural updates across instances',
]);
}

return $schema;
}

#[Override]
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {

$qbUpdate = $this->db->getQueryBuilder();
$qbUpdate->update(self::TARGET_TABLE)
->set(self::COL_UUID, $qbUpdate->createParameter('columnUuid'))
->where($qbUpdate->expr()->eq(self::COL_ID, $qbUpdate->createParameter('columnLocalId')));

$qbSelect = $this->db->getQueryBuilder();
$qbSelect->select(self::COL_ID)
->from(self::TARGET_TABLE);
$select = $qbSelect->executeQuery();

$writeBatches = 250;
$updates = 0;

try {
$this->db->beginTransaction();
while (($columnId = $select->fetchOne()) !== false) {
$qbUpdate->setParameters(
[
'columnLocalId' => (int)$columnId,
'columnUuid' => Uuid::v7()->toRfc4122(),
],
[
Types::INTEGER,
Types::STRING,
]
);
$qbUpdate->executeStatement();
$updates++;
if ($updates % $writeBatches === 0) {
$this->db->commit();
$this->db->beginTransaction();
}
}
$this->db->commit();
} catch (\Exception $e) {
$this->db->rollBack();
throw $e;
}

$select->closeCursor();
}
}
Loading