Restore private prompt history with idempotent user-scoped imports
Hop-State: A_06FNBBSMHQ9HVEQCC70EPA8 Hop-Proposal: R_06FNBBRHSSJTCFN79G3KWJ0 Hop-Task: T_06FNB93F0NJANQV08BA6VAG Hop-Attempt: AT_06FNB93F0PSZWAGR81JCWBG
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
CREATE UNIQUE INDEX prompts_repository_user_state_idx
|
||||
ON prompts (repository_id, gitea_user_id, state_id)
|
||||
WHERE gitea_user_id IS NOT NULL AND state_id <> '';
|
||||
@@ -67,6 +67,7 @@ type CreatePromptInput struct {
|
||||
Status string
|
||||
ResponseSummary string
|
||||
Metadata json.RawMessage
|
||||
CreatedAt *time.Time
|
||||
CompletedAt *time.Time
|
||||
}
|
||||
|
||||
@@ -199,11 +200,18 @@ func (p *Postgres) CreatePrompt(ctx context.Context, input CreatePromptInput) (P
|
||||
}
|
||||
var prompt Prompt
|
||||
err = p.pool.QueryRow(ctx, `
|
||||
INSERT INTO prompts (id, repository_id, gitea_user_id, task_id, attempt_id, state_id, prompt, agent_name, agent_model, status, response_summary, metadata, completed_at)
|
||||
SELECT $1, r.id, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14
|
||||
INSERT INTO prompts (id, repository_id, gitea_user_id, task_id, attempt_id, state_id, prompt, agent_name, agent_model, status, response_summary, metadata, created_at, completed_at)
|
||||
SELECT $1, r.id, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, COALESCE($14, now()), $15
|
||||
FROM repositories r WHERE r.owner=$2 AND r.name=$3
|
||||
ON CONFLICT (repository_id, gitea_user_id, state_id)
|
||||
WHERE gitea_user_id IS NOT NULL AND state_id <> ''
|
||||
DO UPDATE SET
|
||||
task_id=EXCLUDED.task_id, attempt_id=EXCLUDED.attempt_id,
|
||||
prompt=EXCLUDED.prompt, agent_name=EXCLUDED.agent_name, agent_model=EXCLUDED.agent_model,
|
||||
status=EXCLUDED.status, response_summary=EXCLUDED.response_summary, metadata=EXCLUDED.metadata,
|
||||
created_at=EXCLUDED.created_at, completed_at=EXCLUDED.completed_at
|
||||
RETURNING id, gitea_user_id, task_id, attempt_id, state_id, prompt, agent_name, agent_model, status, response_summary, metadata, created_at, completed_at`,
|
||||
id, input.Owner, input.Repository, input.GiteaUserID, input.TaskID, input.AttemptID, input.StateID, input.Prompt, input.AgentName, input.AgentModel, input.Status, input.ResponseSummary, metadata, input.CompletedAt,
|
||||
id, input.Owner, input.Repository, input.GiteaUserID, input.TaskID, input.AttemptID, input.StateID, input.Prompt, input.AgentName, input.AgentModel, input.Status, input.ResponseSummary, metadata, input.CreatedAt, input.CompletedAt,
|
||||
).Scan(&prompt.ID, &prompt.GiteaUserID, &prompt.TaskID, &prompt.AttemptID, &prompt.StateID, &prompt.Prompt, &prompt.AgentName, &prompt.AgentModel, &prompt.Status, &prompt.ResponseSummary, &prompt.Metadata, &prompt.CreatedAt, &prompt.CompletedAt)
|
||||
if err != nil {
|
||||
return Prompt{}, err
|
||||
|
||||
Reference in New Issue
Block a user