Skip to content

feat(rows): add persistent UUIDv7 identifiers to rows - #3229

Open
foolfitz wants to merge 6 commits into
nextcloud:mainfrom
foolfitz:feat/3093-row-uuid-squashed
Open

foolfitz wants to merge 6 commits into
nextcloud:mainfrom
foolfitz:feat/3093-row-uuid-squashed

Conversation

@foolfitz

@foolfitz foolfitz commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Related issue: #3093

Rows get a persistent UUIDv7, so a row can still be identified after a user migration export and import changes its integer ID. Rows are still addressed by integer ID; this PR adds no UUID-based routes (see #3093 (comment)).

Main changes

  • A uuid column on tables_row_sleeves with an instance-wide unique index, assigned on insert and immutable afterwards.
  • Existing rows are backfilled by a background job; until then their uuid is null.
  • User migration archives preserve row UUIDs. On import, a row keeps its UUID if it is a valid UUIDv7 and is unused on the destination instance. Otherwise, the imported row gets a new UUIDv7.
  • Row responses include a read-only uuid (API v1, v2 and public shares).

Testing

Unit tests, the upgrade from 2.4.0 with the backfill, and user migration imports were run on SQLite, MySQL, MariaDB and PostgreSQL before the latest merge of main.

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔙 Backport requests are created or not needed: /backport to stableX.X
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Codex assisted with developing the code and tests, and Claude Code assisted with their review. I performed the manual migration test and captured the screenshots; Codex assisted with drafting the PR description.

@foolfitz
foolfitz marked this pull request as ready for review November 6, 2026 07:02
@foolfitz foolfitz changed the title feat(rows): add persistent UUIDv7 identifiers and UUID-based API access #3093 feat(rows): add persistent UUIDv7 identifiers and UUID-based API access Nov 6, 2026
@enjeck enjeck mentioned this pull request Nov 18, 2026
4 of 5 tasks

@blizzz blizzz left a comment

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.

Apart of the comments, we get some more overhead on PUT and DELETE requests:

(RowOCSController.php:190,241). It checks the read permission, loads the view and runs a filtered scope query. Then updateRowData/delete do all of that again: getRowById, the permission checks, and isRowInViewPresent (RowService.php:707,831).

(by code, without benchmarking)

I would prefer keeping the UUID out of the core logic as much as possible. Handle them on the Controller parts, where necessary, and continue working with the ID. The main way to interact with Tables should still be the id.

All in all there are too many other things creeping into this PR, and the changes are more complicated than necessary.

Comment thread lib/Controller/RowOCSController.php Outdated
#[NoAdminRequired]
#[RequirePermission(permission: Application::PERMISSION_READ, typeParam: 'nodeCollection')]
#[ApiRoute(verb: 'GET', url: '/api/2/{nodeCollection}/{nodeId}/rows/{rowId}', requirements: ['nodeCollection' => '(tables|views)', 'nodeId' => '(\d+)'])]
public function getRow(string $nodeCollection, int $nodeId, string $rowId): DataResponse {

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.

not sure this addition belongs to this PR, what is the motivation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#3093 asked for it: the route section says "this needs a GET for both uuid and integer id, as this route does not exist yet", and one of the acceptance criteria covers GET, PUT and DELETE on that path. It was also where most of the extra logic came from: API v2 has no single-row read yet, so reading through a view needed its own permission, filter and column handling, including the zero-column changes you asked about below. Given your preference to keep UUIDs out of the core logic, I've removed it together with the UUID addressing, so this PR doesn't cover that acceptance criterion.

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.

@rjzondervan how flexible are we here?

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.

I'm looking into the plan, I might revise issue 3093 to contain uuid-routing to contexts/applications only. I'll come back to this shortly.

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.

Ok, looking into the plan, we could decide to contain routing to uuids only to the applications. For our usecases that would work. However, there is also an issue (3096) that uses uuids on relations. If we wouldn't port uuid routing to other fields, that would prevent the possibility of copying the value and pasting it into the API route to access the related object.

If that's something that we can accept on the 'normal' routes because API use here is not foreseen, we can work with that (we might possibly need to add some translation then in the frontend workings).

I'll comment this also on #3093 with a bit more detail.

@blizzz blizzz Nov 26, 2026 •

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.

I yet miss to understand why IDs are not sufficient, but UUIDs are required?

For everything related to im-/exporting, deployment etc. yes they are absolutely necessary, but the relevant logic is to be only contained on such operations. In daily operation, the sequential ID should be sufficient (even with federation).

Comment thread lib/Controller/RowOCSController.php Outdated
#[RequirePermission(permission: Application::PERMISSION_UPDATE, typeParam: 'nodeCollection')]
#[ApiRoute(verb: 'PUT', url: '/api/2/{nodeCollection}/{nodeId}/rows/{rowId}', requirements: ['nodeCollection' => '(tables|views)', 'nodeId' => '(\d+)'])]
public function updateRow(string $nodeCollection, int $nodeId, int $rowId, mixed $data): DataResponse {
public function updateRow(string $nodeCollection, int $nodeId, string $rowId, mixed $data): DataResponse {

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.

did you consider creating a new endpoint to retrieve a row by UUID, and what let you to this decision?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I followed the design in #3093, which puts the UUID into the existing {rowId} routes and notes that rowId switches from int to string in their specification. The issue considered a separate /api/2/rows/{uuid} and rejected it, because API v2 already puts the table or view in the route and a UUID alone would leave the permission context ambiguous. I didn't evaluate a separate route under the node path. I've now taken UUID addressing out of this PR, so PUT and DELETE are unchanged from main.

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.

I'd keep it separated and not mangle to many behaviours into the same path. @rjzondervan would that work with you?

@rjzondervan rjzondervan Nov 24, 2026 •

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.

As per my comment in the other thread, I think we could contain it to routing within applications.

Comment thread lib/Controller/RowOCSController.php Outdated
#[RequirePermission(permission: Application::PERMISSION_DELETE, typeParam: 'nodeCollection')]
#[ApiRoute(verb: 'DELETE', url: '/api/2/{nodeCollection}/{nodeId}/rows/{rowId}', requirements: ['nodeCollection' => '(tables|views)', 'nodeId' => '(\d+)'])]
public function deleteRow(string $nodeCollection, int $nodeId, int $rowId): DataResponse {
public function deleteRow(string $nodeCollection, int $nodeId, string $rowId): DataResponse {

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.

same question here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

Comment thread lib/Db/Row2Mapper.php Resolved
Comment thread lib/Db/Row2Mapper.php Resolved
Comment thread lib/Model/RowDataInput.php Resolved
Comment thread lib/Service/ImportService.php Resolved
Comment thread lib/Service/RowService.php Resolved
foolfitz and others added 4 commits November 20, 2026 23:01
Add a nullable, uniquely indexed uuid column to tables_row_sleeves.
Every sleeve insertion, including legacy transfers with explicit IDs,
assigns a UUIDv7 before writing. An assigned identity is normalized to
lowercase and cannot change or be cleared. Stored values load unchanged,
so rows created before this release keep NULL until they are backfilled.

User migration archives now carry each row's UUID. Import keeps an
archived UUID unless another row already has it, in which case the
imported row gets a fresh one. Archives without a UUID, or with one that
is not a valid UUIDv7, get a fresh one as well, as table imports treat
invalid table UUIDs. The UUID is looked up before inserting, as
TableService::create() does for table UUIDs, because the import runs in
one transaction that a unique constraint violation would cancel.

Refs: nextcloud#3093
Assisted-by: Codex:gpt-6
Assisted-by: Codex:gpt-6-astra
Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-fable-5-2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jiajun Xu <foolfitz@gmail.com>
Register a periodic job from the migration that assigns UUIDv7 values
to sleeves still holding NULL. A run processes batches of up to 500
rows for about five seconds and commits each batch. The update only
touches rows whose uuid is still NULL, so concurrent assignments and
deletions are respected and audit metadata stays unchanged. Parallel
runs are disabled.

Progress is a lazy app-config cursor written once per run. A lagging
cursor only repeats a cheap NULL scan, while writing it after every
batch would invalidate the shared app-config cache. When a pass finds
nothing left, the job rescans from the start for rows below the cursor
before it removes itself. On SQLite the job pauses briefly between
batches so requests can take the single writer.

Refs: nextcloud#3093
Assisted-by: Codex:gpt-6
Assisted-by: Codex:gpt-6-astra
Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-fable-5-2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jiajun Xu <foolfitz@gmail.com>
Row responses now include the persisted uuid next to the integer id,
including public-share rows and the row returned by POST. Rows created
before the backfill reaches them report null. Row responses forwarded
from a federated server keep the remote uuid, or report null when the
remote server does not send one.

Regenerate openapi.json and the TypeScript types for the new field.

Refs: nextcloud#3093
Assisted-by: Codex:gpt-6
Assisted-by: Codex:gpt-6-astra
Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jiajun Xu <foolfitz@gmail.com>
Existing installations run the row UUID migration only when the declared
app version is higher than the installed one. Bump appinfo/info.xml along
with package.json and package-lock.json, which this repository keeps in
sync.

Refs: nextcloud#3093
Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-fable-5-2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jiajun Xu <foolfitz@gmail.com>
@foolfitz
foolfitz force-pushed the feat/3093-row-uuid-squashed branch from 266c10c to 8ab689f Compare November 20, 2026 15:01
@foolfitz

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I've cut the PR down to the row identity itself: the UUID column with its unique index, assignment on insert, the background backfill, keeping UUIDs in user migration archives, and uuid in row responses.

Addressing rows by UUID is no longer part of it. The API v2 row routes are back to main's numeric IDs (only federated responses still fill in uuid: null), and RowService::updateSet(), delete() and the row lookups in Row2Mapper are unchanged from main, so the extra work on PUT and DELETE is gone, together with the unrelated changes you pointed out. Archive import now checks for a used UUID before inserting, the same way TableService::create() does for table UUIDs, and the backfill job no longer retries collisions itself.

To get there I dropped the last two commits and rebased the rest onto current main, which also resolves the conflicts. The PR is now the first three commits, with the archive import change folded into the first, plus the version bump. I tested the upgrade from 2.4.0, the backfill, user migration imports and the unit suite on MySQL, MariaDB, PostgreSQL and SQLite.

@github-actions

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@foolfitz foolfitz changed the title feat(rows): add persistent UUIDv7 identifiers and UUID-based API access feat(rows): add persistent UUIDv7 identifiers to rows Nov 22, 2026
@blizzz blizzz added enhancement New feature or request 2. developing Work in progress labels Nov 24, 2026
@rjzondervan rjzondervan mentioned this pull request Nov 24, 2026
Comment thread lib/Db/RowSleeve.php
* Hydration uses Entity::setter() instead, so stored values load unchanged.
*/
public function setUuid(?string $uuid): void {
$uuid = $uuid !== null ? (new UuidV7($uuid))->toRfc4122() : null;

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.

why only v7 UUIDs accepted?

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.

They can be sorted while still being random. Other versions cannot guarantee that.

@blizzz

blizzz commented Nov 30, 2026

Copy link
Copy Markdown
Member

We had refinements to the spec last week, as noted in #3093 (comment)

@foolfitz

foolfitz commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@blizzz
Thanks for the pointer. I removed UUID-based row addressing in the Nov 21 rework and have now updated the PR description to reflect that.

The PR still assigns and stores row UUIDs, backfills existing rows, and preserves UUIDs during user migration. The only API change is a read-only uuid field in row responses (API v1, v2, and public shares). Would you prefer to keep that field in this PR or defer exposing it?

Assisted by ClaudeCode:claude-opus-5-5

rjzondervan added a commit to ConductionNL/tables that referenced this pull request Dec 2, 2026
Upstream continues with nextcloud#3229 for the row uuid, so take
out the net change of nextcloud#3253 as merged here (the diff from its merge base
with main to 7d307e2). The id routes go back to main: an integer row
id and no single-row GET.

The slug routes share the row helpers with the id routes, so they take
the integer row id again as well ('rowId' => '(\d+)'). findInNode()
stays in RowService for the single-row GET by slug, with its tests in
RowServiceFindInNodeTest.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Zondervan <robert@conduction.nl>
rjzondervan added a commit to ConductionNL/tables that referenced this pull request Dec 2, 2026
Upstream continues with nextcloud#3229 for the row uuid, so take
out the net change of nextcloud#3253 (the diff from its merge base with main to
b5977db). The single-row GET and the uuid addressing of the row routes
go with it. The row listing keeps the node helpers it uses.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Zondervan <robert@conduction.nl>
rjzondervan added a commit to ConductionNL/tables that referenced this pull request Dec 2, 2026
The row uuid of nextcloud#3229: column with a unique index, set on insert,
backfill job, kept on user-migration import, uuid in TablesRow.
It brings main up to 466339b and the version 2.5.0-dev.1.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rjzondervan added a commit to ConductionNL/tables that referenced this pull request Dec 2, 2026
The revert of nextcloud#3253 took findViewOrFail() with it, which the listing
uses, so it comes back as a private helper. The tests construct
RowService without the IDBConnection that nextcloud#3229 dropped and with the
RowQueryResolver the listing added.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Zondervan <robert@conduction.nl>
rjzondervan added a commit to ConductionNL/tables that referenced this pull request Dec 2, 2026
Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Zondervan <robert@conduction.nl>
rjzondervan added a commit to ConductionNL/tables that referenced this pull request Dec 2, 2026
Brings in the revert of nextcloud#3253 and nextcloud#3229 through the row
listing. Conflicts:

- RowOCSController: the single-row GET came from nextcloud#3253 and goes with
  the revert, together with the shape handling 3096/1 added to it; a
  numeric-id read of one row follows as its own commit.
- RowSleeveMapper: findIdByUuid of nextcloud#3253 goes; findUuidsByIds of 3096/1
  stays for now.
- openapi.json and the TS types are regenerated.

The controller and find-page tests that read a single row now read the
listing; the findUuidsByIds tests use the sleeve helpers of nextcloud#3229.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Zondervan <robert@conduction.nl>
rjzondervan added a commit to ConductionNL/tables that referenced this pull request Dec 2, 2026
Row uuids are not used to address rows on the regular endpoints
(nextcloud#3093), so the id in @self of the object shape is the
numeric row id that the other api/2 routes take. The uuid of nextcloud#3229 is a
separate read-only field, null for a row that has none yet. rowId goes,
it would only repeat the id.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Zondervan <robert@conduction.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress enhancement New feature or request feedback-requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants