PhoenixKitDocumentCreator.Schemas.Template (PhoenixKitDocumentCreator v0.6.0)

Copy Markdown View Source

Schema for document templates.

Templates are now managed as Google Docs in Google Drive. The google_doc_id field links a template record to its Google Doc. Variables use {{ placeholder }} syntax and are substituted via the Google Docs API.

Note: Several fields (content_html, content_css, content_native, header/footer associations) are retained for database compatibility but are no longer used in the Google Docs workflow. A future migration should remove these columns.

Deprecated taxonomy columns (do not drop)

As of migration chain V2, a template's category/group membership is a many-to-many relation stored in phoenix_kit_doc_template_taxonomy (see PhoenixKitDocumentCreator.Schemas.TemplateTaxonomy). The two single-binding columns below are deprecated but deliberately kept and kept populated as a mirror of the primary membership so the ANDI consumer keeps working until it migrates to the join table:

  • category_uuid — mirror of the lowest-Category.position active membership
  • type_uuid — that membership's group (nulled when the group is soft-deleted)

The mirror is recomputed whenever memberships are written (Taxonomy.set_template_memberships/3) and on category/type soft-delete and restore (trash_category/restore_category/trash_type/restore_type recompute it from the surviving active memberships). As long as it is kept in sync this way — the normal write path, an invariant enforced by tests — it does not point at a trashed category/group.

Permanent deletion is the one best-effort gap, driven by the join table's own foreign keys rather than a recompute: deleting a category cascades the membership row away (ON DELETE CASCADE), while deleting a type nulls that row's type_uuid (ON DELETE SET NULL). Either way the mirror is only brought back in line lazily, on the template's next membership write; until then a multi-category template may keep a stale/nil mirror. The join table stays authoritative.

Both columns are stamped with a deprecation COMMENT in the database (V2). They must not be dropped without a coordinated ANDI migration; a later chain version will remove them once ANDI reads memberships directly.

Summary

Functions

Focused changeset for setting/clearing the locale tag on a template.

Changeset for upserting from Google Drive sync data.

Types

t()

@type t() :: %PhoenixKitDocumentCreator.Schemas.Template{
  __meta__: term(),
  category: term(),
  category_uuid: term(),
  config: term(),
  content_css: term(),
  content_html: term(),
  content_native: term(),
  created_by_uuid: term(),
  data: term(),
  description: term(),
  folder_id: term(),
  footer: term(),
  footer_uuid: term(),
  google_doc_id: term(),
  header: term(),
  header_uuid: term(),
  inserted_at: term(),
  language: term(),
  name: term(),
  path: term(),
  slug: term(),
  status: term(),
  thumbnail: term(),
  type: term(),
  type_uuid: term(),
  updated_at: term(),
  uuid: term(),
  variables: term()
}

Functions

changeset(template, attrs)

language_changeset(template, attrs)

Focused changeset for setting/clearing the locale tag on a template.

Used by both the create-time language stamp (Documents.create_template/2) and the post-create updater (Documents.update_template_language/3) so both write paths honour validate_length(:language, max: 10) — the prior update_all write skipped this and would surface oversized codes as a Postgrex value too long exception instead of a clean changeset error.

sync_changeset(template, attrs)

Changeset for upserting from Google Drive sync data.