Repository navigation
feat(pages): store grid pages and their widgets relationally (#3100, step 1) - #46
Open
rubenvdlinde wants to merge 3 commits into
Open
rubenvdlinde wants to merge 3 commits into
rubenvdlinde wants to merge 3 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_pagegetstitle,emoji,description(nullable) and an index oncontext_id;Page::TYPE_GRID.tables_contexts_widget(page_id, type, title, grid_x/y/width/height,settings) andtables_contexts_widget_source(PK widget_id, index node_rel_id), with entities and mappers.WidgetServicereads widgets with their settings and source and writes them. Settings live in the widget row as one JSON object (see below).widget_sourcerows: the widget stays.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).tables_contexts_page_contentandnode_rel_idare 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)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_settingis gone.tables_contexts_widget.settings: TEXT, nullable.Widget::getSettingsArray()/setSettingsArray()decode and encode it, asViewdoes 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::sanitizeSettingsstill runs on every save, so the JSON only holds known, typed settings. API response shape and OpenAPI are unchanged (no drift fromgenerate-spec); an empty map still serialises as[].Version2400Date20261016000001now creates the column and no settings table. For instances that ran the earlier version:Version2400Date20261022000001adds 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 wheresettingsis still NULL);Version2400Date20261022000002drops the old table. The drop is a separate step because a step applies itschangeSchemabefore its ownpostSchemaChange, 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.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/WidgetSettingMapperand 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)OK (374 tests, 742 assertions);composer cs:check: no files; psalm: no errors;generate-spec: no drift.OK (566 tests, 1202 assertions); Playwrightcontext-grid-pages,application,tables-import-export-schemeat 1600 px: 24 passed.oc_tables_contexts_widget_settingno longer exists.Prepared in the Conduction fork for porting upstream by @remko48. Prepared with Claude Code.