: asapien/signet

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
# Schema upgrades

Run upgrades as the database owner, with the API and worker stopped and a tested
backup. Do not run against a shared/production service without administrator
approval. Test on an isolated database first; fresh installs use schema.sql.

## 001 — submit-time snapshots

Apply `001-submit-snapshots.sql` before installing the snapshot-aware API/worker.
The two nullable columns preserve drafts, completed documents and old history.
The script is additive/idempotent; it does not manufacture old snapshots from
current PIM/DAM values or silently alter a document's attested content.

Before upgrading, drain all pending documents with the old application, or
arrange an explicitly authorised correction/recreation and fresh sign-offs.
Already-pending legacy revisions have no authentic submit-time snapshot. New
workers fail closed rather than rebuilding them from today's attributes/assets.
Do not auto-backfill them or label a current-value backfill historically frozen.
New submits (including authorised corrections) create fresh revision snapshots.

Snapshot storage is private under the document directory: snapshot-<UUID>/ holds
flat asset-N files and the database holds the server-only resolved layout and
asset hashes. The worker also keeps proof-<UUID>.pdf as the revision's immutable
flattened cache; public proof.pdf is a hard link, and initial stamped input is a
byte-identical copy. Retain referenced snapshots/proofs with the database and
source/artifact backups. Restoring files must preserve group signet read access
(directory0550, assets0440) and hashes; do not repair missing inputs with mutable
live assets. Exact bytes can be restored from a verified backup before retry.

Rollback before COMMIT removes a newly created snapshot. If COMMIT's outcome is
ambiguous, retain its files: deleting them could destroy committed inputs. A
crash can leave an unreferenced snapshot/proof; inventory against snapshot_id and
retained revision policy before any administrative removal. No automatic sweep
or destructive retention policy is introduced here.

## 002 — private signature collections

Apply `002-signature-collections.sql` before the collection-aware API/worker,
with both stopped under the same backup/approval precautions above. It adds a
UUID primary key, label/default/storage/hash/error metadata and nullable
`doc_decisions.facsimile_id`. Original username/enrolment/dimension fields remain
unchanged. It is transactional and repeatable on both the former single-user
primary key schema and the current fresh schema.

Existing files stay `<username>.png` (`storage_id IS NULL`); existing decisions
stay NULL-reference decisions and the worker resolves their legacy file, never
a newly chosen default. New variants use `<UUID>.png` and new decisions pin an
owned enrolled UUID. Do not backfill old decisions from today's default, rename
or replace legacy originals, or move private files into DAM. New originals are
hash-checked at signing; legacy already-enrolled rows without hashes remain
supported. Keep the complete private directory with DB/queue/document backups.

The old single-facsimile application cannot run against the upgraded primary
key. Rollback requires the verified pre-upgrade DB/files backup, not dropping
new fields and discarding collected variants. `test/signature-migration.sh`
checks repeat migration and preservation of original metadata in a temporary
isolated PostgreSQL database; `test/signature-contract.sh` covers legacy decision
replay after a default change, frozen choices, retry and ownership boundaries.

## 003 — bounded PDF upload transport

Apply `003-bounded-pdf-uploads.sql` with writers stopped and verified coordinated
DB/files/queue/config backups. It adds nullable integer source-total/received
counters and a checked pair/range constraint. Repeat application preserves every
old field; existing NULL/NULL sources stay complete without rewriting their PDF.
`test/upload-migration.sh` verifies a real legacy-schema fixture separately.

Install the API, browser and lighttpd request cap together: PDF capacity remains
32MiB, but large files now use authenticated256KiB application-level chunks.
Incomplete uploads are DRAFTs, not a new status; they are not readable/editable/
submittable or usable as templates. Back up the partial source file and SQL
counter together. A failed/uncertain final commit can leave source.pdf beside an
older counter: do not mark it complete manually. The guarded retry reconciles
publication and compares acknowledged bytes. No initial creation retry or orphan
sweep is automatic; inventory unreferenced directories before administrative
removal.

**Do not run an old API while incomplete uploads exist:** it does not enforce
these readiness checks. Complete or explicitly discard them under the new API
with owner approval, or reconcile a tested paired DB/files rollback with all
newer activity. Blindly restoring an old backup after user activity loses data.
No preserved-preview or production upgrade is implied by source integration.

## 004 — optional detached release timestamps

Apply `004-detached-timestamps.sql` as database owner with writers stopped,
backups verified and explicit upgrade approval, **before the timestamp-aware
API**, even when timestamping will remain disabled. It adds an evidence table,
bounded-state/response constraints, due/released indexes and the timestamp
worker's SELECT/INSERT/UPDATE grant. Existing documents, decisions, PDF hashes
and files are unchanged; the migration does not enqueue or backdate evidence.
`test/timestamp-migration.sh` verifies legacy fields/decisions, empty new evidence,
grants and repeat application in a separate disposable database.

`document_timestamps` contains the full RFC3161 response bound to the released
revision/hash and its persistent release-anchored one-hour/four-attempt budget.
Back it up with the unchanged final PDFs and the relevant public trust bundles.
Enable only after independently provisioning TSA trust and configuring system
cron; see `docs/timestamps.md`. Installing the binary/example alone does not
schedule requests. Stop its cron entry during upgrades/restores. Retain evidence
on rollback; do not drop rows or blindly restore an old DB after newer activity.
The older API can ignore this additive table, but cannot expose its evidence.

These upgrades are not native deployment/resource certification. The repaired
two-max-file upload fixture does not certify parser amplification, aggregate
image/font/render resources or shared-service coexistence. Command deadlines
are not RSS/CPU quotas. Never infer safe coexistence with maa-1 from dev tests.