Skip to content

feat(pages): store grid pages and their widgets relationally (#3100, step 1) - #46

Open
rubenvdlinde wants to merge 3 commits into
main-forkedfrom
stack/r1-page-model
Open

rubenvdlinde wants to merge 3 commits into
main-forkedfrom
stack/r1-page-model

Conversation

@rubenvdlinde

@rubenvdlinde rubenvdlinde commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Step 1 of the page rework on the data model of nextcloud#3100 (follows the review on nextcloud#3075). No API or UI yet.

What

  • tables_contexts_page gets title, emoji, description (nullable) and an index on context_id; Page::TYPE_GRID.
  • New tables tables_contexts_widget (page_id, type, title, grid_x/y/width/height, settings) and tables_contexts_widget_source (PK widget_id, index node_rel_id), with entities and mappers.
  • WidgetService reads widgets with their settings and source and writes them. Settings live in the widget row as one JSON object (see below).
  • Deleting an application deletes its pages' widgets, settings and sources. Deleting a table or view, or removing a node from the application, deletes only the widget_source rows: the widget stays.
  • Context responses list the page title, emoji and description. A grid page without start page rows no longer gets an empty content entry from the mapper's join.
  • Scheme export (getScheme) and the user migration export carry each page's widgets; importContext() imports them and remaps the source through the existing $nodeRelMap (a source whose node was not imported is dropped).
  • App version 2.4.0-dev.9. tables_contexts_page_content and node_rel_id are unchanged.

nextcloud#3100 points covered

Schema (all of it), "deleting a page or an application deletes its widgets, settings and sources", "removing a table or view deletes only the source row", "scheme export and import copy widgets, settings and sources". Saving and the API follow in the next PR.

Tests (Nextcloud 34, PostgreSQL 16, in the container)

  • tests/unit/Service/WidgetServiceTest.php (real DB): OK (5 tests, 13 assertions)
  • tests/unit/Db/ContextMapperTest.php (real DB): OK (1 test, 5 assertions)
  • tests/unit/Service/ContextPagesRoundTripTest.php (real DB, export, import, node removal, application deletion): OK (2 tests, 10 assertions)
  • tests/unit/Service/ContextServiceTest.php: OK (6 tests, 18 assertions)
  • tests/unit/TablesMigratorTest.php: OK (12 tests, 20 assertions)
  • whole unit suite: OK (370 tests, 723 assertions)
  • composer cs:check: no files; psalm: no errors.

Settings in one JSON column (agreed with enjeck, 22 Oct)

This follows nextcloud#3100 except for one point: widget settings are one JSON column on the widget, not one row per setting, so tables_contexts_widget_setting is gone.

  • tables_contexts_widget.settings: TEXT, nullable. Widget::getSettingsArray() / setSettingsArray() decode and encode it, as View does for its JSON columns. A save writes {} when there are no settings, because an entity setter given the value it already holds does not mark the field changed, so writing NULL would leave old settings in place on an update. NULL (or anything that is not a JSON object) reads as no settings. A nullable column is needed because NOT NULL on an existing table with rows needs a default, which TEXT does not take on every database.
  • GridWidgetTypes::sanitizeSettings still runs on every save, so the JSON only holds known, typed settings. API response shape and OpenAPI are unchanged (no drift from generate-spec); an empty map still serialises as [].
  • Version2400Date20261016000001 now creates the column and no settings table. For instances that ran the earlier version: Version2400Date20261022000001 adds the column if missing and, if the old table exists, copies its rows into each widget (each value JSON-decoded, one object per widget, written once, only where settings is still NULL); Version2400Date20261022000002 drops the old table. The drop is a separate step because a step applies its changeSchema before its own postSchemaChange, so a copy and a drop in one step would drop the rows first. Both are no-ops on a fresh install and on a second run.
  • App versions along the stack, so every head runs the new steps: r1 to r4 2.4.0-dev.9, r5/r6 dev.10, stack-5-main and s1 to s4 dev.11, s5/s6 dev.12.
  • Tests (Nextcloud 34, PostgreSQL 16, in the container), on this branch:
    • tests/unit/Db/WidgetTest.php (new): OK (4 tests, 10 assertions)
    • tests/unit/Migration/WidgetSettingsToJsonMigrationTest.php (new, real DB: rows to JSON, table dropped, second run unchanged, instance without the table untouched): OK (2 tests, 8 assertions)
    • tests/unit/Service/WidgetServiceTest.php (settings on the widget row, WidgetSetting/WidgetSettingMapper and their tests removed): OK (4 tests, 15 assertions)
    • tests/unit/Service/ContextPagesRoundTripTest.php: OK (2 tests, 10 assertions); ContextServiceTest: OK (6 tests, 18 assertions); TablesMigratorTest: OK (12 tests, 20 assertions)
    • whole unit suite: OK (374 tests, 742 assertions); composer cs:check: no files; psalm: no errors; generate-spec: no drift.
    • At the top of the stack (s6): whole unit suite OK (566 tests, 1202 assertions); Playwright context-grid-pages, application, tables-import-export-scheme at 1600 px: 24 passed.
    • Real upgrade: a demo instance that had run the earlier r1 (5 widgets, 11 setting rows) upgraded to s6; the API responses of both pages are byte-identical before and after, and oc_tables_contexts_widget_setting no longer exists.

Prepared in the Conduction fork for porting upstream by @remko48. Prepared with Claude Code.

Adds the data model of nextcloud#3100: pages get a title, emoji and
description and the grid page type; widgets, their settings and the node a
data widget shows live in tables_contexts_widget, tables_contexts_widget_setting
and tables_contexts_widget_source. Deleting an application or page deletes
its widgets; removing a node deletes only the widget sources. Scheme and
user migration export carry the widgets, import remaps their node.

Assisted-by: ClaudeCode:claude-opus-5-5
Widget settings move from one row per setting in
tables_contexts_widget_setting to one JSON object in
tables_contexts_widget.settings, as agreed with enjeck on 22 Oct. The rest of
the nextcloud#3100 data model stays.

The first grid page migration now creates the settings column and no
settings table. Version2400Date20261022000001 adds the column on instances
that ran the earlier version and copies the setting rows into it;
Version2400Date20261022000002 drops the old table afterwards. The app
version goes to 2.4.0-dev.9 so these run.

Assisted-by: ClaudeCode:claude-opus-5-5
An entity setter that receives the value the entity already holds does not
mark the field as changed, so saving a widget with no settings over one
that had some left the old JSON in place. Writing `{}` makes the update
clear them.

Assisted-by: ClaudeCode:claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant