fix(seed): preserve admin-selected defaults across re-seeds#468
Merged
Conversation
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.
Contributor
Author
|
🎉 This PR is included in version 0.40.8 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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$extendsaudit hooks.Most visibly, the prompt-config seeder demoted every
isDefault: truerow via a blanketupdateManyand 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
seedPromptConfig.ts) — removed the blanketupdateManydemotion;createsetsisDefaultonly when no active default exists;updateno longer touchesisDefault.seedCoreData) —updateno longer forcesuser→default /admin→non-default;userbecomes default only on fresh install.seedWorkflows) — tracks existing defaults per scope (SESSIONS/RUNS/CASES);updateno longer writesisDefault;createsets it only for a scope that has no default yet.seedMilestoneTypes) —updateno longer touchesisDefault; 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)
Type of Change
How Has This Been Tested?
pnpm precommitsuite)Behavior: on a fresh install everything seeds defaults as before; on upgrade/re-seed, existing rows keep whatever the admin set.
Checklist