# gen-upc-snapshot

Regenerates the embedded UPC snapshot consumed by
`pkg/litigationplanner/embedded/upc`. Slice C of the litigation-planner
extraction (m/paliad#124 §19). See
`docs/design-litigation-planner-2026-05-26.md` §19 for the full design.

## When to regenerate

After any change that affects the public UPC rule corpus:

- new rules merged via the admin rule-editor
- a deadline-rule migration that touches UPC rows
- a `paliad.holidays` update (new public holidays / vacation runs)
- a `paliad.courts` update (new UPC LD opens, etc.)
- a `paliad.proceeding_types` change for `jurisdiction = 'UPC'`

The snapshot is operator-controlled — there is no CI regeneration in v1.

## How to regenerate

```sh
make snapshot-upc
```

or directly:

```sh
DATABASE_URL=postgres://...  go run ./cmd/gen-upc-snapshot
```

Flags:

| Flag            | Default                                | Purpose |
|-----------------|----------------------------------------|---------|
| `-output`       | `./pkg/litigationplanner/embedded/upc` | directory to write JSON files into |
| `-version`      | auto-derived (`YYYY-MM-DD-N`)          | override the snapshot version |
| `-source-label` | empty                                  | text label written to `meta.json` (`paliad-prod`, `paliad-dev`, …) |

The generator:

1. Applies pending migrations against `DATABASE_URL` (snapshot always matches schema HEAD).
2. SELECTs UPC active proceeding_types + their published+active rules + referenced trigger_events + DE/UPC holidays + UPC courts.
3. Writes pretty-printed JSON to `<output>/{proceeding_types,rules,trigger_events,holidays,courts,meta}.json`.

## Idempotence

Running twice with the same DB state produces the same JSON (modulo `meta.generated_at`). Diff-friendly in git.

## Versioning

`meta.json.version` uses `YYYY-MM-DD-N` where N starts at 1 and increments on same-day regenerations. The generator reads the existing `meta.json` and bumps automatically.

## After regeneration

1. Review the diff: `git diff pkg/litigationplanner/embedded/upc/`.
2. Run tests: `go test ./pkg/litigationplanner/embedded/upc/...`.
3. Commit with a message like `chore(snapshot): regenerate UPC snapshot (<reason>)`.
4. Notify any downstream consumer (youpc.org) that a new paliad release is available.
