Skip to content

refactor(data): migrate QuickPhrase to Prompt with version management#13430

Open
zhangjiadi225 wants to merge 3 commits intoCherryHQ:v2from
zhangjiadi225:refactor/v2/prompt-management
Open

refactor(data): migrate QuickPhrase to Prompt with version management#13430
zhangjiadi225 wants to merge 3 commits intoCherryHQ:v2from
zhangjiadi225:refactor/v2/prompt-management

Conversation

@zhangjiadi225
Copy link

What this PR does

Before this PR:

  • Quick phrases stored in Dexie (IndexedDB) with no version history
  • No way to compare or rollback prompt changes
  • Unused template variable definition system (variables field) added complexity

After this PR:

  • Prompts stored in SQLite via Drizzle ORM with automatic version management
  • Content changes auto-create version snapshots; rollback supported
  • Quick panel supports version sub-menu for multi-version prompts
  • Removed unused variables system, keeping only ${var} syntax in content

Why we need it and why it was done in this way

The following tradeoffs were made:

  • Rollback creates a new version (append-only history) rather than reverting — ensures no history is ever lost
  • Version selection in quick panel is temporary (doesn't change currentVersion) — keeps version management in settings page

The following alternatives were considered:

  • Eager loading versions for all prompts — rejected in favor of lazy loading for performance

Breaking changes

Data migration from Dexie quick_phrases to SQLite prompt table runs automatically via PromptMigrator.

Checklist

  • PR: The PR description is expressive enough
  • Code: Write code that humans can understand and Keep it simple
  • Refactor: Boy Scout Rule followed
  • Documentation: Not required (internal data layer change)
  • Self-review

Release note

Migrated Quick Phrases to Prompt Management system with automatic version history, rollback support, and version selection in the quick panel.

- Replace QuickPhrase with Prompt entity backed by SQLite via Drizzle ORM
- Add prompt and prompt_version tables with automatic versioning
- Implement PromptService with CRUD, version history, and rollback
- Add API handlers and schemas for /prompts endpoints
- Create PromptMigrator for Dexie quick_phrases → SQLite migration
- Refactor QuickPhrasesButton with version sub-menu selection
- Replace QuickPhraseSettings with PromptSettings page
- Remove unused template variables system and templateEngine utility
- Update routing from /settings/quickphrase to /settings/prompts

Signed-off-by: zhangjiadi225 <625013594@qq.com>
@zhangjiadi225 zhangjiadi225 changed the base branch from main to v2 March 13, 2026 03:05
@zhangjiadi225 zhangjiadi225 requested a review from a team March 13, 2026 03:05
@DeJeune
Copy link
Collaborator

DeJeune commented Mar 13, 2026

Note

This comment was translated by Claude.

Add unit tests for the key migrator


Original Content 关键的migrator加一下单元测试

- Test prepare phase: table existence, valid/invalid filtering, empty table, error handling
- Test execute phase: insertion, title defaults, progress reporting, transaction errors
- Test validate phase: count matching, mismatch detection, db failure handling, skip tracking

Signed-off-by: zhangjiadi225 <625013594@qq.com>
@SiinXu
Copy link
Collaborator

SiinXu commented Mar 13, 2026

Nice work on the migration and version management! A few things before detailed review:

Question: Variable design

The old QuickPhrase had a variables field (unused), and the current ${var} syntax in content is inserted as-is with no runtime substitution. Since this PR is redesigning the Prompt data model:

Have you considered the variable substitution story? How should ${var} placeholders work going forward?

Want to make sure the data model accounts for this before we merge.

Initial code observations

  • Transaction safety: create(), update(), rollback(), and reorder() in PromptService are not wrapped in db.transaction() — risk of data inconsistency. The migrator correctly uses transactions, service methods should too.
  • UNIQUE constraint: The composite index on prompt_version(promptId, version) should be uniqueIndex() to enforce version uniqueness at DB level.
  • Nullable columns: currentVersion and sortOrder should have .notNull() constraints.

@zhangjiadi225
Copy link
Author

zhangjiadi225 commented Mar 13, 2026 via email

…aints

- Wrap create/update/rollback/reorder in db.transaction()
- Move reads inside transactions to prevent race conditions
- Add notNull constraints to currentVersion and sortOrder
- Change prompt_version composite index to uniqueIndex
- Remove redundant null fallbacks in rowToPrompt

Signed-off-by: zhangjiadi225 <625013594@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants