Skip to content

Migration cleanup: drop hand-rolled test DDL, swap to ensure_current/2#7

Merged
ddon merged 2 commits into
BeamLabEU:mainfrom
mdon:migration-cleanup
May 5, 2026
Merged

Migration cleanup: drop hand-rolled test DDL, swap to ensure_current/2#7
ddon merged 2 commits into
BeamLabEU:mainfrom
mdon:migration-cleanup

Conversation

@mdon
Copy link
Copy Markdown
Contributor

@mdon mdon commented May 5, 2026

Summary

Replace the inline DDL (uuid_generate_v7 fn, phoenix_kit_activities stub, phoenix_kit_settings stub) plus the Ecto.Migrator.up(TestRepo, 0, PhoenixKitSync.Migration, ...) call in test/test_helper.exs with PhoenixKit.Migration.ensure_current/2 (core 1.7.105+ / phoenix_kit#515). Schema drift between test and prod is impossible by construction.

Sync tables are owned by core (V37 creates them as phoenix_kit_db_sync_*; V44 renames to phoenix_kit_sync_*; V56/V58/V61/V73/V74 evolve them). phoenix_kit_settings (V03), phoenix_kit_activities (V90), and the uuid_generate_v7 function (V40) are also owned by core.

Should be merged after BeamLabEU/phoenix_kit#515 — CI will be red until core 1.7.105 publishes.

Quality follow-ups bundled (commit e6127ac)

The migration-cleanup commit surfaced two pre-existing test failures (committed in 7916940 with no DB-verified runs). Both fixed in this PR rather than punted:

  • F1 Iron Law gatehandle_params/3's catch-all handle_action clause was calling load_connections/1 unconditionally; the original F1 fix only gated mount/3. Swap to maybe_load_connections/1 so the dead render seeds empty assigns and the doubled DB queries + async HTTP fan-out only fire on the live phase. The existing dead-render test now passes.
  • F4 revoke test rework — the revoke button only renders in the connection detail view (connections_live.ex:1940), not the list. Updated the test to mount directly into the detail view via ?action=show&id=<uuid> (where the show_connection push_patch lands) before clicking revoke. Now pins the gettext-wrapped persisted reason as intended.

Files touched

File Change
test/test_helper.exs Drop ~75 lines of inline DDL + Ecto.Migrator.up(_, 0, PhoenixKitSync.Migration, _); replace with PhoenixKit.Migration.ensure_current/2
lib/phoenix_kit_sync/web/connections_live.ex Gate catch-all handle_action with maybe_load_connections/1 (F1 follow-up)
test/phoenix_kit_sync/web/connections_live_test.exs Unskip F1 + rework F4 to mount directly into detail view
AGENTS.md Database & Migrations / Testing sections refreshed

Verification

Local test suite via phoenix_kit_parent path-dep override resolving to local core 1.7.104+:

  • mix test — 587 tests, 0 failures, 0 skipped
  • 3 consecutive stable runs

Test plan

  • mix test — 587 tests, 0 failures, 0 skipped
  • 3 consecutive stable runs
  • Fresh dropdb && createdb before run
  • CI greens after core 1.7.105 publishes

mdon added 2 commits May 5, 2026 07:15
Replace the inline DDL (uuid_generate_v7 fn, phoenix_kit_activities
stub, phoenix_kit_settings stub) plus the
`Ecto.Migrator.up(TestRepo, 0, PhoenixKitSync.Migration, ...)` call
in `test/test_helper.exs` with `PhoenixKit.Migration.ensure_current/2`
(core 1.7.105+ / phoenix_kit#515).

Sync tables are owned by core (V37 creates them as `phoenix_kit_db_sync_*`;
V44 renames to `phoenix_kit_sync_*`; V56/V58/V61/V73/V74 evolve them).
phoenix_kit_settings (V03), phoenix_kit_activities (V90), and the
uuid_generate_v7 function (V40) are also owned by core. Schema drift
between test and prod is impossible by construction.

Two pre-existing test failures surfaced — both committed in 7916940
("PR BeamLabEU#5 follow-up bundle (F1–F4)") whose own message admits "DB
tests will be exercised by the next full mix test run on a host with
the test DB available". The old inline DDL had been masking the
real LV behavior. Both skipped with `@tag :skip` and clear comments
naming the bug + intended fix; out of migration-cleanup scope:

- F1 Iron Law dead-render test — `handle_params/3`'s catch-all
  `handle_action` clause calls `load_connections/1` unconditionally,
  bypassing the `connected?` gate that F1 added to `mount/3`. Needs
  a one-line LV fix: swap `load_connections()` →
  `maybe_load_connections()` in `connections_live.ex:106`.
- F4 revoke gettext test — looks for `[phx-click='revoke_connection']`
  in the list view, but the revoke button only exists in the connection
  detail view (`connections_live.ex:1940`). Test needs a navigate-then-
  click flow or a context-layer pin.

Companion edits:
- `AGENTS.md`: Database & Migrations / Testing sections updated.

Depends on BeamLabEU/phoenix_kit#515 — CI will be red until core
1.7.105 publishes.
Bundle the two follow-ups from the migration-cleanup batch's
documented skips into the same PR per workspace request to land
quality fixes that are within reach.

F1 Iron Law gate
  `handle_params/3`'s catch-all `handle_action` clause was calling
  `load_connections/1` unconditionally — the original F1 fix only
  gated `mount/3`. Swap to `maybe_load_connections/1` so the dead
  render path also seeds empty assigns and the doubled DB queries +
  async sender-status / receiver-verification HTTP calls only fire
  on the live phase. Pinned by the existing
  "dead render does not include connection names from the DB" test
  which is now unskipped.

F4 revoke test rework
  The revoke button only renders in the connection detail view
  (connections_live.ex:1940), not in the list. The original test
  asserted on the list view and never passed. Mount directly into
  the detail view via the URL the `show_connection` push_patch
  would land on (`?action=show&id=<uuid>`), then click revoke. Now
  pins the gettext-wrapped reason as intended.
@ddon ddon merged commit 0658557 into BeamLabEU:main May 5, 2026
ddon added a commit that referenced this pull request May 5, 2026
handle_params/3 fires on both the dead render and the connected phase.
The "show", "edit", and "sync" clauses each called
Connections.get_connection/1 unconditionally, so a deep-linked URL
(?action=show&id=<uuid>) ran the query in dead render — and on the nil
branch, fanned out load_connections (the same DB+async-HTTP fan-out the
F1 fix at maybe_load_connections/1 was specifically eliminating).

Replace the three handle_action clauses for show/edit/sync with one
connected?-gated dispatcher + a dispatch_resource_action/3 helper. Mount
already seeds safe list-view assigns via maybe_load_connections/1, so
the dead-render no-op is render-safe; the connected phase re-fires
handle_params/3 and resolves the action. The nil-branch
load_connections/1 calls in handle_connection_action/3 and
handle_sync_action/2 are now implicitly gated since their parents only
run on connected sockets.

Pinning (connections_live_test.exs):
- dead render of ?action=show&id=<uuid> does not include connection
  name (Phoenix.ConnTest.get/2; mirrors existing F1 dead-render test)
- dead render of ?action=edit&id=<uuid> does not include connection name
- live render of ?action=show&id=<uuid> *does* include connection name
  (pins the gate is connected?-conditional, not "never load")

Surfaced by PR #7 review (dev_docs/pull_requests/2026/7-migration-cleanup
/CLAUDE_REVIEW.md, finding 3). Pre-existing — not introduced by the
migration-cleanup PR — but the F4 revoke test there now exercises the
deep-link path explicitly, making the gap discoverable.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ddon added a commit that referenced this pull request May 5, 2026
Post-merge review covering the migration-cleanup PR: 4 files, +24/-73,
587/0/0 across 3 stable runs. Approve with one follow-up logged and
fixed on-branch.

Strengths called out: single-source-of-truth schema setup via core's
ensure_current/2 (eliminates schema drift class entirely), correct
F1/F4 fixes that resolve the rows sketched in PR #5's CLAUDE_REVIEW,
the upstream ensure_current/2 design (microsecond-precision Migrator
trick + table-comment short-circuit), good comment locator hygiene at
test_helper.exs:41-56.

Findings:
- (1) merged-with-red-CI process pattern, post-mortem only since core
  1.7.105 has since published and is pinned in mix.lock
- (2) bundled-PR scope creep — nit
- (3) latent Iron Law gap on deep-link entry to ?action=show|edit|sync
  (pre-existing; F4 test surfaced it). FIXED on-branch in the
  preceding commit.
- (4) cosmetic schema_migrations row accumulation per mix test
  invocation — no action

No outstanding follow-ups from this PR.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

2 participants