-- t-paliad-313 (m/paliad#141): Composer Slice A — point submission_drafts at a base.
--
-- Two purely-additive columns on paliad.submission_drafts:
--
--   base_id uuid — FK to paliad.submission_bases. NULL on existing
--     drafts (Slice A explicitly does NOT auto-upgrade pre-Composer
--     rows — that's Slice C). NEW drafts created post-Composer get
--     base_id seeded by SubmissionDraftService.Create from the firm
--     default for the proceeding family. ON DELETE SET NULL keeps a
--     draft renderable via the v1 fallback chain even if its base is
--     removed; the lawyer picks a new base via the sidebar.
--
--   composer_meta jsonb — Composer-specific metadata. For Slice A this
--     carries the seed-time section order so the editor paints without
--     a join. Future slices may add hidden_sections, active_locale,
--     etc.
--
-- No data backfill, no auto-upgrade — pre-Composer drafts keep base_id
-- NULL and render via the existing v1 path. The Go side has the
-- corresponding gate (base_id IS NULL OR no submission_sections rows →
-- v1 path).

ALTER TABLE paliad.submission_drafts
    ADD COLUMN IF NOT EXISTS base_id       uuid REFERENCES paliad.submission_bases(id) ON DELETE SET NULL,
    ADD COLUMN IF NOT EXISTS composer_meta jsonb NOT NULL DEFAULT '{}'::jsonb;

COMMENT ON COLUMN paliad.submission_drafts.base_id IS
    't-paliad-313: Composer base reference. NULL = pre-Composer draft, renders via v1 fallback chain. ON DELETE SET NULL.';

COMMENT ON COLUMN paliad.submission_drafts.composer_meta IS
    't-paliad-313: Composer-side metadata (section_order, hidden_sections, …). jsonb, default {}.';
