Files
summercms/.planning/todos/done/user-plugin-commands-open-database.md
2026-10-20 23:07:22 +02:00

17 lines
2.2 KiB
Markdown

---
title: Let the sm-user-plugin console commands open their own database
date: 2026-10-07
priority: low
area: sm-user-plugin
---
`user:token:create`, `user:token:list`, `user:token:revoke` (`console/api_tokens.go`) and `user:require-password-change` (`console/require_password_change.go`) only look up a published `*gorm.DB`. The generated application `main` boots the plugins before any command runs, and only `serve`, the `migrate*` commands and the queue commands open and publish the database themselves, so in the real binary these commands stop with `golem15.user: database is not configured` (or `user:require-password-change: database is not configured`). Their tests pass because the test harness publishes the database first.
Found in Phase 14.2 research (gap G1): the same gap stopped `fonoteka:reindex`. Plan 14.2-01 fixed the Fonoteka plugin's own commands (`fonoteka:reindex`, `fonoteka:oauth-client`, `fonoteka:prune-notifications`, and the new `fonoteka:dev-seed`) with a helper that returns the published handle when there is one and otherwise opens `database.dsn` with `lagoon.OpenFromApp` and publishes it with `lagoon.Publish`, so `lagoon.OnDatabase` hooks still run. The seed mints its own API token, so the local stack does not need `user:token:create`.
Suggested fix, in the sm-user-plugin repository: the same published-else-open-and-publish pattern in the user plugin's command helper. It is additive and non-breaking (no route, payload, table, migration ID or config key changes). It is deferred here because sm-user-plugin is a shared core plugin and Phase 14.2 must not modify it; commit and push the plugin first, then bump the submodule pointers in the applications as separate commits. A framework helper (for example in lagoon) that every plugin command can call would remove the duplication; that needs its own decision.
## Done (2026-10-20, Phase 19.5 plan 19.5-01)
Resolved by sm-user-plugin 24b16b1 (`Plugin.withDB` for the token and require-password-change commands) and c43ba87 (plan 19.5-01: `user:backfill-handles` opens its own database with `lagoon.OpenFromApp`). The commands open the database for their run without publishing it, so `lagoon.OnDatabase` hooks do not run for them; a framework helper is still a separate decision.