Posts 0.3.0: Saving a post keeps its slug, and scheduled posts publish once
Posts 0.3.0 fixes two problems on live sites: saving a post could rewrite the slug its author chose, moving a published URL, and a scheduled post could be published twice, with two entries in the activity log.
Slugs stay as the author set them
When a post was saved without a slug of its own in the submitted data, the module made a new one from the title. The admin edit form does exactly this on an ordinary save, because a slug that has not changed is not sent as a change. So editing the title of a published post, or just saving it, could give it a new slug and a new address, and the old slug was not kept anywhere.
The module now tells “no slug was sent” apart from “the post has no slug yet”, and only makes one in the second case. Tags and groups had the same fault with their names and are fixed too.
Scheduled posts are published once
Scheduled posts are published by two jobs: the module’s own and PhoenixKit core’s catch-up job, on separate schedules. Both could take the same post and each believe it had published it, so the activity log got two publish entries for one post. The check now happens in the database in one step, so only one of them publishes, and the other finds the post already done without counting it as a failure.
A scheduled publish also no longer goes through when the author has moved the post back to draft in the meantime. The publish buttons in the admin still publish a draft as before.
Smaller changes
The admin forms (posts, groups and settings) use daisyUI 5’s form markup.
Upgrading
No migration and no configuration. The PhoenixKit requirement stays at 2.0 or later.
Full release notes: Posts 0.3.0
0.3.0 · 14 August 2026
Fixed
-
Publishing or editing a post rewrote a slug the author had chosen, moving a live URL.
maybe_generate_slug/1askedget_change(:slug), which isnilboth when the caller left the slug alone and when the record hasn’t got one — so any save carrying no slug of its own re-derived it from the title, and the old slug was recorded nowhere. The admin edit form makes this ordinary rather than exotic: it repopulates"slug" => post.slug, andcast/3drops a value equal to the data, so it arrives looking identical to no slug at all.fetch_change/2separates the two.PostTagandPostGroupcarried the same helper against:nameand are fixed with it (#17). -
Two callers could both publish the same scheduled post, and both log it. The guard read
post.status— the copy in the caller’s hand — so two callers each holding a struct that still said"scheduled"both believed they had made the transition, writing two activity rows and two broadcasts. Two callers is the normal case:process_scheduled_posts/0runs from this module’s cron worker and from core’sProcessScheduledJobsWorkercatch-up, on separate schedules in separate queues — no cluster or unlucky timing required.The predicate now lives in the
WHEREof a singleupdate_all, so the database settles it. The loser is reloaded and returned{:ok, current}rather than an error, becausescheduled_post_handler.exturns{:error, _}into a permanently failed job and a no-op is not a failure. -
The test harness could not reach a database on a role without
CREATEDB, and reported success anyway.config/test.exshardcoded the database name and read noPGDATABASE, unlike every sibling module and core. Where the database was unreachable,test_helper.exsexcluded all 18:integrationtests — which is where the slug and atomic-publish regressions live — and the run still exited 0.PGDATABASE/PGPOOLare now honoured, with the previous name as the fallback so CI is unaffected.
Added
- A database test harness.
test_helper.exswasExUnit.start()andconfig/test.exsconfigured no repo, so nothing in the context layer could be exercised. That was not a neutral gap: every context function here rescues its own DB errors and returns a plausible nothing, so a repo-less suite did not fail — it passed while asserting the rescue. Posts tables come from core’s versioned chain, so the schema is built byPhoenixKit.Migration.ensure_current/2, the same call a host makes.
Changed
publish_post/2takes:only_if— the statuses it may publish from. It defaults wide, because the admin Publish button legitimately publishes a draft; the scheduled sweep and the Oban handler pass["scheduled"]so a post the author has since moved back to draft is not published by a retry.- Dependency updates:
phoenix_kit2.4.0. The~> 2.0pin is unchanged — this release keeps its local slug helper and callsSlug.ensure_unique/2, which has existed since core 2.0, rather than adopting core 2.4.0’s newput_slug/3.
Posts 0.3.0. Install or update: {:phoenix_kit_posts, "~> 0.3"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.