PhoenixKitDocumentCreator.Migrations.Schema (PhoenixKitDocumentCreator v0.6.0)

Copy Markdown View Source

Module-owned versioned migrations for phoenix_kit_document_creator — the decentralized-migrations protocol core's mix phoenix_kit.update discovers via migration_module/0 (current_version/0 + migrated_version_runtime/1 + idempotent up/1 + version-aware down/1). Adopted per the workspace direction of moving module tables out of the core chain (phoenix_kit_projects is the reference implementation; the doc TABLES themselves remain core-created — V86 + V94 — this chain only ITERATES on them).

Versions:

  • V1phoenix_kit_doc_documents.project_uuid (nullable FK → phoenix_kit_projects, ON DELETE SET NULL): real per-project document linkage for the projects hub's Documents tab. The FK target is core-created (V101), present on every current install.
  • V2phoenix_kit_doc_template_taxonomy join table: a template's membership in one category, with an optional group (type_uuid). Replaces the single category_uuid/type_uuid FKs on phoenix_kit_doc_templates with a many-to-many model (a template may belong to several categories, each with its own group). Existing (category_uuid, type_uuid) bindings are backfilled as one row each. The legacy template columns are kept as a compatibility mirror of the primary membership and stamped with a deprecation COMMENT — they must not be dropped until the ANDI consumer migrates.

The migrated version is tracked as a dcr_schema:<N> COMMENT on phoenix_kit_doc_documents (the marker convention from the projects chain, namespaced). A marker-less table reads as version 0 — the core baseline shape before this chain existed.

Summary

Functions

Rolls back to target (version-aware; 0 removes everything this chain added).

The chain version currently applied in the database, read OUTSIDE a migration (the protocol shape core's update task calls — opts with :prefix): the dcr_schema:<N> marker when present; a marker-less or foreign-comment table reads as 0 (core-baseline shape — unlike the projects chain there is no pre-chain content to defend, V1 is purely additive).

Applies every chain version up to current_version/0 (idempotent).

Functions

current_version()

@spec current_version() :: pos_integer()

down(opts \\ [])

Rolls back to target (version-aware; 0 removes everything this chain added).

Ecto wraps each migration's down/1 in a DDL transaction (this chain does not set @disable_ddl_transaction), so the statements below are atomic: a failure rolls the whole rollback back and leaves the dcr_schema marker untouched. The DROP TABLE runs first so a failure never strands a "marker present, table gone" state.

⚠️ Rolling back past V2 destroys all multi-category data. down(target: 1) drops phoenix_kit_doc_template_taxonomy — the source of truth for template memberships. Only the V1 legacy mirror (templates.category_uuid/type_uuid, a single binding per template) survives; every membership a template held beyond its primary one is lost. A subsequent up re-backfills only from that single mirror column.

migrated_version_runtime(opts \\ [])

The chain version currently applied in the database, read OUTSIDE a migration (the protocol shape core's update task calls — opts with :prefix): the dcr_schema:<N> marker when present; a marker-less or foreign-comment table reads as 0 (core-baseline shape — unlike the projects chain there is no pre-chain content to defend, V1 is purely additive).

up(opts \\ [])

Applies every chain version up to current_version/0 (idempotent).