A submission draft can now render from an uploaded docforge template
instead of a legacy Gitea base. DB-VERIFIED against TEST_DATABASE_URL (the
head greenlit option C) before commit — not just compiled.
Schema: migration 159 adds submission_drafts.template_version_id (nullable,
FK template_versions ON DELETE SET NULL) — the snapshot pin (PRD A3). A
later template edit creates a new version; the pinned draft keeps rendering
its version.
Draft service: TemplateVersionID on the model + draftColumns + the JOIN
list + DraftPatch (two-level pointer like base_id) + Update SET. Column-sync
verified live (Create_seeds_section_rows + the new pin test both pass).
Export/preview (handlers): a template-version path checked FIRST — load the
carrier via TemplateStore.GetVersion, render via the existing Export/
RenderPreview (the carrier already carries {{slots}}; no Composer/sections
needed). Falls through to base_id / v1 if the pin is missing. Both preview
sites + the view assembly branch on it.
Store: TemplateMeta.VersionID exposes the current version's row id (slice-4
gap — a consumer needs it to pin); populated in List/Get/GetVersion + the
authoring JSON. New GET /api/templates (authenticated, firm-filtered) is the
picker list any lawyer reads; admin authoring endpoints stay gated.
Frontend: the submission editor's base picker now offers uploaded templates
as a 'tpl:<version_id>' optgroup; selecting one PATCHes template_version_id
(clearing base_id) and vice versa — mutually exclusive render paths.
Live test (submission_draft_template_live_test.go, gated): pin round-trips
Update→Get, the uploaded carrier renders ({{firm.name}}→HLC via Export), and
clearing nulls it — all PASS against real Postgres.
Verification: go build/vet/gofmt clean; bun build + bun test 274/274; slice-7
+ slice-4 store + draft/composer live tests PASS against TEST_DATABASE_URL.
Pre-existing env failures (approval/projection seed $1-type quirk,
migration136 stale deadline_rules table) are unrelated — confirmed my branch
touches none of that code.
m/paliad#157
29 lines
1.4 KiB
SQL
29 lines
1.4 KiB
SQL
-- t-paliad-349 (m/paliad#157): docforge slice 7 — pin an uploaded template
|
|
-- version onto a submission draft (generation-on-uploaded-templates).
|
|
--
|
|
-- A draft can now source its document from a docforge uploaded template
|
|
-- (paliad.template_versions) instead of a legacy Gitea base. template_version_id
|
|
-- is the snapshot pin (PRD §4 A3): the draft renders the exact carrier of the
|
|
-- version it was bound to, so a later template edit (which creates a new
|
|
-- version) doesn't shift an in-flight draft.
|
|
--
|
|
-- Nullable + additive: existing drafts keep template_version_id NULL and
|
|
-- render via their existing path (Composer base_id, or the v1 fallback).
|
|
-- The three sources are mutually exclusive in practice; the export path
|
|
-- checks template_version_id first, then base_id, then v1.
|
|
--
|
|
-- ON DELETE SET NULL: if the pinned version is removed, the draft detaches
|
|
-- and falls back rather than failing — same posture as base_id's
|
|
-- ON DELETE SET NULL.
|
|
|
|
ALTER TABLE paliad.submission_drafts
|
|
ADD COLUMN IF NOT EXISTS template_version_id uuid
|
|
REFERENCES paliad.template_versions(id) ON DELETE SET NULL;
|
|
|
|
CREATE INDEX IF NOT EXISTS submission_drafts_template_version_idx
|
|
ON paliad.submission_drafts (template_version_id)
|
|
WHERE template_version_id IS NOT NULL;
|
|
|
|
COMMENT ON COLUMN paliad.submission_drafts.template_version_id IS
|
|
't-paliad-349: pinned docforge template version (snapshot-at-create). NULL = render via base_id Composer path or v1 fallback.';
|