Skip to content

fix(seed): preserve admin-selected defaults across re-seeds#468

Merged
therealbrad merged 1 commit into
mainfrom
fix/seed-preserve-admin-default-choices
Jun 24, 2026
Merged

fix(seed): preserve admin-selected defaults across re-seeds#468
therealbrad merged 1 commit into
mainfrom
fix/seed-preserve-admin-default-choices

Conversation

@therealbrad

Copy link
Copy Markdown
Contributor

Description

The Prisma seed runs on every application boot/upgrade (Docker entrypoint → main()). Several seeders were force-resetting "default" flags on every run, silently reverting any default an admin had selected — with no audit trail, since seed uses the raw Prisma client and bypasses the $extends audit hooks.

Most visibly, the prompt-config seeder demoted every isDefault: true row via a blanket updateMany and then unconditionally re-promoted the config named "Default". So if an admin picked a different prompt configuration as the default, the next restart reverted it.

This applies the same defensive pattern already used by seedDefaultTemplate (and the SSO-provider upsert) to every affected seeder: only set a default on a fresh install (when no active default exists), and never overwrite the flag on update.

Seeders fixed

  • PromptConfig (seedPromptConfig.ts) — removed the blanket updateMany demotion; create sets isDefault only when no active default exists; update no longer touches isDefault.
  • Roles (seedCoreData) — update no longer forces user→default / admin→non-default; user becomes default only on fresh install.
  • Workflows (seedWorkflows) — tracks existing defaults per scope (SESSIONS/RUNS/CASES); update no longer writes isDefault; create sets it only for a scope that has no default yet.
  • MilestoneTypes (seedMilestoneTypes) — update no longer touches isDefault; the seed default is applied only on fresh install.

Each seeder logs a message when it preserves an admin's existing choice.

Already-safe (unchanged)

  • Priority field options — guarded by a skip-if-exists check.
  • Default template and the Magic Link SSO provider — already use this defensive pattern.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

How Has This Been Tested?

  • Unit tests (full pnpm precommit suite)
  • Manual testing — verified that on re-seed an admin-selected default is preserved, and a fresh install still installs the canonical defaults.

Behavior: on a fresh install everything seeds defaults as before; on upgrade/re-seed, existing rows keep whatever the admin set.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

The Prisma seed runs on every app boot/upgrade and was force-resetting
default flags, silently reverting an admin's choices with no audit trail
(seed uses the raw Prisma client and bypasses the audit hooks).

Apply the seedDefaultTemplate pattern to every affected seeder: only set a
default on fresh install (no active default exists) and never overwrite the
flag on update.

- PromptConfig: drop the blanket updateMany demotion; set default only on
  fresh install; do not touch isDefault on update.
- Roles: stop forcing user->default / admin->non-default on update.
- Workflows: track existing defaults per scope; only seed a default for a
  scope that has none yet; do not touch isDefault on update.
- MilestoneTypes: do not touch isDefault on update; seed default only on
  fresh install.

Each seeder logs when it preserves an admin's existing choice.
@therealbrad therealbrad merged commit ead6c69 into main Jun 24, 2026
5 checks passed
@therealbrad therealbrad deleted the fix/seed-preserve-admin-default-choices branch June 24, 2026 02:33
@therealbrad

Copy link
Copy Markdown
Contributor Author

🎉 This PR is included in version 0.40.8 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant