# Drizzle / Persistence Completion Targets — V1-P2-0233

## Audit scope

Every site under `libs/` and `apps/` that documents a placeholder for a
production-grade persistence call. The patterns we matched:

- `// Would insert/update/delete/query/fetch/read/write/persist/store/save … via Drizzle`
- `// Would … in production`, `// Would … database`,
  `// In a full implementation, persist to db`
- `logger.info('Would store … to database', …)` in the nyx/veritas pipelines
- `// Would store token in database`, `// Would fetch from API`,
  `// Would create payment intent via API`

Counts excluded `node_modules`, `*.spec.ts`, and `*.test.ts`. Numbers below
reflect the audit at commit time; re-run the grep before declaring this section
complete.

---

## 1. Drizzle-shaped database stubs (literal "via Drizzle" mention)

- [ ] `libs/cybele/api/src/routes/properties.ts:160` — "Would insert into
      `cybele_properties` via Drizzle in a full implementation". Replace with
      `db.insert(properties).values(...).returning()` against the Cybele Drizzle
      schema.

(There is exactly one literal "via Drizzle" callsite at audit time. The
remaining persistence stubs are listed under §2 by storage backend.)

---

## 2. "Would store … to database" — long-running pipelines

These are batch-write paths in the Nyx astronomy pipelines and the Veritas
elections pipelines. Each currently logs and discards the batch; production must
fan the rows into Drizzle inserts
(`db.insert( table).values(rows).onConflictDoUpdate({ target, set: rows })`).

- [ ] `apps/nyx/pipelines/src/catalog-syncer.ts:1198` — Messier objects →
      `nyx_messier_catalog` table. Idempotent upsert keyed by
      `(catalogId, messierNumber)`.
- [ ] `apps/nyx/pipelines/src/catalog-syncer.ts:1207` — NGC objects →
      `nyx_ngc_catalog` keyed by `(catalogId, ngcNumber)`.
- [ ] `apps/nyx/pipelines/src/catalog-syncer.ts:1216` — exoplanets →
      `nyx_exoplanet_catalog` keyed by `(planetName, hostStar)`.
- [ ] `apps/nyx/pipelines/src/tle-updater.ts:346` — TLE records →
      `nyx_satellite_tle` keyed by `(catalogNumber, epoch)`.
- [ ] `apps/nyx/pipelines/src/ephemeris-generator.ts:448` — ephemeris grid →
      `nyx_ephemeris` keyed by `(bodyId, jdTt, observerSite)`.
- [ ] `apps/nyx/pipelines/src/event-calculator.ts:403` — astronomy events →
      `nyx_astronomy_events` keyed by `(eventType, jdTt)`.

---

## 3. Veritas — emergency / risk / RAG persistence

- [ ] `libs/veritas/emergency/distribution.ts:682` — push-notification tokens.
      Replace with
      `db.select().from(userPushTokens).where(eq(     userPushTokens.userId, ...))`.
- [ ] `libs/veritas/emergency/distribution.ts:687` — phone numbers.
      `db.select({ phone: users.phone }).from(users)...`
- [ ] `libs/veritas/emergency/election.ts:231` — election state update.
      `db.update(electionState).set(...).where(...)`
- [ ] `libs/veritas/risk/technical.ts:472` — risk-config update.
      `db.update(riskConfig)...` plus a follow-up threshold check that enqueues
      a job into the BullMQ `risk-recalc` queue.
- [ ] `libs/veritas/risk/legal.ts:161` — compliance license query.
      `db.select().from(complianceLicenses).where(...)`
- [ ] `libs/veritas/risk/legal.ts:499` — compliance finding resolved flag.
      `db.update(complianceFindings).set({ resolved: true })...`
- [ ] `libs/veritas/operations/editorial.ts:537` — editorial-plan update.
      `db.update(editorialPlans)...`
- [ ] `libs/veritas/rag/search.ts:491` — archive query. Currently a stub.
      Replace with
      `db.select().from(archiveDocuments).where(     and(eq(archive.subject, ...), gte(archive.publishedAt, ...)))`.

---

## 4. Iris / agent-tooling / streaming

- [ ] `libs/iris/agents/tools/learning/tool-registration.ts:551` — "Would fetch
      tool definitions from URL". Replace with a `fetch(url)` call followed by
      `db.insert(toolDefinitions)...` so the registry caches the result.
- [ ] `libs/iris/platform/streaming/grpc/index.ts:270` — "Would write to
      bidirectional stream". Pipe through the existing gRPC `StreamWriter`
      instead of dropping bytes.

---

## 5. App-tier persistence stubs

### 5.1 Aphrodite mobile (AsyncStorage / native bridge)

- [ ] `apps/aphrodite/mobile-viewer/services/OfflineService.ts:1385` — delete
      file via native FS bridge.
- [ ] `apps/aphrodite/mobile-viewer/services/OfflineService.ts:1389` — create
      directory via native FS bridge.
- [ ] `apps/aphrodite/mobile-viewer/services/OfflineService.ts:1418` — save to
      AsyncStorage (settings).
- [ ] `apps/aphrodite/mobile-viewer/services/OfflineService.ts:1426` — save to
      AsyncStorage (favourites).
- [ ] `apps/aphrodite/mobile-viewer/services/OfflineService.ts:1434` — save to
      AsyncStorage (download queue).
- [ ] `apps/aphrodite/mobile-viewer/services/OfflineService.ts:1442` — save to
      AsyncStorage (history).
- [ ] `apps/aphrodite/mobile-viewer/services/OfflineService.ts:1459` — "Would
      fetch from API" — replace with `fetch(...)` + zod parse.
- [ ] `apps/aphrodite/mobile-viewer/services/TippingService.ts:566` — fetch from
      creator-tipping API.
- [ ] `apps/aphrodite/mobile-viewer/services/TippingService.ts:618` — create
      payment intent (Stripe).
- [ ] `apps/aphrodite/mobile-broadcaster/services/FaceTrackingService.ts:342` —
      query native module for actual capabilities.
- [ ] `apps/aphrodite/mobile-broadcaster/services/PortraitModeService.ts:1306` —
      same; query native capabilities.
- [ ] `apps/aphrodite/mobile-broadcaster/services/NotificationService.ts:1044` —
      Android notification channel creation via native module.

### 5.2 Veritas / Lilith / Aja

- [ ] `apps/veritas/notifications/src/api/server.ts:368` — store push token in
      database. `db.insert(userPushTokens)...`
- [ ] `apps/lilith/svc-metaverse/src/ai/tools/batch-route-migrator.ts:413` —
      "Would create file (dry-run)". Add a real `--dry-run` flag and
      `fs.writeFileSync(...)` in non-dry-run mode.
- [ ] `apps/lilith/svc-metaverse/src/advanced/GroupMeditationCircles.ts:331` —
      "Would update visual representation here". Wire to the meditation-room
      avatar update channel.
- [ ] `apps/lilith/svc-metaverse/src/creator/WorldSharing.ts:176` —
      `ownerDisplayName: project.owner` — fetch from user service.
- [ ] `apps/aja/cli/src/commands/convert.ts:98` — "Would create directory".
      Replace with `fs.mkdirSync(outputDir, { recursive:     true })` outside
      dry-run mode.

### 5.3 Metis worker

- [ ] `apps/metis/worker/src/jobs/cleanup-jobs.ts:410` — "Would delete:
      `${report.cleanedCount}` items". Replace with the actual `db.delete(...)`
      against the cleanup target table.

### 5.4 Civitai integration

- [ ] `libs/isis/ai-providers/src/providers/civitai/collection-management-provider.ts:1445`
      — fetch from API.
- [ ] `libs/isis/ai-providers/src/providers/civitai/model-comparison-provider.ts:966`
      — fetch from API or infer from model data.

### 5.5 Aje Bitcoin

- [ ] `libs/aje/bitcoin/src/lsp/channels.ts:250` —
      `currentBlockHeight     = 800_000` is hardcoded. Replace with
      `await     bitcoinProvider.getBlockCount()` (V1-P2-0190).

### 5.6 Euterpe DMX

- [ ] `libs/euterpe/stage/lighting-visuals/lighting-visuals.ts:995` — "Would
      write RGB to all DMX addresses". Wire to the DMX-512 output path.

### 5.7 Hestia / Yemaya cycle-prevention guards (NOT STUBS)

These two are valid "Would create cycle" guards in graph-walking code; they
detect a cycle attempt and short-circuit. They are not persistence stubs — they
are correct logic. Listed for completeness so they are not flagged in future
scans.

- `libs/hestia/recipes/collections.ts:654` — folder cycle prevention.
- `libs/yemaya/ui/components/EnvironmentConcepting/types.ts:1593` — graph cycle
  prevention.

---

## 6. Veritas realtime data fetch

- [ ] `libs/veritas/realtime-data/utilities.ts:281` — "Would fetch from NPA API
      or OMC sources". Replace with a real HTTP fetch through the `@aje/rpc`
      orchestrator (V1-P2-0190) — these are external data sources that should
      ride the same retry / rate-limit / fan-out pipeline as RPC calls.

---

## 7. Summary statistics

| directory                         | "via Drizzle" | "Would store … to database" | other persistence stubs | total |
| --------------------------------- | ------------: | --------------------------: | ----------------------: | ----: |
| `libs/cybele/`                    |             1 |                           0 |                       0 |     1 |
| `apps/nyx/pipelines/`             |             0 |                           6 |                       0 |     6 |
| `libs/veritas/`                   |             0 |                           0 |                       9 |     9 |
| `libs/iris/`                      |             0 |                           0 |                       2 |     2 |
| `apps/aphrodite/mobile-*`         |             0 |                           0 |                      11 |    11 |
| `apps/veritas/notifications/`     |             0 |                           0 |                       1 |     1 |
| `apps/lilith/svc-metaverse/`      |             0 |                           0 |                       3 |     3 |
| `apps/aja/cli/`                   |             0 |                           0 |                       1 |     1 |
| `apps/metis/worker/`              |             0 |                           0 |                       1 |     1 |
| `libs/isis/ai-providers/civitai/` |             0 |                           0 |                       2 |     2 |
| `libs/aje/bitcoin/`               |             0 |                           0 |                       1 |     1 |
| `libs/euterpe/stage/`             |             0 |                           0 |                       1 |     1 |
| **total**                         |             1 |                           6 |                      32 |    39 |

(Hestia + Yemaya cycle-prevention guards are excluded as they are correct logic,
not stubs.)

---

## 8. Remediation policy

1. **One Drizzle table per logical entity.** Don't reuse a generic `key_value`
   table for distinct domain concepts — that defeats query planning and
   migration safety.
2. **Idempotent upserts for pipeline writes.** Every Nyx / Veritas pipeline must
   use `onConflictDoUpdate({ target: <unique-key>, set: excluded })` so
   re-running the pipeline is a no-op when the data is unchanged.
3. **Drizzle migrations per change.** Every new table or column ships a Drizzle
   migration in `libs/<domain>/drizzle/<service>/ migrations/` so the V1-P2-0236
   drift detector can verify schema parity in CI.
4. **Pull external fetches through `@aje/rpc`.** External HTTP calls (Civitai,
   NPA / OMC, push-token providers) should ride the shared rate-limit / retry /
   fallback orchestrator from V1-P2-0190.
5. **Replace fake `currentBlockHeight = 800_000` with real RPC.** Anything that
   hardcodes a chain state must route through the `@aje/rpc` typed providers
   (V1-P2-0190).
6. **Native-module bridges (Aphrodite mobile).** AsyncStorage / FS /
   notifications must call into the actual React Native bridge. Until the bridge
   exists, these are blocked rather than stub.

When every checkbox above is `[x]`, file V1-P2-0233 can be marked complete in
`OSHUN_V1_TODOS_P2.md`.
