PhoenixKit 1.7.231: Case-insensitive usernames and shareable list URLs
PhoenixKit 1.7.231 makes usernames case-insensitive, so Pavel and pavel can no longer be two accounts, and keeps search and filters of several admin lists in the address bar.
Two accounts differing only in username case could exist, and then signing in by username failed with an error for both. Migration V161 makes the username column case-insensitive, which also makes username sign-in use its index.
The Users, Sessions, Live Sessions and Jobs lists and the media selector now keep their search, filter, sort and page in the URL, so a filtered list can be shared, survives a reload, and the Back button returns to the previous query. Migration V162 lets a billing order record which payment option the customer chose. Utils.Slug.slugify/2 gets a transliterate: true option for Russian and Ukrainian titles.
Upgrading
Run mix phoenix_kit.update to apply V161 and V162. V161 refuses to run if two usernames differ only by case and names the value: rename or merge those accounts, then run it again.
Full release notes: PhoenixKit 1.7.231
1.7.231 · 5 August 2026
⚠️ Two new migrations (V161, V162) — run mix phoenix_kit.update. V161
converts phoenix_kit_users.username to citext and refuses to run if
your database already holds usernames differing only by case; it names the
offending value so you can rename or merge the accounts, then re-run.
Added
-
PhoenixKitWeb.Live.UrlState— URL-backed search, filter, sort and page for list LiveViews (#680). Typing in a list’s search box filtered the table but left the address bar untouched on most admin screens: the result could not be shared, did not survive a reload, and Back walked out of the page instead of back to the previous query. A workspace audit found 26 LiveViews with that defect and seven independently hand-rolled fixes on the screens that did work — six of which rebuilt the path from a literal, so a LiveView reachable at more than one route patched itself to the wrong page.Declare the state, implement
handle_url_state/2, push changes withpush_url_state/3. Params are keyed by assign name withurl_key:naming the query key separately, so adopting it touches no templates (users.html.heex, 700 lines, needed no edit). Values equal to their default are dropped from the query, so an unfiltered list stays/admin/users.cast:/in:whitelist values and no atom is ever created from user input; integer params carry a default ceiling of 1,000,000 so a crafted?page=cannot reach Ecto as anOFFSETthat overflows PostgreSQL’sbigint. The path comes from the liveuri, unknown query keys are preserved, and the callback runs only on a real change.Converted:
users,sessions,live_sessions,jobs/index,media_selector.⚠️
mode: :patch(the default) makes a LiveView un-embeddable.push_patchrequireshandle_params/3to be exported, and exporting it — whatever its body — makeslive_render/3raise. The two are mutually exclusive in LiveView itself.mode: :historysidesteps both by driving the address bar from a JS hook (<.url_state_sync mode={:history} />) instead of touchinghandle_paramsat all.MediaBrowser.Embed’surl_sync: truehas always carried the:patchconstraint through its injected stub; that is now stated in its moduledoc rather than implied. -
Utils.Sluggains opt-in transliteration (#682). A Cyrillic title slugified to an empty string — every character fell outside[a-z0-9]and was stripped. Callers read empty as “no slug yet”, so a Ukrainian shop’s CSV catalogue could not be matched on re-import and inserted the whole feed again on every run.slugify(text, transliterate: true)maps Russian and Ukrainian Cyrillic to Latin and strips Latin diacritics. Opt-in, so existing callers keep today’s ASCII-only behaviour and a consumer passing the option against an older core gets today’s result rather than an error. -
PhoenixKit.Install.StatusReport— the “what should the operator do next” decision behindmix phoenix_kit.status, extracted so it can be tested without pointing the task at a live database in each of five states.
Fixed
-
⚠️ V161:
phoenix_kit_users.usernameis nowcitext(#681). Two accounts existed in production asPavelandpavel. Nothing prevented it:phoenix_kit_users_username_uidxwas a plain btree on avarcharcolumn,unsafe_validate_uniquecompared exactly, andget_user_by_username/1is a bareRepo.get_by. The mechanism was systematic rather than a fluke —generate_username_from_email/1force-downcases whileensure_unique_username/3checked availability case-sensitively, so a username set manually with a capital was invisible to the generator, which proposed the lowercase form, found it “free”, and added no suffix.Once such a pair existed, login by username 500’d for both accounts: that path already lowercased both sides, so its query matched two rows and
Repo.one/1raisedEcto.MultipleResultsError. (An earlier draft of this entry described the symptom as landing in the wrong account; the failure was a hard error, not a silent cross-account login.emailwas unaffected — it has beencitextsince V01.)Postgres decides comparison semantics from the column type, so one
ALTERfixes uniqueness and every lookup, including a bareRepo.get_by. A functional unique index onlower(username)would have fixed only the constraint and left every read exact-match.varchar → citextis binary-coercible, so there is no table rewrite; the column’s index is rebuilt, which is what makes it start rejecting case variants. -
Username login no longer sequentially scans the users table.
get_user_by_email_or_username_and_password/3hand-rolled its case folding asfragment("LOWER(?)", u.username), which matches no index in the chain — there is no functional index onlower(username). Now that the column iscitext, plain equality is both correct and index-backed viaphoenix_kit_users_username_uidx. This was the only username lookup in the codebase still scanning, on the one endpoint reachable without authenticating. -
V162: payment-option linkage on billing orders (#682). Adds a nullable
payment_option_uuidFK (plus its index) tophoenix_kit_orders, pointing atphoenix_kit_payment_options. An order records how it is to be paid viapayment_method, a small closed vocabulary; what the customer actually chose is a payment-option row, with its own name, instructions, provider and billing-profile requirement. Several options can share onepayment_method(“Bank transfer (EU)” and “Bank transfer (UK)” are bothbank), and an option can be renamed or deactivated after the order is placed. Without a link the choice was discarded at conversion, so an operator processing a bank transfer could not tell which instructions the customer had been shown.ON DELETE SET NULL: deleting a payment option is an ordinary operator action and must neither be blocked by historical orders nor destroy them. -
A tab gated on a sub-permission registers correctly (#682). A module tab may be gated on a sub-permission (
"shop.manage_settings"). Registration pushed that throughregister_custom_key/2, which rejects a dotted key — and the raise aborted the rest of the callback, so the view → permission mapping the admin gate reads was never cached. The module silently fell back to the coarser base key for core’s gate, and every boot logged a failure for a key that was declared correctly. Sub-permissions are already declared throughpermission_metadata/0, so registration now skips them. -
The automatic view gate requires the base of a dotted key (#682). With the dotted key now cached, the admin mount gate resolves one — and it was calling
has_module_access?/2, direct membership only, which by contract leaves the base check to its caller. A scope holding an orphaned"shop.manage_settings"without"shop"would have passed a gate the sidebar,can?/2and every module’s own check all refuse. -
The
PhoenixKitUrlStateJS hook no longer leaks a callback per remount.handleEventregisters on the LiveSocket, not the element, sodestroyed()has to callremoveHandleEvent— it only removed thepopstatelistener.
Changed
mix phoenix_kit.statussays “code expects”, not “update available”. Everything it reports is measured against the version compiled into the running release; it never asks Hex what exists, so it cannot tell you a newer PhoenixKit is out. A version gap is not an optional upgrade being offered — it means the schema disagrees with the code already querying it, which surfaces as runtime errors on whatever the newer version added. When core and a module are both behind, one command fixes both and both reasons are now listed, so re-running does not turn up a second finding that was already knowable.- The test suite can use a database you already have.
config/test.exshardcodedphoenix_kit_test, which forces a role withCREATEDB— exactly what a shared or managed instance withholds.PGDATABASEandPGPOOLnow join thePGHOST/PGUSER/PGPASSWORDthat were already read. Defaults are unchanged. AGENTS.mdno longer claimsmix precommitruns the test suite. It never did, and CI isworkflow_dispatch, so in practice nothing ran the Elixir suite automatically. Addingmix testtoprecommitwas tried and reverted — the suite is not green from a clean checkout (~5 “unit” tests fail with no database, becauseSettingsreads hit the DB on a cache miss), and a permanently red gate teaches people to ignore the gate. The docs now say running the suite is a manual step, and warn thatmix testwith no database excludes every integration test and still exits 0 — the failure mode that matters most when the change is a migration.- Dependency bumps:
etcher0.10.0 → 0.10.2,spitfire0.3.13 → 0.4.0.
Internal
- Post-merge review of #680/#681/#682 with the findings above:
dev_docs/pull_requests/2026/680-682-post-merge-review/CLAUDE_REVIEW.md. test/phoenix_kit/migrations/v162_test.exs— V162 shipped with no test. Pins the column, the FK target, the index, andON DELETE SET NULLspecifically: that is the migration’s whole design decision, and a later refactor reaching for a plainreferences/2would silently make itRESTRICTwith nothing failing.
PhoenixKit 1.7.231. Install or update: {:phoenix_kit, "~> 1.7"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.