This repository has been archived on 2026-03-09. You can view files and clone it, but cannot push or open issues or pull requests.
php-agentic/Models/PromptVersion.php
darbs-claude 8c1cd9ed4f fix: verify prompt_versions migration exists, add model docblock
Investigation confirms migration exists at
Migrations/0001_01_01_000004_create_prompt_tables.php with all
required columns, foreign keys, and indexes:

- prompt_id FK (cascadeOnDelete)
- version (unsignedInteger)
- system_prompt, user_template (text, nullable)
- variables (json, nullable)
- created_by FK to users (nullOnDelete)
- composite index on [prompt_id, version]

Feature tests at tests/Feature/PromptVersionTest.php cover
creation, relationships, restore, and version history.

Adds @property docblock to PromptVersion model for IDE support,
consistent with AgentWorkspaceState.

Closes #22

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 06:41:45 +00:00

72 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Core\Mod\Agentic\Models;
use Core\Tenant\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* Prompt version snapshot for history and rollback.
*
* Captures the state of a prompt at a point in time, enabling
* version history and rollback via the restore() method.
*
* @property int $id
* @property int $prompt_id
* @property int $version
* @property string|null $system_prompt
* @property string|null $user_template
* @property array|null $variables
* @property int|null $created_by
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
*/
class PromptVersion extends Model
{
protected $fillable = [
'prompt_id',
'version',
'system_prompt',
'user_template',
'variables',
'created_by',
];
protected $casts = [
'variables' => 'array',
'version' => 'integer',
];
/**
* Get the parent prompt.
*/
public function prompt(): BelongsTo
{
return $this->belongsTo(Prompt::class);
}
/**
* Get the user who created this version.
*/
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
/**
* Restore this version to the parent prompt.
*/
public function restore(): Prompt
{
$this->prompt->update([
'system_prompt' => $this->system_prompt,
'user_template' => $this->user_template,
'variables' => $this->variables,
]);
return $this->prompt;
}
}