Skip to content

fix: save snippets to a table that missed the 4.0.0 upgrade - #620

Merged
sheabunge merged 4 commits into
core-betafrom
fix/table-upgrade-retry/core
Nov 3, 2026
Merged

sheabunge merged 4 commits into
core-betafrom
fix/table-upgrade-retry/core

Conversation

@TallblokeUK

Copy link
Copy Markdown
Contributor

A snippets table that misses the 4.0.0 upgrade lacks the created_by and updated_by columns. Every write then fails: creating a snippet returns rest_cannot_create ("The snippet could not be created."), and editing one reports success while the change is not saved. Each site's version is recorded before its table is upgraded, so a failed upgrade is not retried.

Changes

  • save_snippet(): when an insert or update fails with an unknown-column error, the table is upgraded with DB::create_table() and the write is retried once. Any site's table, or the network table, is repaired by the first save made to it.
  • save_snippet(): a failed update now returns null, so the REST route responds with rest_cannot_update instead of returning the unchanged snippet as if it had been saved. The snippet's lock state is set only once the row is written.
  • New DB::upgrade_after_unknown_column(); DB::create_or_upgrade_tables() now returns whether every table was upgraded.
  • Settings → Advanced → Upgrade Database Table reports the database error when the upgrade fails, instead of always reporting success.

Verification

  • New DB_Test: a save to a table without the authorship columns upgrades it and succeeds, and a later edit is saved; a failed update returns null and leaves the stored code unchanged; create_or_upgrade_tables() reports success.
  • Full PHPUnit suite and PHPCS pass locally on core-beta.
  • On a local site with updated_by dropped from the snippets table, 4.0.0 reproduces both symptoms (create returns 500, edit returns 200 without saving). With this change, create succeeds, the edit is saved, and the column is restored.

@sheabunge
sheabunge merged commit b9373ff into core-beta Nov 3, 2026
18 checks passed
@sheabunge
sheabunge deleted the fix/table-upgrade-retry/core branch November 3, 2026 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-tests Trigger automated tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants