4 Commits

Author SHA1 Message Date
Justin Maier 37ce3531d6 fix(db): remove dead metric trigger + harden programmability bootstrap (#3031)
* fix(db): make programmability apply fail loudly and deterministically

The db:program bootstrap applied all programmability SQL in one transaction whose catch block only console.error'd and let the process exit 0, so a single bad statement silently no-oped every function/view/trigger. It also relied on fs.readdir order, which is not guaranteed across platforms, to apply IIF.sql before views.sql (which calls iif() 315x).

Now: exit non-zero on failure (process.exitCode = 1), disconnect Prisma, and order files deterministically with helper functions (IIF/months_between/is_new_user) first and views.sql last.

Found during review of daceheg PR #2417.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore(db): remove dead metrics_trigger.sql from programmability

add_model_metrics()/add_image_metrics() are legacy PG-trigger metric seeders. add_model_metrics INSERTs into ModelMetric(timeframe,...), but the ModelMetric overhaul (migration 20251123142214) dropped the timeframe column and made it one row per model; migration 20251124081808 then explicitly drops both the add_metrics_after_insert trigger on Model AND the add_model_metrics function. add_image_metrics targets the now-removed ImageMetric table and its own trigger is dropped at the end of the same file.

Re-CREATE-OR-REPLACE-ing them via db:program resurrected the dropped, now-broken trigger, making any Model INSERT throw at runtime during local bootstrap. ModelMetric rows are populated by the metrics processor upsert (src/server/metrics/model.metrics.ts:270, INSERT ... ON CONFLICT DO UPDATE), not this trigger, so the whole file is dead.

Found during review of daceheg PR #2417.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 15:59:25 -06:00
Briant Diehl 343c3c9bb4 fix(build): update prisma/build paths for the db-schema package move
The Prisma schema/migrations moved to packages/civitai-db-schema; point the build and migration tooling at the new path.

- Dockerfile: workspace-aware deps layer (copy pnpm-workspace.yaml + packages/*), schema paths -> packages/civitai-db-schema/prisma
- prisma-migrate-with-views-workaround / mark-migration-applied / prepare-programmability / local-dev/run_migrations: updated hardcoded prisma/ paths

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 15:34:21 -06:00
Justin Maier 7387790439 Moderation adjustments 2023-03-24 14:14:49 -06:00
Justin Maier c8366ce0f2 Add DB programmability 2023-03-24 09:40:41 -06:00