Version Strategy
Current Version Pattern
Prompts follow a snapshot-on-update versioning strategy:- The
promptstable stores the latest version only (no JOINs needed for reads) - On every update, the current state is snapshotted to
prompt_versionstable - Version number is auto-incremented on each update
- Version 1 is created automatically when the prompt is first created
Database Schema
Endpoints
Get Prompt (Current or Historical Version)
GET /api/admin/prompts/:id
Retrieve the current version or a specific historical version.
Query Parameters
number
Historical version number to retrieve (omit for current version)Example:
2Example: Get Current Version
Example: Get Historical Version
Response
Get Change History
GET /api/admin/prompts/:id/history
Returns the full version history of a prompt, including diffs between versions, who made each change, and when.
Response Fields
array
Array of change records
string
Change record UUID
number
Version number this change created
string
Type of changeValues:
CREATE, UPDATE, DELETE, ACTIVATE, DEACTIVATEobject
Field-level diff objectFormat:
{ field: { old: value, new: value } }Example:string
Optional comment explaining the change
object
User who made the change
id(string): User UUIDemail(string): User email
string
ISO 8601 timestamp of the change
Example Request
Example Response
Version Lifecycle
1. Creation (v1)
When a prompt is created viaPOST /api/admin/prompts/create:
2. Update (v2, v3, …)
When a prompt is updated viaPUT /api/admin/prompts/:id/update:
3. Toggle Active State
When toggling viaPOST /api/admin/prompts/:id/toggle-active:
4. Deletion
When deleting viaDELETE /api/admin/prompts/:id:
Diff Computation
Thechanges field in PromptChange records contains field-level diffs:
Rollback Pattern
To rollback to a previous version:- Fetch the historical version:
GET /api/admin/prompts/:id?version=2 - Extract all fields from the response
- Update the prompt with those values:
PUT /api/admin/prompts/:id/update
Version Retention
All versions are retained indefinitely unless:- The entire prompt is deleted (CASCADE deletes all versions)
- A specific version is explicitly deleted:
DELETE /api/admin/prompts/:id?version=2
Conflict Detection
The update endpoint implements optimistic locking to detect concurrent modifications:Best Practices
1. Version Naming
Include version numbers in the prompt name for easy identification:2. Change Comments
Use the comment field in change records to explain significant updates:3. Version Review
Before activating a new version, review the change history:4. Version Cleanup
Periodically delete old version snapshots to reduce database size:Source Code
- Versioning logic:
packages/api/src/prompts/prompts.service.ts - Change history service:
packages/api/src/prompts/change-history.service.ts - Get prompt endpoint:
packages/api/src/prompts/prompts.controller.ts:141 - Get history endpoint:
packages/api/src/prompts/prompts.controller.ts:244