PhoenixKit.Modules.Publishing.DBStorage (phoenix_kit v1.7.71)

Copy Markdown View Source

Database storage layer for the Publishing module.

Provides CRUD operations for publishing groups, posts, versions, and contents via PostgreSQL with Ecto.

Summary

Functions

Clears a specific url_slug from all content rows of a post. Returns cleared language codes.

Counts posts by primary language status for a group.

Counts primary language status from an already-loaded list of posts. Avoids re-querying when posts are already available.

Creates content for a version/language.

Creates a publishing group.

Creates a post within a group.

Creates a new version for a post.

Creates a new version by cloning content from a source version.

Deletes a group and all its posts (cascade).

Hard-deletes a post and all its versions/contents (cascade).

Finds content by a previous URL slug (stored in data.previous_url_slugs JSONB array).

Finds content by URL slug across all versions in a group.

Finds a post by date and time (timestamp mode, matches hour:minute only).

Gets content for a specific version and language.

Gets a group by UUID.

Gets a group by slug.

Gets the latest version for a post.

Gets a post by group slug and post slug.

Gets a timestamp-mode post by date and time.

Gets a post by UUID with preloads.

Gets a specific version by post and version number.

Lists all content rows for a version.

Lists all groups ordered by position.

Lists available languages for a version.

Lists posts in a group, optionally filtered by status.

Lists all posts in a group in listing format (excerpt only, no full content).

Lists posts in slug mode (ordered by slug asc).

Lists posts in timestamp mode (ordered by date/time desc).

Lists all posts in a group with their latest version metadata.

Lists all versions for a post, ordered by version number.

Updates all posts in a group to use the given primary language.

Gets the next version number for a post.

Reads a full post with its latest version and content for a specific language.

Reads a timestamp-mode post by date and time instead of slug.

Soft-deletes a post by setting status to 'archived'.

Bulk-updates the status of all content rows for a version, excluding a specific language.

Updates a publishing group.

Updates a post.

Updates a version.

Upserts content by version_id + language.

Upserts a group by slug.

Functions

clear_url_slug_from_post(group_slug, post_slug, url_slug_to_clear)

Clears a specific url_slug from all content rows of a post. Returns cleared language codes.

count_primary_language_status(group_slug, global_primary)

Counts posts by primary language status for a group.

Returns %{current: n, needs_migration: n, needs_backfill: n} where:

  • current — primary_language matches the global setting
  • needs_migration — primary_language is set but differs from global
  • needs_backfill — primary_language is nil

count_primary_language_status_from_posts(posts, global_primary)

Counts primary language status from an already-loaded list of posts. Avoids re-querying when posts are already available.

Posts can be DB structs or legacy maps (with :primary_language key).

create_content(attrs)

Creates content for a version/language.

create_group(attrs)

Creates a publishing group.

create_post(attrs)

Creates a post within a group.

create_version(attrs)

Creates a new version for a post.

create_version_from(post_uuid, source_version_number, opts \\ %{})

Creates a new version by cloning content from a source version.

Creates a new version row and copies all content rows from the source. Wrapped in a transaction for atomicity.

Returns {:ok, %PublishingVersion{}} or {:error, reason}.

delete_group(group)

Deletes a group and all its posts (cascade).

delete_post(post)

Hard-deletes a post and all its versions/contents (cascade).

find_by_previous_url_slug(group_slug, language, url_slug)

Finds content by a previous URL slug (stored in data.previous_url_slugs JSONB array).

find_by_url_slug(group_slug, language, url_slug)

Finds content by URL slug across all versions in a group.

find_post_by_date_time(group_slug, date, time)

Finds a post by date and time (timestamp mode, matches hour:minute only).

get_content(version_uuid, language)

Gets content for a specific version and language.

get_group(uuid)

Gets a group by UUID.

get_group_by_slug(slug)

Gets a group by slug.

get_latest_version(post_uuid)

Gets the latest version for a post.

get_post(group_slug, post_slug)

Gets a post by group slug and post slug.

get_post_by_datetime(group_slug, date, time)

Gets a timestamp-mode post by date and time.

Truncates seconds from the input time since URLs use HH:MM format only, and new posts are stored with seconds zeroed. For legacy posts with non-zero seconds, falls back to hour:minute matching.

get_post_by_uuid(uuid, preloads \\ [])

Gets a post by UUID with preloads.

get_version(post_uuid, version_number)

Gets a specific version by post and version number.

list_contents(version_uuid)

Lists all content rows for a version.

list_groups()

Lists all groups ordered by position.

list_languages(version_uuid)

Lists available languages for a version.

list_posts(group_slug, status \\ nil)

Lists posts in a group, optionally filtered by status.

list_posts_for_listing(group_slug)

Lists all posts in a group in listing format (excerpt only, no full content).

Always uses Mapper.to_listing_map/4 which strips content bodies and includes only excerpts. Designed for caching in :persistent_term where data is copied to the reading process heap — keeping entries small matters.

list_posts_slug_mode(group_slug, status \\ nil)

Lists posts in slug mode (ordered by slug asc).

list_posts_timestamp_mode(group_slug, status \\ nil)

Lists posts in timestamp mode (ordered by date/time desc).

list_posts_with_metadata(group_slug)

Lists all posts in a group with their latest version metadata.

Returns a list of legacy-format maps suitable for listing pages.

list_versions(post_uuid)

Lists all versions for a post, ordered by version number.

migrate_primary_language(group_slug, primary_language)

Updates all posts in a group to use the given primary language.

Returns {:ok, count} with the number of updated posts.

next_version_number(post_uuid)

Gets the next version number for a post.

read_post(group_slug, post_slug, language \\ nil, version_number \\ nil)

Reads a full post with its latest version and content for a specific language.

Returns a map suitable for the legacy mapper or nil if not found.

read_post_by_datetime(group_slug, date, time, language \\ nil, version_number \\ nil)

Reads a timestamp-mode post by date and time instead of slug.

soft_delete_post(post)

Soft-deletes a post by setting status to 'archived'.

update_content(content, attrs)

Updates content.

update_content_status_except(version_uuid, exclude_language, new_status)

Bulk-updates the status of all content rows for a version, excluding a specific language.

update_group(group, attrs)

Updates a publishing group.

update_post(post, attrs)

Updates a post.

update_version(version, attrs)

Updates a version.

upsert_content(attrs)

Upserts content by version_id + language.

upsert_group(attrs)

Upserts a group by slug.