refactor(store,tools): migrate IDs from UUID to bigserial int64
Some checks failed
CI / build-and-test (push) Failing after -31m12s
Some checks failed
CI / build-and-test (push) Failing after -31m12s
All internal entity lookups now use bigserial primary keys (int64) while GUIDs are retained for external/public identification. Updated store functions (TouchProject, UpdateThoughtMetadata, AddThoughtAttachment) to query by id instead of guid, added GetThoughtByID, changed semanticSearch and all tool helpers to use *int64 project IDs, and updated retry/backfill workers to use int64 thought IDs throughout.
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
"git.warky.dev/wdevs/amcs/internal/generatedmodels"
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
const planColumns = `
|
||||
id, title, description, status, priority, project_id, owner, due_date,
|
||||
id, guid, title, description, status, priority, project_id, owner, due_date,
|
||||
completed_at, reviewed_by, last_reviewed_at, supersedes_plan_id, tags::text[], created_at, updated_at`
|
||||
|
||||
func (db *DB) CreatePlan(ctx context.Context, plan ext.Plan) (ext.Plan, error) {
|
||||
@@ -37,19 +37,19 @@ func (db *DB) CreatePlan(ctx context.Context, plan ext.Plan) (ext.Plan, error) {
|
||||
return scanPlan(row)
|
||||
}
|
||||
|
||||
func (db *DB) GetPlan(ctx context.Context, id uuid.UUID) (ext.Plan, error) {
|
||||
func (db *DB) GetPlan(ctx context.Context, id int64) (ext.Plan, error) {
|
||||
row := db.pool.QueryRow(ctx, `select`+planColumns+` from plans where id = $1`, id)
|
||||
plan, err := scanPlan(row)
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
return ext.Plan{}, fmt.Errorf("plan not found: %s", id)
|
||||
return ext.Plan{}, fmt.Errorf("plan not found: %d", id)
|
||||
}
|
||||
return ext.Plan{}, fmt.Errorf("get plan: %w", err)
|
||||
}
|
||||
return plan, nil
|
||||
}
|
||||
|
||||
func (db *DB) GetPlanDetail(ctx context.Context, id uuid.UUID) (ext.PlanDetail, error) {
|
||||
func (db *DB) GetPlanDetail(ctx context.Context, id int64) (ext.PlanDetail, error) {
|
||||
plan, err := db.GetPlan(ctx, id)
|
||||
if err != nil {
|
||||
return ext.PlanDetail{}, err
|
||||
@@ -105,7 +105,7 @@ func (db *DB) GetPlanDetail(ctx context.Context, id uuid.UUID) (ext.PlanDetail,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (db *DB) UpdatePlan(ctx context.Context, id uuid.UUID, u ext.PlanUpdate) (ext.Plan, error) {
|
||||
func (db *DB) UpdatePlan(ctx context.Context, id int64, u ext.PlanUpdate) (ext.Plan, error) {
|
||||
sets := []string{"updated_at = now()"}
|
||||
args := []any{}
|
||||
|
||||
@@ -169,14 +169,14 @@ func (db *DB) UpdatePlan(ctx context.Context, id uuid.UUID, u ext.PlanUpdate) (e
|
||||
plan, err := scanPlan(row)
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
return ext.Plan{}, fmt.Errorf("plan not found: %s", id)
|
||||
return ext.Plan{}, fmt.Errorf("plan not found: %d", id)
|
||||
}
|
||||
return ext.Plan{}, fmt.Errorf("update plan: %w", err)
|
||||
}
|
||||
return plan, nil
|
||||
}
|
||||
|
||||
func (db *DB) DeletePlan(ctx context.Context, id uuid.UUID) error {
|
||||
func (db *DB) DeletePlan(ctx context.Context, id int64) error {
|
||||
tag, err := db.pool.Exec(ctx, `delete from plans where id = $1`, id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("delete plan: %w", err)
|
||||
@@ -232,7 +232,7 @@ func (db *DB) ListPlans(ctx context.Context, filter ext.PlanFilter) ([]ext.Plan,
|
||||
|
||||
// Dependencies
|
||||
|
||||
func (db *DB) AddPlanDependency(ctx context.Context, planID, dependsOnPlanID uuid.UUID) error {
|
||||
func (db *DB) AddPlanDependency(ctx context.Context, planID, dependsOnPlanID int64) error {
|
||||
_, err := db.pool.Exec(ctx, `
|
||||
insert into plan_dependencies (plan_id, depends_on_plan_id)
|
||||
values ($1, $2)
|
||||
@@ -244,7 +244,7 @@ func (db *DB) AddPlanDependency(ctx context.Context, planID, dependsOnPlanID uui
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *DB) RemovePlanDependency(ctx context.Context, planID, dependsOnPlanID uuid.UUID) error {
|
||||
func (db *DB) RemovePlanDependency(ctx context.Context, planID, dependsOnPlanID int64) error {
|
||||
tag, err := db.pool.Exec(ctx, `
|
||||
delete from plan_dependencies where plan_id = $1 and depends_on_plan_id = $2
|
||||
`, planID, dependsOnPlanID)
|
||||
@@ -259,7 +259,7 @@ func (db *DB) RemovePlanDependency(ctx context.Context, planID, dependsOnPlanID
|
||||
|
||||
// Related Plans
|
||||
|
||||
func (db *DB) AddRelatedPlan(ctx context.Context, planAID, planBID uuid.UUID) error {
|
||||
func (db *DB) AddRelatedPlan(ctx context.Context, planAID, planBID int64) error {
|
||||
a, b := canonicalPlanPair(planAID, planBID)
|
||||
_, err := db.pool.Exec(ctx, `
|
||||
insert into plan_related_plans (plan_a_id, plan_b_id)
|
||||
@@ -272,7 +272,7 @@ func (db *DB) AddRelatedPlan(ctx context.Context, planAID, planBID uuid.UUID) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *DB) RemoveRelatedPlan(ctx context.Context, planAID, planBID uuid.UUID) error {
|
||||
func (db *DB) RemoveRelatedPlan(ctx context.Context, planAID, planBID int64) error {
|
||||
a, b := canonicalPlanPair(planAID, planBID)
|
||||
tag, err := db.pool.Exec(ctx, `
|
||||
delete from plan_related_plans where plan_a_id = $1 and plan_b_id = $2
|
||||
@@ -288,7 +288,7 @@ func (db *DB) RemoveRelatedPlan(ctx context.Context, planAID, planBID uuid.UUID)
|
||||
|
||||
// Plan Skills
|
||||
|
||||
func (db *DB) AddPlanSkill(ctx context.Context, planID, skillID uuid.UUID) error {
|
||||
func (db *DB) AddPlanSkill(ctx context.Context, planID, skillID int64) error {
|
||||
_, err := db.pool.Exec(ctx, `
|
||||
insert into plan_skills (plan_id, skill_id) values ($1, $2) on conflict do nothing
|
||||
`, planID, skillID)
|
||||
@@ -298,7 +298,7 @@ func (db *DB) AddPlanSkill(ctx context.Context, planID, skillID uuid.UUID) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *DB) RemovePlanSkill(ctx context.Context, planID, skillID uuid.UUID) error {
|
||||
func (db *DB) RemovePlanSkill(ctx context.Context, planID, skillID int64) error {
|
||||
tag, err := db.pool.Exec(ctx, `
|
||||
delete from plan_skills where plan_id = $1 and skill_id = $2
|
||||
`, planID, skillID)
|
||||
@@ -311,7 +311,7 @@ func (db *DB) RemovePlanSkill(ctx context.Context, planID, skillID uuid.UUID) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *DB) ListPlanSkills(ctx context.Context, planID uuid.UUID) ([]ext.AgentSkill, error) {
|
||||
func (db *DB) ListPlanSkills(ctx context.Context, planID int64) ([]ext.AgentSkill, error) {
|
||||
rows, err := db.pool.Query(ctx, `
|
||||
select s.id, s.name, s.description, s.content, s.tags::text[], s.created_at, s.updated_at
|
||||
from agent_skills s
|
||||
@@ -332,7 +332,7 @@ func (db *DB) ListPlanSkills(ctx context.Context, planID uuid.UUID) ([]ext.Agent
|
||||
return nil, fmt.Errorf("scan plan skill: %w", err)
|
||||
}
|
||||
s := ext.AgentSkill{
|
||||
ID: model.ID.UUID(),
|
||||
ID: model.ID.Int64(),
|
||||
Name: model.Name.String(),
|
||||
Description: model.Description.String(),
|
||||
Content: model.Content.String(),
|
||||
@@ -350,7 +350,7 @@ func (db *DB) ListPlanSkills(ctx context.Context, planID uuid.UUID) ([]ext.Agent
|
||||
|
||||
// Plan Guardrails
|
||||
|
||||
func (db *DB) AddPlanGuardrail(ctx context.Context, planID, guardrailID uuid.UUID) error {
|
||||
func (db *DB) AddPlanGuardrail(ctx context.Context, planID, guardrailID int64) error {
|
||||
_, err := db.pool.Exec(ctx, `
|
||||
insert into plan_guardrails (plan_id, guardrail_id) values ($1, $2) on conflict do nothing
|
||||
`, planID, guardrailID)
|
||||
@@ -360,7 +360,7 @@ func (db *DB) AddPlanGuardrail(ctx context.Context, planID, guardrailID uuid.UUI
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *DB) RemovePlanGuardrail(ctx context.Context, planID, guardrailID uuid.UUID) error {
|
||||
func (db *DB) RemovePlanGuardrail(ctx context.Context, planID, guardrailID int64) error {
|
||||
tag, err := db.pool.Exec(ctx, `
|
||||
delete from plan_guardrails where plan_id = $1 and guardrail_id = $2
|
||||
`, planID, guardrailID)
|
||||
@@ -373,7 +373,7 @@ func (db *DB) RemovePlanGuardrail(ctx context.Context, planID, guardrailID uuid.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *DB) ListPlanGuardrails(ctx context.Context, planID uuid.UUID) ([]ext.AgentGuardrail, error) {
|
||||
func (db *DB) ListPlanGuardrails(ctx context.Context, planID int64) ([]ext.AgentGuardrail, error) {
|
||||
rows, err := db.pool.Query(ctx, `
|
||||
select g.id, g.name, g.description, g.content, g.severity, g.tags::text[], g.created_at, g.updated_at
|
||||
from agent_guardrails g
|
||||
@@ -394,7 +394,7 @@ func (db *DB) ListPlanGuardrails(ctx context.Context, planID uuid.UUID) ([]ext.A
|
||||
return nil, fmt.Errorf("scan plan guardrail: %w", err)
|
||||
}
|
||||
g := ext.AgentGuardrail{
|
||||
ID: model.ID.UUID(),
|
||||
ID: model.ID.Int64(),
|
||||
Name: model.Name.String(),
|
||||
Description: model.Description.String(),
|
||||
Content: model.Content.String(),
|
||||
@@ -422,6 +422,7 @@ func scanPlan(row planScanner) (ext.Plan, error) {
|
||||
var tags []string
|
||||
err := row.Scan(
|
||||
&model.ID,
|
||||
&model.GUID,
|
||||
&model.Title,
|
||||
&model.Description,
|
||||
&model.Status,
|
||||
@@ -467,9 +468,9 @@ func (db *DB) listPlansByQuery(ctx context.Context, query string, args ...any) (
|
||||
return plans, nil
|
||||
}
|
||||
|
||||
// canonicalPlanPair ensures the smaller UUID is always plan_a_id to prevent duplicates.
|
||||
func canonicalPlanPair(a, b uuid.UUID) (uuid.UUID, uuid.UUID) {
|
||||
if strings.Compare(a.String(), b.String()) <= 0 {
|
||||
// canonicalPlanPair ensures the smaller ID is always plan_a_id to prevent duplicates.
|
||||
func canonicalPlanPair(a, b int64) (int64, int64) {
|
||||
if a <= b {
|
||||
return a, b
|
||||
}
|
||||
return b, a
|
||||
|
||||
Reference in New Issue
Block a user