Skip to content

UUIDs for rows #3093

Open
Open

Description

@rjzondervan

Is your feature request related to a problem? Please describe.

Tables, columns, views and selection options all already have uuid in the current status, while rows only have incremental identifiers. These incremental integers are local to one instance. That would break references that have to survive exports, imports, packaging and federated relations (relations to other instances). Also, without uuid the api v2 does not have a stable identifier for row routes, while the project plan identifies rows by their uuid.

Describe the solution you'd like

We would like to add a uuid-column to the tables_row_sleeves table of the type STRING(36) with UUIDv7 format (consistent with tables, columns and views). They are time ordered, so they insert well into a btree. The column is immutable once assigned, following the pattern that is used for tables.

That would mean we also add a global unique index on the uuid column so relations still are unique for every row, not only per table. Usually it should not happen that two rows get assigned the same uuid, that’s rather the point of the uuid, but preventing collisions from happening is not a bad idea. The uuid should be assigned on every path possible to create a row, so in the createNewRowSleeve, createRowSleeveFromExistingData, importRow, but also every other possible way of creating a row, hence this must be done in the RowSleeve entity, like it is done in Table, and on the importRow where the uuid must be set explicitly as the export might contain the uuid to use, but if not it shoud generate a new uuid.

This also means we need a backfill for existing rows, I would propose to do that in a batched background job, in order to not black out the table for a long time when there are millions of rows involved. This means that as long as there are objects without uuids, responses will contain uuid=null values, lookups by uuid for those rows will return a 404, and that we can only set a NOT NULL guard on the column when all rows have received their UUID.

Also, we would need a lookup in the RowSleeveMapper and Row2Mapper to lookup rows by uuid, which then can also be leveraged by the api/2 for fetching a row by uuid. The uuid should also show up in the metadata block of the row when calling it over API v2, and the ResponseDefinitions.php and OpenAPI document should be regenerated.

After this we would like to add an api/2 route for fetching rows by the pattern defined in RowOCSController: (/api/2/{tables|views}/{nodeId}/rows/{rowId}, this needs a GET for both uuid and integer id, as this route does not exist yet, with additionally adding the uuid-option to the PUT and DELETE routes by making the service accept both id and uuid for the row lookup by resolving the identifier to the incremental id on entry. This has the added benefit of having the possibility to leverage the existing #[RequirePermission(…, typeParam: 'nodeCollection')] logic for the permissions on a table. The uuid lookup will also be limited to the table or view in the path, so a uuid from another table will give the same 404 error as a non-existent one. Federated tables will for now keep forwarding by integer id, a uuid on a federated table gives a 400, but this gives the possibility to later switch them over to uuid. In the OpenAPI the rowId switches from int to string with integer or uuid format, which will show up in the specification of existing routes. For the shape of responses see the issues for the rows v2 api (listing and object shape).

When exporting and importing a row, at first an attempt should be made to keep the uuid on import, and only if that is not possible (because for example the uuid has already been used, but for another table with different definitions), a new uuid is generated.

Acceptance Criteria

  • Every new row gets a uuid, whatever the creation path
  • After backfill no sleeve has an empty uuid
  • The uuid does not change on updates
  • The unique index exists
  • The CI is green on all four databases
  • The upgrade time on the benchmark table is measured and recorded
  • GET, PUT and DELETE on /api/2/{tables|views}/{nodeId}/rows/{rowId} accept both an integer id and a uuid and behave the same, including permissions for view-only users

Describe alternatives you've considered

We considered to make the uuid column unique on the combination (table_id, uuid) as for columns, but for relations all rows need to have a unique id.

Also we considered uuid v4, but that would mean unordered spread across the index, while v7 keeps everything in order.

We did reject the option to do the backfill with the migration, as it could lock a Nextcloud instance with large tables for an extended amount of time, while generating the uuids by the database would not port to all database types and versions as well as we would like.

Finally, we considered a /api/2/rows/{uuid} path, but this was rejected as the api v2 already proposes the shape with table/view in the route, combined with the added complexity of having an ambiguous permission context when only looking up a row by uuid.

Additional context

Relevant files:
  • lib/Migration/Version2020Date20260513185340.php (the precedent);
  • lib/Db/Table.php (the uuid pattern);
  • lib/Db/RowSleeve.php, lib/Db/RowSleeveMapper.php, lib/Db/Row2Mapper.php;
  • lib/Service/RowService.php;
  • lib/UserMigration/TablesMigrator.php.
Related issues

This blocks the CRUD (technicalName) routes issue. This also comes before the relations by uuid and manifest export (issues yet to be filed).

Activity

  1. added
    enhancement
    0. Needs triage
    on Oct 14, 2026
  2. enjeck commented on Oct 30, 2026

    @enjeck
    Contributor

    sounds good!

  3. rjzondervan commented on Nov 24, 2026

    @rjzondervan
    ContributorAuthor

    In the PR review of @foolfitz's PR #3229 a discussion was started about routing to objects using the added UUIDs.

    I've looked into the plan (and also let my Claude look into it to be sure I didn't miss something), and as far as we can see, it works for us to contain UUID routing to routes within the context of contexts/applications.

    There are however 2 caveats, and they are mostly concerning #3096: if we have relations addressed by UUIDs, we would need some more work to follow the references from the 'pure' api when the reference is done by UUID. (The agent came back with relations outside of the application. I would argue that it is not good practice to relate within an application to a table or view outside of it).

    The other caveat is mostly to check if the row is accessed directly from the table or through a view. I would argue that that logic should be in the service (as it is some complexity) rather than in the controller, but that's coding details that we can figure out.

  4. blizzz commented on Nov 26, 2026

    @blizzz
    Member

    I also left the note in the other PR:

    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).

    Only exception is when some sort of discovery is needed, then with a dedicated endpoint (and legitimacy ensured).

    Hence, I'd disregard any UUIDs compatibility added to any API endpoints (unless required for import/export, deployment, discovery if really necessary; and then with dedicated endpoints). On Service levels they make sense, and preferred in additional method to not bloat up existing methods. Clean code approach.

  5. blizzz commented on Nov 26, 2026

    @blizzz
    Member

    As discussed:

    • endpoints shall be untangled, where UUID-based endpoints are truly necessary, an own endpoint shall be used. They'll be collected into reasonable endpoint path naming
    • they are also subject the permission middleware (through the attributes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0. Needs triageenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions