BlogEngine.Posts.Revisions (blog_engine v0.1.0)

Copy Markdown View Source

Working-revision writes for posts.

Explicit nil attribute policy

Attribute maps distinguish an absent key from a key whose value is nil.

  • An absent key never reaches the changeset, so the stored column is left untouched.
  • An explicit nil clears the column only for the fields listed in [:excerpt, :featured_image_url, :featured_image_alt, :reading_time_minutes, :publish_at], which are exactly the nullable optional revision columns. This is what makes a scheduled publish_at unschedulable.
  • An explicit nil for any other field (including tag_ids, featured, and the required content fields) is ignored exactly as if the key had been omitted. That keeps tag_ids: nil meaning "keep the current tags" and keeps NOT NULL columns such as featured on their stored value or schema default.

Summary

Types

Successful update_working/7 payload.

Failure reason returned by revision writes.

Types

edit()

@type edit() :: %{
  blog: BlogEngine.Schema.Blog.t(),
  before: BlogEngine.Schema.Post.t(),
  post: BlogEngine.Schema.Post.t(),
  revision: BlogEngine.Schema.PostRevision.t(),
  route_changed?: boolean()
}

Successful update_working/7 payload.

failure()

@type failure() :: BlogEngine.Error.t() | Ecto.Changeset.t()

Failure reason returned by revision writes.

Functions

update_working(repo, context, blog_id, post_id, attrs, allow_archived? \\ false, authorize_transition \\ fn _post -> :ok end)

@spec update_working(
  module(),
  BlogEngine.Context.t(),
  Ecto.UUID.t(),
  Ecto.UUID.t(),
  map(),
  boolean(),
  (BlogEngine.Schema.Post.t() -> :ok | {:error, failure()})
) :: {:ok, edit()} | {:error, failure()}

Rewrites (or clones) the working revision of a post.

The active-author requirement only applies when attrs supplies an :author_id that differs from the current working source. Editing content without reassigning authorship therefore keeps working after the original author is deactivated. Reassigning to a deactivated same-tenant author fails with :author_inactive; an unknown or foreign-tenant author fails with :not_found.

See the module documentation for how explicit nil attribute values are interpreted.