# `PhoenixKit.Migrations.Postgres.V117`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.165/lib/phoenix_kit/migrations/postgres/v117.ex#L1)

V117: Document composition — template category, document sections, template presets.

Three schema changes for the document composition feature:

1. ALTER `phoenix_kit_doc_templates` — adds a nullable `category :: varchar`
   column and an index on `(category)` for category-filtered queries.

2. CREATE `phoenix_kit_doc_document_sections` — join table between documents
   and templates for multi-section composed documents. Each row represents one
   template-backed section at a specific position within a document. Supports
   per-section variable overrides (`variable_values`) and image configuration
   (`image_params`). Positions are unique per document; deleting a document
   cascades to its sections. Nullifying a template FK on delete allows the
   section to survive template removal (content would need regeneration).

3. CREATE `phoenix_kit_doc_template_presets` — named, reusable compositions of
   template sections. Presets are scoped via `scope_type` + `scope_id` (e.g.
   `"organization"` + org uuid) and optionally categorized. The `sections`
   JSONB column stores an ordered array of section descriptors
   (`[%{template_uuid, position, variable_values, image_params}]`).

All operations use `IF NOT EXISTS` guards so re-running `up/1` on a
partially-applied schema is a no-op.

`down/1` is destructive for the `category` column: dropping it deletes any
values users have assigned. The two new tables drop cleanly (re-running
`up/1` recreates them empty), but column data is lost on rollback by
design — `Ecto.Migration`'s rollback contract has no way to preserve it.

# `down`

# `up`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
