Skip to content

feat: add UUIDs to columns#2598

Open
blizzz wants to merge 1 commit into
mainfrom
enh/column-uuids
Open

feat: add UUIDs to columns#2598
blizzz wants to merge 1 commit into
mainfrom
enh/column-uuids

Conversation

@blizzz

@blizzz blizzz commented May 13, 2026

Copy link
Copy Markdown
Member

Base for structural updates, cf. my comment in #2504 (comment)

  • Add UUIDs to Tables or consider unnecessary
  • Add UUIDs to Views or consider unnecessary
  • Add UUIDs to multiselection options
  • Treat multiselection default on export and import

@blizzz blizzz requested a review from enjeck as a code owner May 13, 2026 20:04
@blizzz blizzz added the 2. developing Work in progress label May 13, 2026
@blizzz blizzz force-pushed the enh/column-uuids branch from a7d556b to 1564e5e Compare May 13, 2026 20:10
Comment thread lib/Migration/Version2020Date20260513185340.php
Comment thread .scoper-production-dependencies Outdated
@blizzz blizzz force-pushed the enh/column-uuids branch from 1564e5e to dc4ed01 Compare May 18, 2026 20:59
@blizzz

blizzz commented May 18, 2026

Copy link
Copy Markdown
Member Author

Add UUIDs to Tables or consider unnecessary
Add UUIDs to Views or consider unnecessary

Would not implement it now as it is not required currently. If necessary for an auto-update of a table without specifying local ids, this can be always added alter on easily.

@blizzz blizzz force-pushed the enh/column-uuids branch from ae85f9f to bd52932 Compare May 28, 2026 12:18
@Koc

Koc commented May 28, 2026

Copy link
Copy Markdown
Contributor

I guess that uuid should be unique across table (we need add unique id for table_id+uuid).

Here use-cases that we need to support:

Table update between instance

  • a developer designs and evolves a table schema locally using UI
  • exports the schema
  • imports it into production
  • later changes the schema locally again
  • and wants to apply those schema updates to the already existing production table without recreating it from scratch

Table duplocation a single NC instance

A second scenario is especially important for end users who do not have separate environments:

  • a developer designs and evolves a table schema using UI
  • exports the schema
  • imports it into another table on same instance

@blizzz

blizzz commented May 28, 2026

Copy link
Copy Markdown
Member Author

I guess that uuid should be unique across table (we need add unique id for table_id+uuid).

Here use-cases that we need to support:

Table update between instance

* a developer designs and evolves a table schema locally using UI

* exports the schema

* imports it into production

* later changes the schema locally again

* and wants to apply those schema updates to the already existing production table without recreating it from scratch

Yupp, this scenario is exactly what are having in mind.

Table duplocation a single NC instance

A second scenario is especially important for end users who do not have separate environments:

* a developer designs and evolves a table schema using UI

* exports the schema

* imports it into another table on same instance

This would also be covered, as importing always requires a target table. So having columns with the same UUID across different tables is intentional. Hence importing, so the plan, would only affect the columns on the targeted table.

@enjeck enjeck force-pushed the enh/column-uuids branch from bd52932 to b43e52c Compare June 6, 2026 19:54
@blizzz blizzz force-pushed the enh/column-uuids branch from b43e52c to 8572960 Compare June 8, 2026 08:32
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
@blizzz blizzz force-pushed the enh/column-uuids branch from 8572960 to 85e5210 Compare June 15, 2026 10:34

@enjeck enjeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

some comments

Comment thread lib/Db/Column.php
Comment on lines +202 to +215
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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

QBMapper::insert() only writes fields returned by getUpdatedFields(). So we need to call markFieldUpdated('uuid') ?

Comment thread lib/Db/Column.php
$this->uuid = Uuid::v7()->toRfc4122();
}

protected function setUuid(string $uuid): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we ever call this? and is it being protected useful. Cuz when the mapper reads a row, Entity::fromRow() runs (Entity.php:50):

phpforeach ($row as $key => $value) {
    $prop = $instance->columnToProperty($key);
    $instance->setter($prop, [$value]);   // <-- calls the generic setter()
}

It calls the generic setter() method directly with the property name 'uuid'. i don't think it calls setUuid()? So the custom method and its RuntimeException are skipped?

Comment thread lib/Db/Column.php
*
* @psalm-import-type TablesColumn from ResponseDefinitions
*
* @method string getUuid()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since the property is ?string $uuid

Suggested change
* @method string getUuid()
@method ?string getUuid()

Comment thread lib/Db/Column.php
public function jsonSerialize(): array {
return [
'id' => $this->id,
'uuid' => $this->uuid,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need to update ResponseDefinitions.php?

Comment thread lib/Db/Column.php

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In ColumnService.php, we call new Column(). Do we have to do assignUuid() there?

'notnull' => false,
'default' => null,
'length' => 36,
'comment' => 'UUIDv7 identifier to support structural updates across instances',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so it will be nice to have a a UNIQUE index?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants