diff --git a/internal/generatedmodels/sql_public_agent_guardrails.go b/internal/generatedmodels/sql_public_agent_guardrails.go index 6cce557..ee3af06 100644 --- a/internal/generatedmodels/sql_public_agent_guardrails.go +++ b/internal/generatedmodels/sql_public_agent_guardrails.go @@ -9,10 +9,11 @@ import ( type ModelPublicAgentGuardrails struct { bun.BaseModel `bun:"table:public.agent_guardrails,alias:agent_guardrails"` - ID resolvespec_common.SqlUUID `bun:"id,type:uuid,pk,default:gen_random_uuid()," json:"id"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` Content resolvespec_common.SqlString `bun:"content,type:text,notnull," json:"content"` CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` Description resolvespec_common.SqlString `bun:"description,type:text,default:'',notnull," json:"description"` + GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` Name resolvespec_common.SqlString `bun:"name,type:text,notnull," json:"name"` Severity resolvespec_common.SqlString `bun:"severity,type:text,default:'medium',notnull," json:"severity"` Tags resolvespec_common.SqlString `bun:"tags,type:text,nullzero," json:"tags"` diff --git a/internal/generatedmodels/sql_public_agent_skills.go b/internal/generatedmodels/sql_public_agent_skills.go index d3ac912..2c91489 100644 --- a/internal/generatedmodels/sql_public_agent_skills.go +++ b/internal/generatedmodels/sql_public_agent_skills.go @@ -9,10 +9,11 @@ import ( type ModelPublicAgentSkills struct { bun.BaseModel `bun:"table:public.agent_skills,alias:agent_skills"` - ID resolvespec_common.SqlUUID `bun:"id,type:uuid,pk,default:gen_random_uuid()," json:"id"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` Content resolvespec_common.SqlString `bun:"content,type:text,notnull," json:"content"` CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` Description resolvespec_common.SqlString `bun:"description,type:text,default:'',notnull," json:"description"` + GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` Name resolvespec_common.SqlString `bun:"name,type:text,notnull," json:"name"` Tags resolvespec_common.SqlString `bun:"tags,type:text,nullzero," json:"tags"` UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` diff --git a/internal/generatedmodels/sql_public_chat_histories.go b/internal/generatedmodels/sql_public_chat_histories.go index be126c1..ce87e96 100644 --- a/internal/generatedmodels/sql_public_chat_histories.go +++ b/internal/generatedmodels/sql_public_chat_histories.go @@ -9,18 +9,19 @@ import ( type ModelPublicChatHistories struct { bun.BaseModel `bun:"table:public.chat_histories,alias:chat_histories"` - ID resolvespec_common.SqlUUID `bun:"id,type:uuid,pk,default:gen_random_uuid()," json:"id"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` AgentID resolvespec_common.SqlString `bun:"agent_id,type:text,nullzero," json:"agent_id"` Channel resolvespec_common.SqlString `bun:"channel,type:text,nullzero," json:"channel"` CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` + GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` Messages resolvespec_common.SqlJSONB `bun:"messages,type:jsonb,default:'[',notnull," json:"messages"` Metadata resolvespec_common.SqlJSONB `bun:"metadata,type:jsonb,default:'{}',notnull," json:"metadata"` - ProjectID resolvespec_common.SqlUUID `bun:"project_id,type:uuid,nullzero," json:"project_id"` + ProjectID resolvespec_common.SqlInt64 `bun:"project_id,type:bigint,nullzero," json:"project_id"` SessionID resolvespec_common.SqlString `bun:"session_id,type:text,notnull," json:"session_id"` Summary resolvespec_common.SqlString `bun:"summary,type:text,nullzero," json:"summary"` Title resolvespec_common.SqlString `bun:"title,type:text,nullzero," json:"title"` UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=guid" json:"relprojectid,omitempty"` // Has one ModelPublicProjects + RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects } // TableName returns the table name for ModelPublicChatHistories diff --git a/internal/generatedmodels/sql_public_embeddings.go b/internal/generatedmodels/sql_public_embeddings.go index 276c0da..da90976 100644 --- a/internal/generatedmodels/sql_public_embeddings.go +++ b/internal/generatedmodels/sql_public_embeddings.go @@ -15,9 +15,9 @@ type ModelPublicEmbeddings struct { Embedding resolvespec_common.SqlString `bun:"embedding,type:vector,notnull," json:"embedding"` GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` Model resolvespec_common.SqlString `bun:"model,type:text,notnull,unique:uidx_embeddings_thought_id_model," json:"model"` - ThoughtID resolvespec_common.SqlUUID `bun:"thought_id,type:uuid,notnull,unique:uidx_embeddings_thought_id_model," json:"thought_id"` + ThoughtID int64 `bun:"thought_id,type:bigint,notnull,unique:uidx_embeddings_thought_id_model," json:"thought_id"` UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),nullzero," json:"updated_at"` - RelThoughtID *ModelPublicThoughts `bun:"rel:has-one,join:thought_id=guid" json:"relthoughtid,omitempty"` // Has one ModelPublicThoughts + RelThoughtID *ModelPublicThoughts `bun:"rel:has-one,join:thought_id=id" json:"relthoughtid,omitempty"` // Has one ModelPublicThoughts } // TableName returns the table name for ModelPublicEmbeddings diff --git a/internal/generatedmodels/sql_public_learnings.go b/internal/generatedmodels/sql_public_learnings.go index 736f56f..dfb2eff 100644 --- a/internal/generatedmodels/sql_public_learnings.go +++ b/internal/generatedmodels/sql_public_learnings.go @@ -9,31 +9,32 @@ import ( type ModelPublicLearnings struct { bun.BaseModel `bun:"table:public.learnings,alias:learnings"` - ID resolvespec_common.SqlUUID `bun:"id,type:uuid,pk,default:gen_random_uuid()," json:"id"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` ActionRequired bool `bun:"action_required,type:boolean,default:false,notnull," json:"action_required"` Area resolvespec_common.SqlString `bun:"area,type:text,default:'other',notnull," json:"area"` Category resolvespec_common.SqlString `bun:"category,type:text,default:'insight',notnull," json:"category"` Confidence resolvespec_common.SqlString `bun:"confidence,type:text,default:'hypothesis',notnull," json:"confidence"` CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` Details resolvespec_common.SqlString `bun:"details,type:text,default:'',notnull," json:"details"` - DuplicateOfLearningID resolvespec_common.SqlUUID `bun:"duplicate_of_learning_id,type:uuid,nullzero," json:"duplicate_of_learning_id"` + DuplicateOfLearningID resolvespec_common.SqlInt64 `bun:"duplicate_of_learning_id,type:bigint,nullzero," json:"duplicate_of_learning_id"` + GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` Priority resolvespec_common.SqlString `bun:"priority,type:text,default:'medium',notnull," json:"priority"` - ProjectID resolvespec_common.SqlUUID `bun:"project_id,type:uuid,nullzero," json:"project_id"` - RelatedSkillID resolvespec_common.SqlUUID `bun:"related_skill_id,type:uuid,nullzero," json:"related_skill_id"` - RelatedThoughtID resolvespec_common.SqlUUID `bun:"related_thought_id,type:uuid,nullzero," json:"related_thought_id"` + ProjectID resolvespec_common.SqlInt64 `bun:"project_id,type:bigint,nullzero," json:"project_id"` + RelatedSkillID resolvespec_common.SqlInt64 `bun:"related_skill_id,type:bigint,nullzero," json:"related_skill_id"` + RelatedThoughtID resolvespec_common.SqlInt64 `bun:"related_thought_id,type:bigint,nullzero," json:"related_thought_id"` ReviewedAt resolvespec_common.SqlTimeStamp `bun:"reviewed_at,type:timestamptz,nullzero," json:"reviewed_at"` ReviewedBy resolvespec_common.SqlString `bun:"reviewed_by,type:text,nullzero," json:"reviewed_by"` SourceRef resolvespec_common.SqlString `bun:"source_ref,type:text,nullzero," json:"source_ref"` SourceType resolvespec_common.SqlString `bun:"source_type,type:text,nullzero," json:"source_type"` Status resolvespec_common.SqlString `bun:"status,type:text,default:'pending',notnull," json:"status"` Summary resolvespec_common.SqlString `bun:"summary,type:text,notnull," json:"summary"` - SupersedesLearningID resolvespec_common.SqlUUID `bun:"supersedes_learning_id,type:uuid,nullzero," json:"supersedes_learning_id"` + SupersedesLearningID resolvespec_common.SqlInt64 `bun:"supersedes_learning_id,type:bigint,nullzero," json:"supersedes_learning_id"` Tags resolvespec_common.SqlString `bun:"tags,type:text,nullzero," json:"tags"` UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` RelDuplicateOfLearningID *ModelPublicLearnings `bun:"rel:has-one,join:duplicate_of_learning_id=id" json:"relduplicateoflearningid,omitempty"` // Has one ModelPublicLearnings - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=guid" json:"relprojectid,omitempty"` // Has one ModelPublicProjects + RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects RelRelatedSkillID *ModelPublicAgentSkills `bun:"rel:has-one,join:related_skill_id=id" json:"relrelatedskillid,omitempty"` // Has one ModelPublicAgentSkills - RelRelatedThoughtID *ModelPublicThoughts `bun:"rel:has-one,join:related_thought_id=guid" json:"relrelatedthoughtid,omitempty"` // Has one ModelPublicThoughts + RelRelatedThoughtID *ModelPublicThoughts `bun:"rel:has-one,join:related_thought_id=id" json:"relrelatedthoughtid,omitempty"` // Has one ModelPublicThoughts RelSupersedesLearningID *ModelPublicLearnings `bun:"rel:has-one,join:supersedes_learning_id=id" json:"relsupersedeslearningid,omitempty"` // Has one ModelPublicLearnings } diff --git a/internal/generatedmodels/sql_public_plan_dependencies.go b/internal/generatedmodels/sql_public_plan_dependencies.go index 36f9153..3b23540 100644 --- a/internal/generatedmodels/sql_public_plan_dependencies.go +++ b/internal/generatedmodels/sql_public_plan_dependencies.go @@ -9,10 +9,10 @@ import ( type ModelPublicPlanDependencies struct { bun.BaseModel `bun:"table:public.plan_dependencies,alias:plan_dependencies"` - ID resolvespec_common.SqlInt32 `bun:"id,type:serial,pk,autoincrement," json:"id"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - DependsOnPlanID resolvespec_common.SqlUUID `bun:"depends_on_plan_id,type:uuid,notnull,unique:uidx_plan_dependencies_plan_id_depends_on_plan_id," json:"depends_on_plan_id"` - PlanID resolvespec_common.SqlUUID `bun:"plan_id,type:uuid,notnull,unique:uidx_plan_dependencies_plan_id_depends_on_plan_id," json:"plan_id"` + DependsOnPlanID int64 `bun:"depends_on_plan_id,type:bigint,notnull,unique:uidx_plan_dependencies_plan_id_depends_on_plan_id," json:"depends_on_plan_id"` + PlanID int64 `bun:"plan_id,type:bigint,notnull,unique:uidx_plan_dependencies_plan_id_depends_on_plan_id," json:"plan_id"` RelDependsOnPlanID *ModelPublicPlans `bun:"rel:has-one,join:depends_on_plan_id=id" json:"reldependsonplanid,omitempty"` // Has one ModelPublicPlans RelPlanID *ModelPublicPlans `bun:"rel:has-one,join:plan_id=id" json:"relplanid,omitempty"` // Has one ModelPublicPlans } diff --git a/internal/generatedmodels/sql_public_plan_guardrails.go b/internal/generatedmodels/sql_public_plan_guardrails.go index 4c2f750..680d930 100644 --- a/internal/generatedmodels/sql_public_plan_guardrails.go +++ b/internal/generatedmodels/sql_public_plan_guardrails.go @@ -9,10 +9,10 @@ import ( type ModelPublicPlanGuardrails struct { bun.BaseModel `bun:"table:public.plan_guardrails,alias:plan_guardrails"` - ID resolvespec_common.SqlInt32 `bun:"id,type:serial,pk,autoincrement," json:"id"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - GuardrailID resolvespec_common.SqlUUID `bun:"guardrail_id,type:uuid,notnull,unique:uidx_plan_guardrails_plan_id_guardrail_id," json:"guardrail_id"` - PlanID resolvespec_common.SqlUUID `bun:"plan_id,type:uuid,notnull,unique:uidx_plan_guardrails_plan_id_guardrail_id," json:"plan_id"` + GuardrailID int64 `bun:"guardrail_id,type:bigint,notnull,unique:uidx_plan_guardrails_plan_id_guardrail_id," json:"guardrail_id"` + PlanID int64 `bun:"plan_id,type:bigint,notnull,unique:uidx_plan_guardrails_plan_id_guardrail_id," json:"plan_id"` RelGuardrailID *ModelPublicAgentGuardrails `bun:"rel:has-one,join:guardrail_id=id" json:"relguardrailid,omitempty"` // Has one ModelPublicAgentGuardrails RelPlanID *ModelPublicPlans `bun:"rel:has-one,join:plan_id=id" json:"relplanid,omitempty"` // Has one ModelPublicPlans } diff --git a/internal/generatedmodels/sql_public_plan_related_plans.go b/internal/generatedmodels/sql_public_plan_related_plans.go index 1c52fa1..101a686 100644 --- a/internal/generatedmodels/sql_public_plan_related_plans.go +++ b/internal/generatedmodels/sql_public_plan_related_plans.go @@ -9,10 +9,10 @@ import ( type ModelPublicPlanRelatedPlans struct { bun.BaseModel `bun:"table:public.plan_related_plans,alias:plan_related_plans"` - ID resolvespec_common.SqlInt32 `bun:"id,type:serial,pk,autoincrement," json:"id"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - PlanAID resolvespec_common.SqlUUID `bun:"plan_a_id,type:uuid,notnull,unique:uidx_plan_related_plans_plan_a_id_plan_b_id," json:"plan_a_id"` - PlanBID resolvespec_common.SqlUUID `bun:"plan_b_id,type:uuid,notnull,unique:uidx_plan_related_plans_plan_a_id_plan_b_id," json:"plan_b_id"` + PlanAID int64 `bun:"plan_a_id,type:bigint,notnull,unique:uidx_plan_related_plans_plan_a_id_plan_b_id," json:"plan_a_id"` + PlanBID int64 `bun:"plan_b_id,type:bigint,notnull,unique:uidx_plan_related_plans_plan_a_id_plan_b_id," json:"plan_b_id"` RelPlanAID *ModelPublicPlans `bun:"rel:has-one,join:plan_a_id=id" json:"relplanaid,omitempty"` // Has one ModelPublicPlans RelPlanBID *ModelPublicPlans `bun:"rel:has-one,join:plan_b_id=id" json:"relplanbid,omitempty"` // Has one ModelPublicPlans } diff --git a/internal/generatedmodels/sql_public_plan_skills.go b/internal/generatedmodels/sql_public_plan_skills.go index 42947b6..62fee56 100644 --- a/internal/generatedmodels/sql_public_plan_skills.go +++ b/internal/generatedmodels/sql_public_plan_skills.go @@ -9,10 +9,10 @@ import ( type ModelPublicPlanSkills struct { bun.BaseModel `bun:"table:public.plan_skills,alias:plan_skills"` - ID resolvespec_common.SqlInt32 `bun:"id,type:serial,pk,autoincrement," json:"id"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - PlanID resolvespec_common.SqlUUID `bun:"plan_id,type:uuid,notnull,unique:uidx_plan_skills_plan_id_skill_id," json:"plan_id"` - SkillID resolvespec_common.SqlUUID `bun:"skill_id,type:uuid,notnull,unique:uidx_plan_skills_plan_id_skill_id," json:"skill_id"` + PlanID int64 `bun:"plan_id,type:bigint,notnull,unique:uidx_plan_skills_plan_id_skill_id," json:"plan_id"` + SkillID int64 `bun:"skill_id,type:bigint,notnull,unique:uidx_plan_skills_plan_id_skill_id," json:"skill_id"` RelPlanID *ModelPublicPlans `bun:"rel:has-one,join:plan_id=id" json:"relplanid,omitempty"` // Has one ModelPublicPlans RelSkillID *ModelPublicAgentSkills `bun:"rel:has-one,join:skill_id=id" json:"relskillid,omitempty"` // Has one ModelPublicAgentSkills } diff --git a/internal/generatedmodels/sql_public_plans.go b/internal/generatedmodels/sql_public_plans.go index ecae26b..3cd52a1 100644 --- a/internal/generatedmodels/sql_public_plans.go +++ b/internal/generatedmodels/sql_public_plans.go @@ -9,22 +9,23 @@ import ( type ModelPublicPlans struct { bun.BaseModel `bun:"table:public.plans,alias:plans"` - ID resolvespec_common.SqlUUID `bun:"id,type:uuid,pk,default:gen_random_uuid()," json:"id"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` CompletedAt resolvespec_common.SqlTimeStamp `bun:"completed_at,type:timestamptz,nullzero," json:"completed_at"` CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` Description resolvespec_common.SqlString `bun:"description,type:text,default:'',notnull," json:"description"` DueDate resolvespec_common.SqlTimeStamp `bun:"due_date,type:timestamptz,nullzero," json:"due_date"` + GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` LastReviewedAt resolvespec_common.SqlTimeStamp `bun:"last_reviewed_at,type:timestamptz,nullzero," json:"last_reviewed_at"` Owner resolvespec_common.SqlString `bun:"owner,type:text,nullzero," json:"owner"` Priority resolvespec_common.SqlString `bun:"priority,type:text,default:'medium',notnull," json:"priority"` // low, medium, high, critical - ProjectID resolvespec_common.SqlUUID `bun:"project_id,type:uuid,nullzero," json:"project_id"` + ProjectID resolvespec_common.SqlInt64 `bun:"project_id,type:bigint,nullzero," json:"project_id"` ReviewedBy resolvespec_common.SqlString `bun:"reviewed_by,type:text,nullzero," json:"reviewed_by"` Status resolvespec_common.SqlString `bun:"status,type:text,default:'draft',notnull," json:"status"` // draft, active, blocked, completed, cancelled, superseded - SupersedesPlanID resolvespec_common.SqlUUID `bun:"supersedes_plan_id,type:uuid,nullzero," json:"supersedes_plan_id"` + SupersedesPlanID resolvespec_common.SqlInt64 `bun:"supersedes_plan_id,type:bigint,nullzero," json:"supersedes_plan_id"` Tags resolvespec_common.SqlString `bun:"tags,type:text,nullzero," json:"tags"` Title resolvespec_common.SqlString `bun:"title,type:text,notnull," json:"title"` UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=guid" json:"relprojectid,omitempty"` // Has one ModelPublicProjects + RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects RelSupersedesPlanID *ModelPublicPlans `bun:"rel:has-one,join:supersedes_plan_id=id" json:"relsupersedesplanid,omitempty"` // Has one ModelPublicPlans RelDependsOnPlanIDPublicPlanDependencies []*ModelPublicPlanDependencies `bun:"rel:has-many,join:id=depends_on_plan_id" json:"reldependsonplanidpublicplandependencies,omitempty"` // Has many ModelPublicPlanDependencies RelPlanIDPublicPlanDependencies []*ModelPublicPlanDependencies `bun:"rel:has-many,join:id=plan_id" json:"relplanidpublicplandependencies,omitempty"` // Has many ModelPublicPlanDependencies diff --git a/internal/generatedmodels/sql_public_project_guardrails.go b/internal/generatedmodels/sql_public_project_guardrails.go index 07423e5..9db3e31 100644 --- a/internal/generatedmodels/sql_public_project_guardrails.go +++ b/internal/generatedmodels/sql_public_project_guardrails.go @@ -9,12 +9,12 @@ import ( type ModelPublicProjectGuardrails struct { bun.BaseModel `bun:"table:public.project_guardrails,alias:project_guardrails"` - ID resolvespec_common.SqlInt32 `bun:"id,type:serial,pk,autoincrement," json:"id"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - GuardrailID resolvespec_common.SqlUUID `bun:"guardrail_id,type:uuid,notnull," json:"guardrail_id"` - ProjectID resolvespec_common.SqlUUID `bun:"project_id,type:uuid,notnull," json:"project_id"` + GuardrailID int64 `bun:"guardrail_id,type:bigint,notnull," json:"guardrail_id"` + ProjectID int64 `bun:"project_id,type:bigint,notnull," json:"project_id"` RelGuardrailID *ModelPublicAgentGuardrails `bun:"rel:has-one,join:guardrail_id=id" json:"relguardrailid,omitempty"` // Has one ModelPublicAgentGuardrails - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=guid" json:"relprojectid,omitempty"` // Has one ModelPublicProjects + RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects } // TableName returns the table name for ModelPublicProjectGuardrails diff --git a/internal/generatedmodels/sql_public_project_skills.go b/internal/generatedmodels/sql_public_project_skills.go index 1935a1e..9eabbbf 100644 --- a/internal/generatedmodels/sql_public_project_skills.go +++ b/internal/generatedmodels/sql_public_project_skills.go @@ -9,12 +9,12 @@ import ( type ModelPublicProjectSkills struct { bun.BaseModel `bun:"table:public.project_skills,alias:project_skills"` - ID resolvespec_common.SqlInt32 `bun:"id,type:serial,pk,autoincrement," json:"id"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - ProjectID resolvespec_common.SqlUUID `bun:"project_id,type:uuid,notnull," json:"project_id"` - SkillID resolvespec_common.SqlUUID `bun:"skill_id,type:uuid,notnull," json:"skill_id"` - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=guid" json:"relprojectid,omitempty"` // Has one ModelPublicProjects - RelSkillID *ModelPublicAgentSkills `bun:"rel:has-one,join:skill_id=id" json:"relskillid,omitempty"` // Has one ModelPublicAgentSkills + ProjectID int64 `bun:"project_id,type:bigint,notnull," json:"project_id"` + SkillID int64 `bun:"skill_id,type:bigint,notnull," json:"skill_id"` + RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects + RelSkillID *ModelPublicAgentSkills `bun:"rel:has-one,join:skill_id=id" json:"relskillid,omitempty"` // Has one ModelPublicAgentSkills } // TableName returns the table name for ModelPublicProjectSkills diff --git a/internal/generatedmodels/sql_public_projects.go b/internal/generatedmodels/sql_public_projects.go index 92ad209..0585663 100644 --- a/internal/generatedmodels/sql_public_projects.go +++ b/internal/generatedmodels/sql_public_projects.go @@ -16,13 +16,13 @@ type ModelPublicProjects struct { LastActiveAt resolvespec_common.SqlTimeStamp `bun:"last_active_at,type:timestamptz,default:now(),nullzero," json:"last_active_at"` Name resolvespec_common.SqlString `bun:"name,type:text,notnull," json:"name"` ThoughtCount resolvespec_common.SqlInt64 `bun:"thought_count,scanonly" json:"thought_count"` - RelProjectIDPublicThoughts []*ModelPublicThoughts `bun:"rel:has-many,join:guid=project_id" json:"relprojectidpublicthoughts,omitempty"` // Has many ModelPublicThoughts - RelProjectIDPublicStoredFiles []*ModelPublicStoredFiles `bun:"rel:has-many,join:guid=project_id" json:"relprojectidpublicstoredfiles,omitempty"` // Has many ModelPublicStoredFiles - RelProjectIDPublicChatHistories []*ModelPublicChatHistories `bun:"rel:has-many,join:guid=project_id" json:"relprojectidpublicchathistories,omitempty"` // Has many ModelPublicChatHistories - RelProjectIDPublicLearnings []*ModelPublicLearnings `bun:"rel:has-many,join:guid=project_id" json:"relprojectidpubliclearnings,omitempty"` // Has many ModelPublicLearnings - RelProjectIDPublicPlans []*ModelPublicPlans `bun:"rel:has-many,join:guid=project_id" json:"relprojectidpublicplans,omitempty"` // Has many ModelPublicPlans - RelProjectIDPublicProjectSkills []*ModelPublicProjectSkills `bun:"rel:has-many,join:guid=project_id" json:"relprojectidpublicprojectskills,omitempty"` // Has many ModelPublicProjectSkills - RelProjectIDPublicProjectGuardrails []*ModelPublicProjectGuardrails `bun:"rel:has-many,join:guid=project_id" json:"relprojectidpublicprojectguardrails,omitempty"` // Has many ModelPublicProjectGuardrails + RelProjectIDPublicThoughts []*ModelPublicThoughts `bun:"rel:has-many,join:id=project_id" json:"relprojectidpublicthoughts,omitempty"` // Has many ModelPublicThoughts + RelProjectIDPublicStoredFiles []*ModelPublicStoredFiles `bun:"rel:has-many,join:id=project_id" json:"relprojectidpublicstoredfiles,omitempty"` // Has many ModelPublicStoredFiles + RelProjectIDPublicChatHistories []*ModelPublicChatHistories `bun:"rel:has-many,join:id=project_id" json:"relprojectidpublicchathistories,omitempty"` // Has many ModelPublicChatHistories + RelProjectIDPublicLearnings []*ModelPublicLearnings `bun:"rel:has-many,join:id=project_id" json:"relprojectidpubliclearnings,omitempty"` // Has many ModelPublicLearnings + RelProjectIDPublicPlans []*ModelPublicPlans `bun:"rel:has-many,join:id=project_id" json:"relprojectidpublicplans,omitempty"` // Has many ModelPublicPlans + RelProjectIDPublicProjectSkills []*ModelPublicProjectSkills `bun:"rel:has-many,join:id=project_id" json:"relprojectidpublicprojectskills,omitempty"` // Has many ModelPublicProjectSkills + RelProjectIDPublicProjectGuardrails []*ModelPublicProjectGuardrails `bun:"rel:has-many,join:id=project_id" json:"relprojectidpublicprojectguardrails,omitempty"` // Has many ModelPublicProjectGuardrails } // TableName returns the table name for ModelPublicProjects diff --git a/internal/generatedmodels/sql_public_stored_files.go b/internal/generatedmodels/sql_public_stored_files.go index fd970d4..e6a1422 100644 --- a/internal/generatedmodels/sql_public_stored_files.go +++ b/internal/generatedmodels/sql_public_stored_files.go @@ -17,13 +17,13 @@ type ModelPublicStoredFiles struct { Kind resolvespec_common.SqlString `bun:"kind,type:text,default:'file',notnull," json:"kind"` MediaType resolvespec_common.SqlString `bun:"media_type,type:text,notnull," json:"media_type"` Name resolvespec_common.SqlString `bun:"name,type:text,notnull," json:"name"` - ProjectID resolvespec_common.SqlUUID `bun:"project_id,type:uuid,nullzero," json:"project_id"` + ProjectID resolvespec_common.SqlInt64 `bun:"project_id,type:bigint,nullzero," json:"project_id"` Sha256 resolvespec_common.SqlString `bun:"sha256,type:text,notnull," json:"sha256"` SizeBytes int64 `bun:"size_bytes,type:bigint,notnull," json:"size_bytes"` - ThoughtID resolvespec_common.SqlUUID `bun:"thought_id,type:uuid,nullzero," json:"thought_id"` + ThoughtID resolvespec_common.SqlInt64 `bun:"thought_id,type:bigint,nullzero," json:"thought_id"` UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=guid" json:"relprojectid,omitempty"` // Has one ModelPublicProjects - RelThoughtID *ModelPublicThoughts `bun:"rel:has-one,join:thought_id=guid" json:"relthoughtid,omitempty"` // Has one ModelPublicThoughts + RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects + RelThoughtID *ModelPublicThoughts `bun:"rel:has-one,join:thought_id=id" json:"relthoughtid,omitempty"` // Has one ModelPublicThoughts } // TableName returns the table name for ModelPublicStoredFiles diff --git a/internal/generatedmodels/sql_public_thought_links.go b/internal/generatedmodels/sql_public_thought_links.go index b534f4a..a945fc1 100644 --- a/internal/generatedmodels/sql_public_thought_links.go +++ b/internal/generatedmodels/sql_public_thought_links.go @@ -9,7 +9,7 @@ import ( type ModelPublicThoughtLinks struct { bun.BaseModel `bun:"table:public.thought_links,alias:thought_links"` - ID resolvespec_common.SqlInt32 `bun:"id,type:serial,pk,autoincrement," json:"id"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),nullzero," json:"created_at"` FromID int64 `bun:"from_id,type:bigint,notnull," json:"from_id"` Relation resolvespec_common.SqlString `bun:"relation,type:text,notnull," json:"relation"` diff --git a/internal/generatedmodels/sql_public_thoughts.go b/internal/generatedmodels/sql_public_thoughts.go index 3f1dec3..e3dc038 100644 --- a/internal/generatedmodels/sql_public_thoughts.go +++ b/internal/generatedmodels/sql_public_thoughts.go @@ -15,14 +15,14 @@ type ModelPublicThoughts struct { CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),nullzero," json:"created_at"` GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` Metadata resolvespec_common.SqlJSONB `bun:"metadata,type:jsonb,default:'{}::jsonb',nullzero," json:"metadata"` - ProjectID resolvespec_common.SqlUUID `bun:"project_id,type:uuid,nullzero," json:"project_id"` + ProjectID resolvespec_common.SqlInt64 `bun:"project_id,type:bigint,nullzero," json:"project_id"` UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),nullzero," json:"updated_at"` - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=guid" json:"relprojectid,omitempty"` // Has one ModelPublicProjects - RelFromIDPublicThoughtLinks []*ModelPublicThoughtLinks `bun:"rel:has-many,join:id=from_id" json:"relfromidpublicthoughtlinks,omitempty"` // Has many ModelPublicThoughtLinks - RelToIDPublicThoughtLinks []*ModelPublicThoughtLinks `bun:"rel:has-many,join:id=to_id" json:"reltoidpublicthoughtlinks,omitempty"` // Has many ModelPublicThoughtLinks - RelThoughtIDPublicEmbeddings []*ModelPublicEmbeddings `bun:"rel:has-many,join:guid=thought_id" json:"relthoughtidpublicembeddings,omitempty"` // Has many ModelPublicEmbeddings - RelThoughtIDPublicStoredFiles []*ModelPublicStoredFiles `bun:"rel:has-many,join:guid=thought_id" json:"relthoughtidpublicstoredfiles,omitempty"` // Has many ModelPublicStoredFiles - RelRelatedThoughtIDPublicLearnings []*ModelPublicLearnings `bun:"rel:has-many,join:guid=related_thought_id" json:"relrelatedthoughtidpubliclearnings,omitempty"` // Has many ModelPublicLearnings + RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects + RelFromIDPublicThoughtLinks []*ModelPublicThoughtLinks `bun:"rel:has-many,join:id=from_id" json:"relfromidpublicthoughtlinks,omitempty"` // Has many ModelPublicThoughtLinks + RelToIDPublicThoughtLinks []*ModelPublicThoughtLinks `bun:"rel:has-many,join:id=to_id" json:"reltoidpublicthoughtlinks,omitempty"` // Has many ModelPublicThoughtLinks + RelThoughtIDPublicEmbeddings []*ModelPublicEmbeddings `bun:"rel:has-many,join:id=thought_id" json:"relthoughtidpublicembeddings,omitempty"` // Has many ModelPublicEmbeddings + RelThoughtIDPublicStoredFiles []*ModelPublicStoredFiles `bun:"rel:has-many,join:id=thought_id" json:"relthoughtidpublicstoredfiles,omitempty"` // Has many ModelPublicStoredFiles + RelRelatedThoughtIDPublicLearnings []*ModelPublicLearnings `bun:"rel:has-many,join:id=related_thought_id" json:"relrelatedthoughtidpubliclearnings,omitempty"` // Has many ModelPublicLearnings } // TableName returns the table name for ModelPublicThoughts diff --git a/internal/store/chat_histories.go b/internal/store/chat_histories.go index 6e23706..ac84c2a 100644 --- a/internal/store/chat_histories.go +++ b/internal/store/chat_histories.go @@ -7,7 +7,6 @@ import ( "strings" "time" - "github.com/google/uuid" "github.com/jackc/pgx/v5" "git.warky.dev/wdevs/amcs/internal/generatedmodels" @@ -28,7 +27,7 @@ func (db *DB) SaveChatHistory(ctx context.Context, h ext.ChatHistory) (ext.ChatH insert into chat_histories (session_id, title, channel, agent_id, project_id, messages, summary, metadata) values ($1, $2, $3, $4, $5, $6, $7, $8) - returning id, created_at, updated_at + returning id, guid, created_at, updated_at `, h.SessionID, nullStr(h.Title), nullStr(h.Channel), nullStr(h.AgentID), h.ProjectID, messages, nullStr(h.Summary), meta, @@ -36,16 +35,17 @@ func (db *DB) SaveChatHistory(ctx context.Context, h ext.ChatHistory) (ext.ChatH created := h var model generatedmodels.ModelPublicChatHistories - if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil { + if err := row.Scan(&model.ID, &model.GUID, &model.CreatedAt, &model.UpdatedAt); err != nil { return ext.ChatHistory{}, fmt.Errorf("insert chat history: %w", err) } - created.ID = model.ID.UUID() + created.ID = model.ID.Int64() + created.GUID = model.GUID.UUID() created.CreatedAt = model.CreatedAt.Time() created.UpdatedAt = model.UpdatedAt.Time() return created, nil } -func (db *DB) GetChatHistory(ctx context.Context, id uuid.UUID) (ext.ChatHistory, bool, error) { +func (db *DB) GetChatHistory(ctx context.Context, id int64) (ext.ChatHistory, bool, error) { row := db.pool.QueryRow(ctx, ` select id, session_id, title, channel, agent_id, project_id, messages, summary, metadata, created_at, updated_at @@ -81,7 +81,7 @@ func (db *DB) GetChatHistoryBySessionID(ctx context.Context, sessionID string) ( } type ListChatHistoriesFilter struct { - ProjectID *uuid.UUID + ProjectID *int64 Channel string AgentID string SessionID string @@ -149,7 +149,7 @@ func (db *DB) ListChatHistories(ctx context.Context, f ListChatHistoriesFilter) return result, rows.Err() } -func (db *DB) DeleteChatHistory(ctx context.Context, id uuid.UUID) (bool, error) { +func (db *DB) DeleteChatHistory(ctx context.Context, id int64) (bool, error) { tag, err := db.pool.Exec(ctx, `delete from chat_histories where id = $1`, id) if err != nil { return false, fmt.Errorf("delete chat history: %w", err) @@ -171,7 +171,8 @@ func scanChatHistory(row rowScanner) (ext.ChatHistory, error) { } h := ext.ChatHistory{ - ID: model.ID.UUID(), + ID: model.ID.Int64(), + GUID: model.GUID.UUID(), SessionID: model.SessionID.String(), Title: model.Title.String(), Channel: model.Channel.String(), @@ -181,7 +182,7 @@ func scanChatHistory(row rowScanner) (ext.ChatHistory, error) { UpdatedAt: model.UpdatedAt.Time(), } if model.ProjectID.Valid { - id := model.ProjectID.UUID() + id := model.ProjectID.Int64() h.ProjectID = &id } diff --git a/internal/store/files.go b/internal/store/files.go index 89b8043..4841ef6 100644 --- a/internal/store/files.go +++ b/internal/store/files.go @@ -17,11 +17,12 @@ func (db *DB) InsertStoredFile(ctx context.Context, file thoughttypes.StoredFile row := db.pool.QueryRow(ctx, ` insert into stored_files (thought_id, project_id, name, media_type, kind, encoding, size_bytes, sha256, content) values ($1, $2, $3, $4, $5, $6, $7, $8, $9) - returning guid, thought_id, project_id, name, media_type, kind, encoding, size_bytes, sha256, created_at, updated_at + returning id, guid, thought_id, project_id, name, media_type, kind, encoding, size_bytes, sha256, created_at, updated_at `, file.ThoughtID, file.ProjectID, file.Name, file.MediaType, file.Kind, file.Encoding, file.SizeBytes, file.SHA256, file.Content) var model generatedmodels.ModelPublicStoredFiles if err := row.Scan( + &model.ID, &model.GUID, &model.ThoughtID, &model.ProjectID, @@ -42,13 +43,14 @@ func (db *DB) InsertStoredFile(ctx context.Context, file thoughttypes.StoredFile func (db *DB) GetStoredFile(ctx context.Context, id uuid.UUID) (thoughttypes.StoredFile, error) { row := db.pool.QueryRow(ctx, ` - select guid, thought_id, project_id, name, media_type, kind, encoding, size_bytes, sha256, content, created_at, updated_at + select id, guid, thought_id, project_id, name, media_type, kind, encoding, size_bytes, sha256, content, created_at, updated_at from stored_files where guid = $1 `, id) var model generatedmodels.ModelPublicStoredFiles if err := row.Scan( + &model.ID, &model.GUID, &model.ThoughtID, &model.ProjectID, @@ -89,7 +91,7 @@ func (db *DB) ListStoredFiles(ctx context.Context, filter thoughttypes.StoredFil } query := ` - select guid, thought_id, project_id, name, media_type, kind, encoding, size_bytes, sha256, created_at, updated_at + select id, guid, thought_id, project_id, name, media_type, kind, encoding, size_bytes, sha256, created_at, updated_at from stored_files ` if len(conditions) > 0 { @@ -109,6 +111,7 @@ func (db *DB) ListStoredFiles(ctx context.Context, filter thoughttypes.StoredFil for rows.Next() { var model generatedmodels.ModelPublicStoredFiles if err := rows.Scan( + &model.ID, &model.GUID, &model.ThoughtID, &model.ProjectID, @@ -132,7 +135,7 @@ func (db *DB) ListStoredFiles(ctx context.Context, filter thoughttypes.StoredFil return files, nil } -func (db *DB) AddThoughtAttachment(ctx context.Context, thoughtID uuid.UUID, attachment thoughttypes.ThoughtAttachment) error { +func (db *DB) AddThoughtAttachment(ctx context.Context, thoughtID int64, attachment thoughttypes.ThoughtAttachment) error { tx, err := db.pool.Begin(ctx) if err != nil { return fmt.Errorf("begin transaction: %w", err) @@ -142,7 +145,7 @@ func (db *DB) AddThoughtAttachment(ctx context.Context, thoughtID uuid.UUID, att }() var metadataBytes []byte - if err := tx.QueryRow(ctx, `select metadata from thoughts where guid = $1 for update`, thoughtID).Scan(&metadataBytes); err != nil { + if err := tx.QueryRow(ctx, `select metadata from thoughts where id = $1 for update`, thoughtID).Scan(&metadataBytes); err != nil { if err == pgx.ErrNoRows { return err } @@ -177,7 +180,7 @@ func (db *DB) AddThoughtAttachment(ctx context.Context, thoughtID uuid.UUID, att update thoughts set metadata = $2::jsonb, updated_at = now() - where guid = $1 + where id = $1 `, thoughtID, updatedMetadata) if err != nil { return fmt.Errorf("update thought attachments: %w", err) diff --git a/internal/store/learnings.go b/internal/store/learnings.go index 56640aa..801cb72 100644 --- a/internal/store/learnings.go +++ b/internal/store/learnings.go @@ -6,7 +6,6 @@ import ( "strings" "git.warky.dev/wdevs/amcs/internal/generatedmodels" - "github.com/google/uuid" "github.com/jackc/pgx/v5" thoughttypes "git.warky.dev/wdevs/amcs/internal/types" @@ -25,7 +24,7 @@ func (db *DB) CreateLearning(ctx context.Context, learning thoughttypes.Learning $13, $14, $15, $16, $17, $18 ) - returning id, created_at, updated_at + returning id, guid, created_at, updated_at `, strings.TrimSpace(learning.Summary), strings.TrimSpace(learning.Details), @@ -49,16 +48,17 @@ func (db *DB) CreateLearning(ctx context.Context, learning thoughttypes.Learning created := learning var model generatedmodels.ModelPublicLearnings - if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil { + if err := row.Scan(&model.ID, &model.GUID, &model.CreatedAt, &model.UpdatedAt); err != nil { return thoughttypes.Learning{}, fmt.Errorf("create learning: %w", err) } - created.ID = model.ID.UUID() + created.ID = model.ID.Int64() + created.GUID = model.GUID.UUID() created.CreatedAt = model.CreatedAt.Time() created.UpdatedAt = model.UpdatedAt.Time() return created, nil } -func (db *DB) GetLearning(ctx context.Context, id uuid.UUID) (thoughttypes.Learning, error) { +func (db *DB) GetLearning(ctx context.Context, id int64) (thoughttypes.Learning, error) { row := db.pool.QueryRow(ctx, ` select id, summary, details, category, area, status, priority, confidence, action_required, source_type, source_ref, project_id, related_thought_id, @@ -71,7 +71,7 @@ func (db *DB) GetLearning(ctx context.Context, id uuid.UUID) (thoughttypes.Learn learning, err := scanLearning(row) if err != nil { if err == pgx.ErrNoRows { - return thoughttypes.Learning{}, fmt.Errorf("learning not found: %s", id) + return thoughttypes.Learning{}, fmt.Errorf("learning not found: %d", id) } return thoughttypes.Learning{}, fmt.Errorf("get learning: %w", err) } diff --git a/internal/store/links.go b/internal/store/links.go index 8fd243b..dd96480 100644 --- a/internal/store/links.go +++ b/internal/store/links.go @@ -25,12 +25,12 @@ func (db *DB) InsertLink(ctx context.Context, link thoughttypes.ThoughtLink) err func (db *DB) LinkedThoughts(ctx context.Context, thoughtID uuid.UUID) ([]thoughttypes.LinkedThought, error) { rows, err := db.pool.Query(ctx, ` - select t.guid, t.content, t.metadata, t.project_id, t.archived_at, t.created_at, t.updated_at, l.relation, 'outgoing' as direction, l.created_at + select t.id, t.guid, t.content, t.metadata, t.project_id, t.archived_at, t.created_at, t.updated_at, l.relation, 'outgoing' as direction, l.created_at from thought_links l join thoughts t on t.id = l.to_id where l.from_id = (select id from thoughts where guid = $1) union all - select t.guid, t.content, t.metadata, t.project_id, t.archived_at, t.created_at, t.updated_at, l.relation, 'incoming' as direction, l.created_at + select t.id, t.guid, t.content, t.metadata, t.project_id, t.archived_at, t.created_at, t.updated_at, l.relation, 'incoming' as direction, l.created_at from thought_links l join thoughts t on t.id = l.from_id where l.to_id = (select id from thoughts where guid = $1) @@ -46,6 +46,7 @@ func (db *DB) LinkedThoughts(ctx context.Context, thoughtID uuid.UUID) ([]though var linked thoughttypes.LinkedThought var model generatedmodels.ModelPublicThoughts if err := rows.Scan( + &model.ID, &model.GUID, &model.Content, &model.Metadata, diff --git a/internal/store/model_adapters.go b/internal/store/model_adapters.go index b42534d..d9118e8 100644 --- a/internal/store/model_adapters.go +++ b/internal/store/model_adapters.go @@ -5,8 +5,6 @@ import ( "fmt" "time" - "github.com/google/uuid" - "git.warky.dev/wdevs/amcs/internal/generatedmodels" ext "git.warky.dev/wdevs/amcs/internal/types" ) @@ -14,6 +12,7 @@ import ( func projectFromModel(m generatedmodels.ModelPublicProjects) ext.Project { return ext.Project{ ID: m.GUID.UUID(), + NumericID: m.ID.Int64(), Name: m.Name.String(), Description: m.Description.String(), CreatedAt: m.CreatedAt.Time(), @@ -29,9 +28,9 @@ func thoughtFromModel(m generatedmodels.ModelPublicThoughts) (ext.Thought, error } } - var projectID *uuid.UUID + var projectID *int64 if m.ProjectID.Valid { - id := m.ProjectID.UUID() + id := m.ProjectID.Int64() projectID = &id } @@ -42,7 +41,8 @@ func thoughtFromModel(m generatedmodels.ModelPublicThoughts) (ext.Thought, error } return ext.Thought{ - ID: m.GUID.UUID(), + ID: m.ID.Int64(), + GUID: m.GUID.UUID(), Content: m.Content.String(), Metadata: metadata, ProjectID: projectID, @@ -53,20 +53,21 @@ func thoughtFromModel(m generatedmodels.ModelPublicThoughts) (ext.Thought, error } func storedFileFromModel(m generatedmodels.ModelPublicStoredFiles) ext.StoredFile { - var thoughtID *uuid.UUID + var thoughtID *int64 if m.ThoughtID.Valid { - id := m.ThoughtID.UUID() + id := m.ThoughtID.Int64() thoughtID = &id } - var projectID *uuid.UUID + var projectID *int64 if m.ProjectID.Valid { - id := m.ProjectID.UUID() + id := m.ProjectID.Int64() projectID = &id } return ext.StoredFile{ - ID: m.GUID.UUID(), + ID: m.ID.Int64(), + GUID: m.GUID.UUID(), ThoughtID: thoughtID, ProjectID: projectID, Name: m.Name.String(), @@ -419,9 +420,9 @@ func storedFileFromModel(m generatedmodels.ModelPublicStoredFiles) ext.StoredFil // } func planFromModel(m generatedmodels.ModelPublicPlans, tags []string) ext.Plan { - var projectID *uuid.UUID + var projectID *int64 if m.ProjectID.Valid { - id := m.ProjectID.UUID() + id := m.ProjectID.Int64() projectID = &id } @@ -443,14 +444,15 @@ func planFromModel(m generatedmodels.ModelPublicPlans, tags []string) ext.Plan { lastReviewedAt = &t } - var supersedesPlanID *uuid.UUID + var supersedesPlanID *int64 if m.SupersedesPlanID.Valid { - id := m.SupersedesPlanID.UUID() + id := m.SupersedesPlanID.Int64() supersedesPlanID = &id } return ext.Plan{ - ID: m.ID.UUID(), + ID: m.ID.Int64(), + GUID: m.GUID.UUID(), Title: m.Title.String(), Description: m.Description.String(), Status: ext.PlanStatus(m.Status.String()), @@ -469,33 +471,33 @@ func planFromModel(m generatedmodels.ModelPublicPlans, tags []string) ext.Plan { } func learningFromModel(m generatedmodels.ModelPublicLearnings, tags []string) ext.Learning { - var projectID *uuid.UUID + var projectID *int64 if m.ProjectID.Valid { - id := m.ProjectID.UUID() + id := m.ProjectID.Int64() projectID = &id } - var relatedThoughtID *uuid.UUID + var relatedThoughtID *int64 if m.RelatedThoughtID.Valid { - id := m.RelatedThoughtID.UUID() + id := m.RelatedThoughtID.Int64() relatedThoughtID = &id } - var relatedSkillID *uuid.UUID + var relatedSkillID *int64 if m.RelatedSkillID.Valid { - id := m.RelatedSkillID.UUID() + id := m.RelatedSkillID.Int64() relatedSkillID = &id } - var duplicateOfLearningID *uuid.UUID + var duplicateOfLearningID *int64 if m.DuplicateOfLearningID.Valid { - id := m.DuplicateOfLearningID.UUID() + id := m.DuplicateOfLearningID.Int64() duplicateOfLearningID = &id } - var supersedesLearningID *uuid.UUID + var supersedesLearningID *int64 if m.SupersedesLearningID.Valid { - id := m.SupersedesLearningID.UUID() + id := m.SupersedesLearningID.Int64() supersedesLearningID = &id } @@ -512,7 +514,8 @@ func learningFromModel(m generatedmodels.ModelPublicLearnings, tags []string) ex } return ext.Learning{ - ID: m.ID.UUID(), + ID: m.ID.Int64(), + GUID: m.GUID.UUID(), Summary: m.Summary.String(), Details: m.Details.String(), Category: m.Category.String(), diff --git a/internal/store/plans.go b/internal/store/plans.go index 912c562..77603cd 100644 --- a/internal/store/plans.go +++ b/internal/store/plans.go @@ -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 diff --git a/internal/store/projects.go b/internal/store/projects.go index e3dd893..0c2190a 100644 --- a/internal/store/projects.go +++ b/internal/store/projects.go @@ -16,11 +16,11 @@ func (db *DB) CreateProject(ctx context.Context, name, description string) (thou row := db.pool.QueryRow(ctx, ` insert into projects (name, description) values ($1, $2) - returning guid, name, description, created_at, last_active_at + returning id, guid, name, description, created_at, last_active_at `, name, description) var model generatedmodels.ModelPublicProjects - if err := row.Scan(&model.GUID, &model.Name, &model.Description, &model.CreatedAt, &model.LastActiveAt); err != nil { + if err := row.Scan(&model.ID, &model.GUID, &model.Name, &model.Description, &model.CreatedAt, &model.LastActiveAt); err != nil { return thoughttypes.Project{}, fmt.Errorf("create project: %w", err) } return projectFromModel(model), nil @@ -46,7 +46,7 @@ func (db *DB) GetProject(ctx context.Context, nameOrID string) (thoughttypes.Pro func (db *DB) getProjectByGUID(ctx context.Context, id uuid.UUID) (thoughttypes.Project, error) { row := db.pool.QueryRow(ctx, ` - select guid, name, description, created_at, last_active_at + select id, guid, name, description, created_at, last_active_at from projects where guid = $1 `, id) @@ -55,7 +55,7 @@ func (db *DB) getProjectByGUID(ctx context.Context, id uuid.UUID) (thoughttypes. func (db *DB) getProjectByName(ctx context.Context, name string) (thoughttypes.Project, error) { row := db.pool.QueryRow(ctx, ` - select guid, name, description, created_at, last_active_at + select id, guid, name, description, created_at, last_active_at from projects where name = $1 `, name) @@ -64,7 +64,7 @@ func (db *DB) getProjectByName(ctx context.Context, name string) (thoughttypes.P func scanProject(row pgx.Row) (thoughttypes.Project, error) { var model generatedmodels.ModelPublicProjects - if err := row.Scan(&model.GUID, &model.Name, &model.Description, &model.CreatedAt, &model.LastActiveAt); err != nil { + if err := row.Scan(&model.ID, &model.GUID, &model.Name, &model.Description, &model.CreatedAt, &model.LastActiveAt); err != nil { if err == pgx.ErrNoRows { return thoughttypes.Project{}, err } @@ -75,10 +75,10 @@ func scanProject(row pgx.Row) (thoughttypes.Project, error) { func (db *DB) ListProjects(ctx context.Context) ([]thoughttypes.ProjectSummary, error) { rows, err := db.pool.Query(ctx, ` - select p.guid, p.name, p.description, p.created_at, p.last_active_at, count(t.id) as thought_count + select p.id, p.guid, p.name, p.description, p.created_at, p.last_active_at, count(t.id) as thought_count from projects p - left join thoughts t on t.project_id = p.guid and t.archived_at is null - group by p.guid, p.name, p.description, p.created_at, p.last_active_at + left join thoughts t on t.project_id = p.id and t.archived_at is null + group by p.id, p.guid, p.name, p.description, p.created_at, p.last_active_at order by p.last_active_at desc, p.created_at desc `) if err != nil { @@ -90,7 +90,7 @@ func (db *DB) ListProjects(ctx context.Context) ([]thoughttypes.ProjectSummary, for rows.Next() { var model generatedmodels.ModelPublicProjects var thoughtCount int - if err := rows.Scan(&model.GUID, &model.Name, &model.Description, &model.CreatedAt, &model.LastActiveAt, &thoughtCount); err != nil { + if err := rows.Scan(&model.ID, &model.GUID, &model.Name, &model.Description, &model.CreatedAt, &model.LastActiveAt, &thoughtCount); err != nil { return nil, fmt.Errorf("scan project summary: %w", err) } projects = append(projects, thoughttypes.ProjectSummary{ @@ -104,8 +104,8 @@ func (db *DB) ListProjects(ctx context.Context) ([]thoughttypes.ProjectSummary, return projects, nil } -func (db *DB) TouchProject(ctx context.Context, id uuid.UUID) error { - tag, err := db.pool.Exec(ctx, `update projects set last_active_at = now() where guid = $1`, id) +func (db *DB) TouchProject(ctx context.Context, id int64) error { + tag, err := db.pool.Exec(ctx, `update projects set last_active_at = now() where id = $1`, id) if err != nil { return fmt.Errorf("touch project: %w", err) } diff --git a/internal/store/skills.go b/internal/store/skills.go index 84bc154..0844023 100644 --- a/internal/store/skills.go +++ b/internal/store/skills.go @@ -5,8 +5,6 @@ import ( "fmt" "strings" - "github.com/google/uuid" - "git.warky.dev/wdevs/amcs/internal/generatedmodels" ext "git.warky.dev/wdevs/amcs/internal/types" ) @@ -20,21 +18,22 @@ func (db *DB) AddSkill(ctx context.Context, skill ext.AgentSkill) (ext.AgentSkil row := db.pool.QueryRow(ctx, ` insert into agent_skills (name, description, content, tags) values ($1, $2, $3, $4) - returning id, created_at, updated_at + returning id, guid, created_at, updated_at `, skill.Name, skill.Description, skill.Content, skill.Tags) created := skill var model generatedmodels.ModelPublicAgentSkills - if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil { + if err := row.Scan(&model.ID, &model.GUID, &model.CreatedAt, &model.UpdatedAt); err != nil { return ext.AgentSkill{}, fmt.Errorf("insert agent skill: %w", err) } - created.ID = model.ID.UUID() + created.ID = model.ID.Int64() + created.GUID = model.GUID.UUID() created.CreatedAt = model.CreatedAt.Time() created.UpdatedAt = model.UpdatedAt.Time() return created, nil } -func (db *DB) RemoveSkill(ctx context.Context, id uuid.UUID) error { +func (db *DB) RemoveSkill(ctx context.Context, id int64) error { tag, err := db.pool.Exec(ctx, `delete from agent_skills where id = $1`, id) if err != nil { return fmt.Errorf("delete agent skill: %w", err) @@ -68,7 +67,7 @@ func (db *DB) ListSkills(ctx context.Context, tag string) ([]ext.AgentSkill, err return nil, fmt.Errorf("scan agent 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(), @@ -84,7 +83,7 @@ func (db *DB) ListSkills(ctx context.Context, tag string) ([]ext.AgentSkill, err return skills, rows.Err() } -func (db *DB) GetSkill(ctx context.Context, id uuid.UUID) (ext.AgentSkill, error) { +func (db *DB) GetSkill(ctx context.Context, id int64) (ext.AgentSkill, error) { row := db.pool.QueryRow(ctx, ` select id, name, description, content, tags::text[], created_at, updated_at from agent_skills where id = $1 @@ -96,7 +95,7 @@ func (db *DB) GetSkill(ctx context.Context, id uuid.UUID) (ext.AgentSkill, error return ext.AgentSkill{}, fmt.Errorf("get agent 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(), @@ -122,21 +121,22 @@ func (db *DB) AddGuardrail(ctx context.Context, g ext.AgentGuardrail) (ext.Agent row := db.pool.QueryRow(ctx, ` insert into agent_guardrails (name, description, content, severity, tags) values ($1, $2, $3, $4, $5) - returning id, created_at, updated_at + returning id, guid, created_at, updated_at `, g.Name, g.Description, g.Content, g.Severity, g.Tags) created := g var model generatedmodels.ModelPublicAgentGuardrails - if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil { + if err := row.Scan(&model.ID, &model.GUID, &model.CreatedAt, &model.UpdatedAt); err != nil { return ext.AgentGuardrail{}, fmt.Errorf("insert agent guardrail: %w", err) } - created.ID = model.ID.UUID() + created.ID = model.ID.Int64() + created.GUID = model.GUID.UUID() created.CreatedAt = model.CreatedAt.Time() created.UpdatedAt = model.UpdatedAt.Time() return created, nil } -func (db *DB) RemoveGuardrail(ctx context.Context, id uuid.UUID) error { +func (db *DB) RemoveGuardrail(ctx context.Context, id int64) error { tag, err := db.pool.Exec(ctx, `delete from agent_guardrails where id = $1`, id) if err != nil { return fmt.Errorf("delete agent guardrail: %w", err) @@ -180,7 +180,7 @@ func (db *DB) ListGuardrails(ctx context.Context, tag, severity string) ([]ext.A return nil, fmt.Errorf("scan agent 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(), @@ -197,7 +197,7 @@ func (db *DB) ListGuardrails(ctx context.Context, tag, severity string) ([]ext.A return guardrails, rows.Err() } -func (db *DB) GetGuardrail(ctx context.Context, id uuid.UUID) (ext.AgentGuardrail, error) { +func (db *DB) GetGuardrail(ctx context.Context, id int64) (ext.AgentGuardrail, error) { row := db.pool.QueryRow(ctx, ` select id, name, description, content, severity, tags::text[], created_at, updated_at from agent_guardrails where id = $1 @@ -209,7 +209,7 @@ func (db *DB) GetGuardrail(ctx context.Context, id uuid.UUID) (ext.AgentGuardrai return ext.AgentGuardrail{}, fmt.Errorf("get agent 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(), @@ -226,7 +226,7 @@ func (db *DB) GetGuardrail(ctx context.Context, id uuid.UUID) (ext.AgentGuardrai // Project Skills -func (db *DB) AddProjectSkill(ctx context.Context, projectID, skillID uuid.UUID) error { +func (db *DB) AddProjectSkill(ctx context.Context, projectID, skillID int64) error { _, err := db.pool.Exec(ctx, ` insert into project_skills (project_id, skill_id) values ($1, $2) @@ -238,7 +238,7 @@ func (db *DB) AddProjectSkill(ctx context.Context, projectID, skillID uuid.UUID) return nil } -func (db *DB) RemoveProjectSkill(ctx context.Context, projectID, skillID uuid.UUID) error { +func (db *DB) RemoveProjectSkill(ctx context.Context, projectID, skillID int64) error { tag, err := db.pool.Exec(ctx, ` delete from project_skills where project_id = $1 and skill_id = $2 `, projectID, skillID) @@ -251,7 +251,7 @@ func (db *DB) RemoveProjectSkill(ctx context.Context, projectID, skillID uuid.UU return nil } -func (db *DB) ListProjectSkills(ctx context.Context, projectID uuid.UUID) ([]ext.AgentSkill, error) { +func (db *DB) ListProjectSkills(ctx context.Context, projectID 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 @@ -272,7 +272,7 @@ func (db *DB) ListProjectSkills(ctx context.Context, projectID uuid.UUID) ([]ext return nil, fmt.Errorf("scan project 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(), @@ -290,7 +290,7 @@ func (db *DB) ListProjectSkills(ctx context.Context, projectID uuid.UUID) ([]ext // Project Guardrails -func (db *DB) AddProjectGuardrail(ctx context.Context, projectID, guardrailID uuid.UUID) error { +func (db *DB) AddProjectGuardrail(ctx context.Context, projectID, guardrailID int64) error { _, err := db.pool.Exec(ctx, ` insert into project_guardrails (project_id, guardrail_id) values ($1, $2) @@ -302,7 +302,7 @@ func (db *DB) AddProjectGuardrail(ctx context.Context, projectID, guardrailID uu return nil } -func (db *DB) RemoveProjectGuardrail(ctx context.Context, projectID, guardrailID uuid.UUID) error { +func (db *DB) RemoveProjectGuardrail(ctx context.Context, projectID, guardrailID int64) error { tag, err := db.pool.Exec(ctx, ` delete from project_guardrails where project_id = $1 and guardrail_id = $2 `, projectID, guardrailID) @@ -315,7 +315,7 @@ func (db *DB) RemoveProjectGuardrail(ctx context.Context, projectID, guardrailID return nil } -func (db *DB) ListProjectGuardrails(ctx context.Context, projectID uuid.UUID) ([]ext.AgentGuardrail, error) { +func (db *DB) ListProjectGuardrails(ctx context.Context, projectID 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 @@ -336,7 +336,7 @@ func (db *DB) ListProjectGuardrails(ctx context.Context, projectID uuid.UUID) ([ return nil, fmt.Errorf("scan project 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(), diff --git a/internal/store/thoughts.go b/internal/store/thoughts.go index 08b63f6..942a8dc 100644 --- a/internal/store/thoughts.go +++ b/internal/store/thoughts.go @@ -33,12 +33,12 @@ func (db *DB) InsertThought(ctx context.Context, thought thoughttypes.Thought, e row := tx.QueryRow(ctx, ` insert into thoughts (content, metadata, project_id) values ($1, $2::jsonb, $3) - returning guid, created_at, updated_at + returning id, guid, created_at, updated_at `, thought.Content, metadata, thought.ProjectID) created := thought created.Embedding = nil - if err := row.Scan(&created.ID, &created.CreatedAt, &created.UpdatedAt); err != nil { + if err := row.Scan(&created.ID, &created.GUID, &created.CreatedAt, &created.UpdatedAt); err != nil { return thoughttypes.Thought{}, fmt.Errorf("insert thought: %w", err) } @@ -132,7 +132,7 @@ func (db *DB) ListThoughts(ctx context.Context, filter thoughttypes.ListFilter) } query := ` - select guid, content, metadata, project_id, archived_at, created_at, updated_at + select id, guid, content, metadata, project_id, archived_at, created_at, updated_at from thoughts ` if len(conditions) > 0 { @@ -151,7 +151,7 @@ func (db *DB) ListThoughts(ctx context.Context, filter thoughttypes.ListFilter) thoughts := make([]thoughttypes.Thought, 0, filter.Limit) for rows.Next() { var model generatedmodels.ModelPublicThoughts - if err := rows.Scan(&model.GUID, &model.Content, &model.Metadata, &model.ProjectID, &model.ArchivedAt, &model.CreatedAt, &model.UpdatedAt); err != nil { + if err := rows.Scan(&model.ID, &model.GUID, &model.Content, &model.Metadata, &model.ProjectID, &model.ArchivedAt, &model.CreatedAt, &model.UpdatedAt); err != nil { return nil, fmt.Errorf("scan listed thought: %w", err) } thought, err := thoughtFromModel(model) @@ -218,13 +218,13 @@ func (db *DB) Stats(ctx context.Context) (thoughttypes.ThoughtStats, error) { func (db *DB) GetThought(ctx context.Context, id uuid.UUID) (thoughttypes.Thought, error) { row := db.pool.QueryRow(ctx, ` - select guid, content, metadata, project_id, archived_at, created_at, updated_at + select id, guid, content, metadata, project_id, archived_at, created_at, updated_at from thoughts where guid = $1 `, id) var model generatedmodels.ModelPublicThoughts - if err := row.Scan(&model.GUID, &model.Content, &model.Metadata, &model.ProjectID, &model.ArchivedAt, &model.CreatedAt, &model.UpdatedAt); err != nil { + if err := row.Scan(&model.ID, &model.GUID, &model.Content, &model.Metadata, &model.ProjectID, &model.ArchivedAt, &model.CreatedAt, &model.UpdatedAt); err != nil { if err == pgx.ErrNoRows { return thoughttypes.Thought{}, err } @@ -239,7 +239,30 @@ func (db *DB) GetThought(ctx context.Context, id uuid.UUID) (thoughttypes.Though return thought, nil } -func (db *DB) UpdateThought(ctx context.Context, id uuid.UUID, content string, embedding []float32, embeddingModel string, metadata thoughttypes.ThoughtMetadata, projectID *uuid.UUID) (thoughttypes.Thought, error) { +func (db *DB) GetThoughtByID(ctx context.Context, id int64) (thoughttypes.Thought, error) { + row := db.pool.QueryRow(ctx, ` + select id, guid, content, metadata, project_id, archived_at, created_at, updated_at + from thoughts + where id = $1 + `, id) + + var model generatedmodels.ModelPublicThoughts + if err := row.Scan(&model.ID, &model.GUID, &model.Content, &model.Metadata, &model.ProjectID, &model.ArchivedAt, &model.CreatedAt, &model.UpdatedAt); err != nil { + if err == pgx.ErrNoRows { + return thoughttypes.Thought{}, err + } + return thoughttypes.Thought{}, fmt.Errorf("get thought by id: %w", err) + } + + thought, err := thoughtFromModel(model) + if err != nil { + return thoughttypes.Thought{}, fmt.Errorf("map thought: %w", err) + } + + return thought, nil +} + +func (db *DB) UpdateThought(ctx context.Context, id uuid.UUID, content string, embedding []float32, embeddingModel string, metadata thoughttypes.ThoughtMetadata, projectID *int64) (thoughttypes.Thought, error) { metadataBytes, err := json.Marshal(metadata) if err != nil { return thoughttypes.Thought{}, fmt.Errorf("marshal updated metadata: %w", err) @@ -271,7 +294,7 @@ func (db *DB) UpdateThought(ctx context.Context, id uuid.UUID, content string, e if len(embedding) > 0 && embeddingModel != "" { if _, err := tx.Exec(ctx, ` insert into embeddings (thought_id, model, dim, embedding) - values ($1, $2, $3, $4) + select id, $2, $3, $4 from thoughts where guid = $1 on conflict (thought_id, model) do update set embedding = excluded.embedding, dim = excluded.dim, @@ -288,7 +311,7 @@ func (db *DB) UpdateThought(ctx context.Context, id uuid.UUID, content string, e return db.GetThought(ctx, id) } -func (db *DB) UpdateThoughtMetadata(ctx context.Context, id uuid.UUID, metadata thoughttypes.ThoughtMetadata) (thoughttypes.Thought, error) { +func (db *DB) UpdateThoughtMetadata(ctx context.Context, id int64, metadata thoughttypes.ThoughtMetadata) (thoughttypes.Thought, error) { metadataBytes, err := json.Marshal(metadata) if err != nil { return thoughttypes.Thought{}, fmt.Errorf("marshal updated metadata: %w", err) @@ -298,7 +321,7 @@ func (db *DB) UpdateThoughtMetadata(ctx context.Context, id uuid.UUID, metadata update thoughts set metadata = $2::jsonb, updated_at = now() - where guid = $1 + where id = $1 `, id, metadataBytes) if err != nil { return thoughttypes.Thought{}, fmt.Errorf("update thought metadata: %w", err) @@ -307,7 +330,7 @@ func (db *DB) UpdateThoughtMetadata(ctx context.Context, id uuid.UUID, metadata return thoughttypes.Thought{}, pgx.ErrNoRows } - return db.GetThought(ctx, id) + return db.GetThoughtByID(ctx, id) } func (db *DB) DeleteThought(ctx context.Context, id uuid.UUID) error { @@ -332,7 +355,7 @@ func (db *DB) ArchiveThought(ctx context.Context, id uuid.UUID) error { return nil } -func (db *DB) RecentThoughts(ctx context.Context, projectID *uuid.UUID, limit int, days int) ([]thoughttypes.Thought, error) { +func (db *DB) RecentThoughts(ctx context.Context, projectID *int64, limit int, days int) ([]thoughttypes.Thought, error) { filter := thoughttypes.ListFilter{ Limit: limit, ProjectID: projectID, @@ -342,7 +365,7 @@ func (db *DB) RecentThoughts(ctx context.Context, projectID *uuid.UUID, limit in return db.ListThoughts(ctx, filter) } -func (db *DB) ListThoughtsPendingMetadataRetry(ctx context.Context, limit int, projectID *uuid.UUID, includeArchived bool, olderThanDays int) ([]thoughttypes.Thought, error) { +func (db *DB) ListThoughtsPendingMetadataRetry(ctx context.Context, limit int, projectID *int64, includeArchived bool, olderThanDays int) ([]thoughttypes.Thought, error) { args := make([]any, 0, 4) conditions := []string{ "(metadata->>'metadata_status' = 'pending' or metadata->>'metadata_status' = 'failed')", @@ -361,7 +384,7 @@ func (db *DB) ListThoughtsPendingMetadataRetry(ctx context.Context, limit int, p } query := ` - select guid, content, metadata, project_id, archived_at, created_at, updated_at + select id, guid, content, metadata, project_id, archived_at, created_at, updated_at from thoughts where ` + strings.Join(conditions, " and ") @@ -376,12 +399,12 @@ func (db *DB) ListThoughtsPendingMetadataRetry(ctx context.Context, limit int, p thoughts := make([]thoughttypes.Thought, 0, limit) for rows.Next() { - var thought thoughttypes.Thought - var metadataBytes []byte - if err := rows.Scan(&thought.ID, &thought.Content, &metadataBytes, &thought.ProjectID, &thought.ArchivedAt, &thought.CreatedAt, &thought.UpdatedAt); err != nil { + var model generatedmodels.ModelPublicThoughts + if err := rows.Scan(&model.ID, &model.GUID, &model.Content, &model.Metadata, &model.ProjectID, &model.ArchivedAt, &model.CreatedAt, &model.UpdatedAt); err != nil { return nil, fmt.Errorf("scan pending metadata retry thought: %w", err) } - if err := json.Unmarshal(metadataBytes, &thought.Metadata); err != nil { + thought, err := thoughtFromModel(model) + if err != nil { return nil, fmt.Errorf("decode pending metadata retry thought: %w", err) } thoughts = append(thoughts, thought) @@ -394,7 +417,7 @@ func (db *DB) ListThoughtsPendingMetadataRetry(ctx context.Context, limit int, p return thoughts, nil } -func (db *DB) SearchSimilarThoughts(ctx context.Context, embedding []float32, embeddingModel string, threshold float64, limit int, projectID *uuid.UUID, excludeID *uuid.UUID) ([]thoughttypes.SearchResult, error) { +func (db *DB) SearchSimilarThoughts(ctx context.Context, embedding []float32, embeddingModel string, threshold float64, limit int, projectID *int64, excludeID *uuid.UUID) ([]thoughttypes.SearchResult, error) { args := []any{pgvector.NewVector(embedding), threshold, embeddingModel} conditions := []string{ "t.archived_at is null", @@ -412,9 +435,9 @@ func (db *DB) SearchSimilarThoughts(ctx context.Context, embedding []float32, em args = append(args, limit) query := ` - select t.guid, t.content, t.metadata, 1 - (e.embedding <=> $1) as similarity, t.created_at + select t.id, t.content, t.metadata, 1 - (e.embedding <=> $1) as similarity, t.created_at from thoughts t - join embeddings e on e.thought_id = t.guid + join embeddings e on e.thought_id = t.id where ` + strings.Join(conditions, " and ") + fmt.Sprintf(` order by e.embedding <=> $1 limit $%d`, len(args)) @@ -443,7 +466,7 @@ func (db *DB) SearchSimilarThoughts(ctx context.Context, embedding []float32, em return results, nil } -func (db *DB) HasEmbeddingsForModel(ctx context.Context, model string, projectID *uuid.UUID) (bool, error) { +func (db *DB) HasEmbeddingsForModel(ctx context.Context, model string, projectID *int64) (bool, error) { args := []any{model} conditions := []string{ "e.model = $1", @@ -454,7 +477,7 @@ func (db *DB) HasEmbeddingsForModel(ctx context.Context, model string, projectID conditions = append(conditions, fmt.Sprintf("t.project_id = $%d", len(args))) } - query := `select exists(select 1 from embeddings e join thoughts t on t.guid = e.thought_id where ` + + query := `select exists(select 1 from embeddings e join thoughts t on t.id = e.thought_id where ` + strings.Join(conditions, " and ") + `)` var exists bool @@ -464,7 +487,7 @@ func (db *DB) HasEmbeddingsForModel(ctx context.Context, model string, projectID return exists, nil } -func (db *DB) ListThoughtsMissingEmbedding(ctx context.Context, model string, limit int, projectID *uuid.UUID, includeArchived bool, olderThanDays int) ([]thoughttypes.Thought, error) { +func (db *DB) ListThoughtsMissingEmbedding(ctx context.Context, model string, limit int, projectID *int64, includeArchived bool, olderThanDays int) ([]thoughttypes.Thought, error) { args := []any{model} conditions := []string{"e.id is null"} @@ -482,9 +505,9 @@ func (db *DB) ListThoughtsMissingEmbedding(ctx context.Context, model string, li args = append(args, limit) query := ` - select t.guid, t.content, t.metadata, t.project_id, t.archived_at, t.created_at, t.updated_at + select t.id, t.guid, t.content, t.metadata, t.project_id, t.archived_at, t.created_at, t.updated_at from thoughts t - left join embeddings e on e.thought_id = t.guid and e.model = $1 + left join embeddings e on e.thought_id = t.id and e.model = $1 where ` + strings.Join(conditions, " and ") + ` order by t.created_at asc limit $` + fmt.Sprintf("%d", len(args)) @@ -497,12 +520,12 @@ func (db *DB) ListThoughtsMissingEmbedding(ctx context.Context, model string, li thoughts := make([]thoughttypes.Thought, 0, limit) for rows.Next() { - var thought thoughttypes.Thought - var metadataBytes []byte - if err := rows.Scan(&thought.ID, &thought.Content, &metadataBytes, &thought.ProjectID, &thought.ArchivedAt, &thought.CreatedAt, &thought.UpdatedAt); err != nil { + var model generatedmodels.ModelPublicThoughts + if err := rows.Scan(&model.ID, &model.GUID, &model.Content, &model.Metadata, &model.ProjectID, &model.ArchivedAt, &model.CreatedAt, &model.UpdatedAt); err != nil { return nil, fmt.Errorf("scan missing-embedding thought: %w", err) } - if err := json.Unmarshal(metadataBytes, &thought.Metadata); err != nil { + thought, err := thoughtFromModel(model) + if err != nil { return nil, fmt.Errorf("decode missing-embedding metadata: %w", err) } thoughts = append(thoughts, thought) @@ -513,7 +536,7 @@ func (db *DB) ListThoughtsMissingEmbedding(ctx context.Context, model string, li return thoughts, nil } -func (db *DB) ListThoughtsForMetadataReparse(ctx context.Context, limit int, projectID *uuid.UUID, includeArchived bool, olderThanDays int) ([]thoughttypes.Thought, error) { +func (db *DB) ListThoughtsForMetadataReparse(ctx context.Context, limit int, projectID *int64, includeArchived bool, olderThanDays int) ([]thoughttypes.Thought, error) { args := make([]any, 0, 3) conditions := make([]string, 0, 4) @@ -531,7 +554,7 @@ func (db *DB) ListThoughtsForMetadataReparse(ctx context.Context, limit int, pro args = append(args, limit) query := ` - select guid, content, metadata, project_id, archived_at, created_at, updated_at + select id, guid, content, metadata, project_id, archived_at, created_at, updated_at from thoughts ` if len(conditions) > 0 { @@ -547,12 +570,12 @@ func (db *DB) ListThoughtsForMetadataReparse(ctx context.Context, limit int, pro thoughts := make([]thoughttypes.Thought, 0, limit) for rows.Next() { - var thought thoughttypes.Thought - var metadataBytes []byte - if err := rows.Scan(&thought.ID, &thought.Content, &metadataBytes, &thought.ProjectID, &thought.ArchivedAt, &thought.CreatedAt, &thought.UpdatedAt); err != nil { + var model generatedmodels.ModelPublicThoughts + if err := rows.Scan(&model.ID, &model.GUID, &model.Content, &model.Metadata, &model.ProjectID, &model.ArchivedAt, &model.CreatedAt, &model.UpdatedAt); err != nil { return nil, fmt.Errorf("scan metadata-reparse thought: %w", err) } - if err := json.Unmarshal(metadataBytes, &thought.Metadata); err != nil { + thought, err := thoughtFromModel(model) + if err != nil { return nil, fmt.Errorf("decode metadata-reparse thought metadata: %w", err) } thoughts = append(thoughts, thought) @@ -564,7 +587,7 @@ func (db *DB) ListThoughtsForMetadataReparse(ctx context.Context, limit int, pro return thoughts, nil } -func (db *DB) UpsertEmbedding(ctx context.Context, thoughtID uuid.UUID, model string, embedding []float32) error { +func (db *DB) UpsertEmbedding(ctx context.Context, thoughtID int64, model string, embedding []float32) error { _, err := db.pool.Exec(ctx, ` insert into embeddings (thought_id, model, dim, embedding) values ($1, $2, $3, $4) @@ -579,7 +602,7 @@ func (db *DB) UpsertEmbedding(ctx context.Context, thoughtID uuid.UUID, model st return nil } -func (db *DB) SearchThoughtsText(ctx context.Context, query string, limit int, projectID *uuid.UUID, excludeID *uuid.UUID) ([]thoughttypes.SearchResult, error) { +func (db *DB) SearchThoughtsText(ctx context.Context, query string, limit int, projectID *int64, excludeID *uuid.UUID) ([]thoughttypes.SearchResult, error) { args := []any{query} conditions := []string{ "t.archived_at is null", @@ -596,11 +619,11 @@ func (db *DB) SearchThoughtsText(ctx context.Context, query string, limit int, p args = append(args, limit) q := ` - select t.guid, t.content, t.metadata, + select t.id, t.content, t.metadata, ts_rank_cd(to_tsvector('simple', t.content) || to_tsvector('simple', coalesce(p.name, '')), websearch_to_tsquery('simple', $1)) as similarity, t.created_at from thoughts t - left join projects p on t.project_id = p.guid + left join projects p on t.project_id = p.id where ` + strings.Join(conditions, " and ") + ` order by similarity desc limit $` + fmt.Sprintf("%d", len(args)) diff --git a/internal/tools/backfill.go b/internal/tools/backfill.go index 6ac06ed..b92f70e 100644 --- a/internal/tools/backfill.go +++ b/internal/tools/backfill.go @@ -2,11 +2,11 @@ package tools import ( "context" + "fmt" "log/slog" "sync" "time" - "github.com/google/uuid" "github.com/modelcontextprotocol/go-sdk/mcp" "golang.org/x/sync/semaphore" @@ -53,11 +53,12 @@ func NewBackfillTool(db *store.DB, embeddings *ai.EmbeddingRunner, sessions *ses // QueueThought queues a single thought for background embedding generation. // It is used by capture when the embedding provider is temporarily unavailable. -func (t *BackfillTool) QueueThought(ctx context.Context, id uuid.UUID, content string) { +func (t *BackfillTool) QueueThought(ctx context.Context, id int64, content string) { go func() { started := time.Now() + idStr := fmt.Sprint(id) t.logger.Info("background embedding started", - slog.String("thought_id", id.String()), + slog.String("thought_id", idStr), slog.String("provider", t.embeddings.PrimaryProvider()), slog.String("model", t.embeddings.PrimaryModel()), ) @@ -65,7 +66,7 @@ func (t *BackfillTool) QueueThought(ctx context.Context, id uuid.UUID, content s result, err := t.embeddings.Embed(ctx, content) if err != nil { t.logger.Warn("background embedding error", - slog.String("thought_id", id.String()), + slog.String("thought_id", idStr), slog.String("provider", t.embeddings.PrimaryProvider()), slog.String("model", t.embeddings.PrimaryModel()), slog.String("stage", "embed"), @@ -76,7 +77,7 @@ func (t *BackfillTool) QueueThought(ctx context.Context, id uuid.UUID, content s } if err := t.store.UpsertEmbedding(ctx, id, result.Model, result.Vector); err != nil { t.logger.Warn("background embedding error", - slog.String("thought_id", id.String()), + slog.String("thought_id", idStr), slog.String("provider", t.embeddings.PrimaryProvider()), slog.String("model", result.Model), slog.String("stage", "upsert"), @@ -86,7 +87,7 @@ func (t *BackfillTool) QueueThought(ctx context.Context, id uuid.UUID, content s return } t.logger.Info("background embedding complete", - slog.String("thought_id", id.String()), + slog.String("thought_id", idStr), slog.String("provider", t.embeddings.PrimaryProvider()), slog.String("model", result.Model), slog.Duration("duration", time.Since(started)), @@ -105,9 +106,9 @@ func (t *BackfillTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in return nil, BackfillOutput{}, err } - var projectID *uuid.UUID + var projectID *int64 if project != nil { - projectID = &project.ID + projectID = &project.NumericID } primaryModel := t.embeddings.PrimaryModel() @@ -140,24 +141,25 @@ func (t *BackfillTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in break } wg.Add(1) - go func(id uuid.UUID, content string) { + go func(id int64, content string) { defer wg.Done() defer sem.Release(1) + idStr := fmt.Sprint(id) result, embedErr := t.embeddings.Embed(ctx, content) if embedErr != nil { mu.Lock() - out.Failures = append(out.Failures, BackfillFailure{ID: id.String(), Error: embedErr.Error()}) + out.Failures = append(out.Failures, BackfillFailure{ID: idStr, Error: embedErr.Error()}) mu.Unlock() - t.logger.Warn("backfill embed failed", slog.String("thought_id", id.String()), slog.String("error", embedErr.Error())) + t.logger.Warn("backfill embed failed", slog.String("thought_id", idStr), slog.String("error", embedErr.Error())) return } if upsertErr := t.store.UpsertEmbedding(ctx, id, result.Model, result.Vector); upsertErr != nil { mu.Lock() - out.Failures = append(out.Failures, BackfillFailure{ID: id.String(), Error: upsertErr.Error()}) + out.Failures = append(out.Failures, BackfillFailure{ID: idStr, Error: upsertErr.Error()}) mu.Unlock() - t.logger.Warn("backfill upsert failed", slog.String("thought_id", id.String()), slog.String("error", upsertErr.Error())) + t.logger.Warn("backfill upsert failed", slog.String("thought_id", idStr), slog.String("error", upsertErr.Error())) return } diff --git a/internal/tools/capture.go b/internal/tools/capture.go index d47950a..0aa70c5 100644 --- a/internal/tools/capture.go +++ b/internal/tools/capture.go @@ -4,7 +4,6 @@ import ( "context" "strings" - "github.com/google/uuid" "github.com/modelcontextprotocol/go-sdk/mcp" "git.warky.dev/wdevs/amcs/internal/ai" @@ -17,13 +16,13 @@ import ( // EmbeddingQueuer queues a thought for background embedding generation. type EmbeddingQueuer interface { - QueueThought(ctx context.Context, id uuid.UUID, content string) + QueueThought(ctx context.Context, id int64, content string) } // MetadataQueuer queues a thought for background metadata retry. Both // MetadataRetryer and EnrichmentRetryer satisfy this. type MetadataQueuer interface { - QueueThought(id uuid.UUID) + QueueThought(id int64) } type CaptureTool struct { @@ -66,7 +65,7 @@ func (t *CaptureTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in C Metadata: rawMetadata, } if project != nil { - thought.ProjectID = &project.ID + thought.ProjectID = &project.NumericID } created, err := t.store.InsertThought(ctx, thought, t.embeddings.PrimaryModel()) @@ -74,7 +73,7 @@ func (t *CaptureTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in C return nil, CaptureOutput{}, err } if project != nil { - _ = t.store.TouchProject(ctx, project.ID) + _ = t.store.TouchProject(ctx, project.NumericID) } if t.retryer != nil { diff --git a/internal/tools/chat_history.go b/internal/tools/chat_history.go index b535b4f..879c05f 100644 --- a/internal/tools/chat_history.go +++ b/internal/tools/chat_history.go @@ -4,7 +4,6 @@ import ( "context" "strings" - "github.com/google/uuid" "github.com/modelcontextprotocol/go-sdk/mcp" "git.warky.dev/wdevs/amcs/internal/session" @@ -64,7 +63,7 @@ func (t *ChatHistoryTool) SaveChatHistory(ctx context.Context, req *mcp.CallTool h.Metadata = map[string]any{} } if project != nil { - h.ProjectID = &project.ID + h.ProjectID = &project.NumericID } saved, err := t.store.SaveChatHistory(ctx, h) @@ -77,7 +76,7 @@ func (t *ChatHistoryTool) SaveChatHistory(ctx context.Context, req *mcp.CallTool // get_chat_history type GetChatHistoryInput struct { - ID string `json:"id,omitempty" jsonschema:"UUID of the saved chat history"` + ID string `json:"id,omitempty" jsonschema:"numeric id of the saved chat history"` SessionID string `json:"session_id,omitempty" jsonschema:"original session_id — returns the most recent history for that session"` } @@ -91,9 +90,9 @@ func (t *ChatHistoryTool) GetChatHistory(ctx context.Context, _ *mcp.CallToolReq } if in.ID != "" { - id, err := uuid.Parse(in.ID) + id, err := parseID(in.ID) if err != nil { - return nil, GetChatHistoryOutput{}, errInvalidField("id", "invalid id", "must be a valid UUID") + return nil, GetChatHistoryOutput{}, errInvalidField("id", "invalid id", "must be a valid numeric id") } h, found, err := t.store.GetChatHistory(ctx, id) if err != nil { @@ -145,7 +144,7 @@ func (t *ChatHistoryTool) ListChatHistories(ctx context.Context, req *mcp.CallTo return nil, ListChatHistoriesOutput{}, err } if project != nil { - filter.ProjectID = &project.ID + filter.ProjectID = &project.NumericID } } @@ -162,7 +161,7 @@ func (t *ChatHistoryTool) ListChatHistories(ctx context.Context, req *mcp.CallTo // delete_chat_history type DeleteChatHistoryInput struct { - ID uuid.UUID `json:"id" jsonschema:"UUID of the chat history to delete"` + ID string `json:"id" jsonschema:"numeric id of the chat history to delete"` } type DeleteChatHistoryOutput struct { @@ -170,7 +169,11 @@ type DeleteChatHistoryOutput struct { } func (t *ChatHistoryTool) DeleteChatHistory(ctx context.Context, _ *mcp.CallToolRequest, in DeleteChatHistoryInput) (*mcp.CallToolResult, DeleteChatHistoryOutput, error) { - deleted, err := t.store.DeleteChatHistory(ctx, in.ID) + id, err := parseID(in.ID) + if err != nil { + return nil, DeleteChatHistoryOutput{}, errInvalidField("id", "invalid id", "must be a valid numeric id") + } + deleted, err := t.store.DeleteChatHistory(ctx, id) if err != nil { return nil, DeleteChatHistoryOutput{}, err } diff --git a/internal/tools/context.go b/internal/tools/context.go index ffc449e..69cd717 100644 --- a/internal/tools/context.go +++ b/internal/tools/context.go @@ -52,7 +52,7 @@ func (t *ContextTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in P } limit := normalizeLimit(in.Limit, t.search) - recent, err := t.store.RecentThoughts(ctx, &project.ID, limit, 0) + recent, err := t.store.RecentThoughts(ctx, &project.NumericID, limit, 0) if err != nil { return nil, ProjectContextOutput{}, err } @@ -60,7 +60,7 @@ func (t *ContextTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in P items := make([]ContextItem, 0, limit*2) seen := map[string]struct{}{} for _, thought := range recent { - key := thought.ID.String() + key := fmt.Sprint(thought.ID) seen[key] = struct{}{} items = append(items, ContextItem{ ID: key, @@ -72,12 +72,12 @@ func (t *ContextTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in P query := strings.TrimSpace(in.Query) if query != "" { - semantic, err := semanticSearch(ctx, t.store, t.embeddings, t.search, query, limit, t.search.DefaultThreshold, &project.ID, nil) + semantic, err := semanticSearch(ctx, t.store, t.embeddings, t.search, query, limit, t.search.DefaultThreshold, &project.NumericID, nil) if err != nil { return nil, ProjectContextOutput{}, err } for _, result := range semantic { - key := result.ID.String() + key := fmt.Sprint(result.ID) if _, ok := seen[key]; ok { continue } @@ -97,7 +97,7 @@ func (t *ContextTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in P lines = append(lines, thoughtContextLine(i, item.Content, item.Metadata, item.Similarity)) } contextBlock := formatContextBlock(fmt.Sprintf("Project context for %s", project.Name), lines) - _ = t.store.TouchProject(ctx, project.ID) + _ = t.store.TouchProject(ctx, project.NumericID) return nil, ProjectContextOutput{ Project: *project, diff --git a/internal/tools/enrichment_retry.go b/internal/tools/enrichment_retry.go index a95eaea..0f9b1c5 100644 --- a/internal/tools/enrichment_retry.go +++ b/internal/tools/enrichment_retry.go @@ -2,11 +2,11 @@ package tools import ( "context" + "fmt" "log/slog" "sync" "time" - "github.com/google/uuid" "github.com/modelcontextprotocol/go-sdk/mcp" "golang.org/x/sync/semaphore" @@ -89,18 +89,19 @@ func (t *RetryEnrichmentTool) Handle(ctx context.Context, req *mcp.CallToolReque return t.retryer.Handle(ctx, req, in) } -func (r *EnrichmentRetryer) QueueThought(id uuid.UUID) { +func (r *EnrichmentRetryer) QueueThought(id int64) { go func() { started := time.Now() + idStr := fmt.Sprint(id) r.logger.Info("background metadata started", - slog.String("thought_id", id.String()), + slog.String("thought_id", idStr), slog.String("provider", r.metadata.PrimaryProvider()), slog.String("model", r.metadata.PrimaryModel()), ) updated, err := r.retryOne(r.backgroundCtx, id) if err != nil { r.logger.Warn("background metadata error", - slog.String("thought_id", id.String()), + slog.String("thought_id", idStr), slog.String("provider", r.metadata.PrimaryProvider()), slog.String("model", r.metadata.PrimaryModel()), slog.Duration("duration", time.Since(started)), @@ -109,7 +110,7 @@ func (r *EnrichmentRetryer) QueueThought(id uuid.UUID) { return } r.logger.Info("background metadata complete", - slog.String("thought_id", id.String()), + slog.String("thought_id", idStr), slog.String("provider", r.metadata.PrimaryProvider()), slog.String("model", r.metadata.PrimaryModel()), slog.Bool("updated", updated), @@ -129,9 +130,9 @@ func (r *EnrichmentRetryer) Handle(ctx context.Context, req *mcp.CallToolRequest return nil, RetryEnrichmentOutput{}, err } - var projectID *uuid.UUID + var projectID *int64 if project != nil { - projectID = &project.ID + projectID = &project.NumericID } thoughts, err := r.store.ListThoughtsPendingMetadataRetry(ctx, limit, projectID, in.IncludeArchived, in.OlderThanDays) @@ -168,7 +169,7 @@ func (r *EnrichmentRetryer) Handle(ctx context.Context, req *mcp.CallToolRequest updated, err := r.retryOne(ctx, thought.ID) if err != nil { mu.Lock() - out.Failures = append(out.Failures, RetryEnrichmentFailure{ID: thought.ID.String(), Error: err.Error()}) + out.Failures = append(out.Failures, RetryEnrichmentFailure{ID: fmt.Sprint(thought.ID), Error: err.Error()}) mu.Unlock() return } @@ -191,8 +192,8 @@ func (r *EnrichmentRetryer) Handle(ctx context.Context, req *mcp.CallToolRequest return nil, out, nil } -func (r *EnrichmentRetryer) retryOne(ctx context.Context, id uuid.UUID) (bool, error) { - thought, err := r.store.GetThought(ctx, id) +func (r *EnrichmentRetryer) retryOne(ctx context.Context, id int64) (bool, error) { + thought, err := r.store.GetThoughtByID(ctx, id) if err != nil { return false, err } diff --git a/internal/tools/files.go b/internal/tools/files.go index c5cacd7..5e182d3 100644 --- a/internal/tools/files.go +++ b/internal/tools/files.go @@ -5,6 +5,7 @@ import ( "crypto/sha256" "encoding/base64" "encoding/hex" + "fmt" "net/http" "os" "path/filepath" @@ -148,7 +149,7 @@ func (t *FilesTool) Upload(ctx context.Context, req *mcp.CallToolRequest, in Upl return nil, UploadFileOutput{}, err } - uri := fileURIPrefix + out.File.ID.String() + uri := fileURIPrefix + fmt.Sprint(out.File.ID) return nil, UploadFileOutput{File: out.File, URI: uri}, nil } @@ -247,7 +248,7 @@ func (t *FilesTool) Load(ctx context.Context, _ *mcp.CallToolRequest, in LoadFil return nil, LoadFileOutput{}, err } - uri := fileURIPrefix + file.ID.String() + uri := fileURIPrefix + fmt.Sprint(file.ID) result := &mcp.CallToolResult{ Content: []mcp.Content{ &mcp.EmbeddedResource{ @@ -294,7 +295,7 @@ func (t *FilesTool) List(ctx context.Context, req *mcp.CallToolRequest, in ListF return nil, ListFilesOutput{}, err } - var thoughtID *uuid.UUID + var thoughtID *int64 if rawThoughtID := strings.TrimSpace(in.ThoughtID); rawThoughtID != "" { parsedThoughtID, err := parseUUID(rawThoughtID) if err != nil { @@ -304,12 +305,12 @@ func (t *FilesTool) List(ctx context.Context, req *mcp.CallToolRequest, in ListF if err != nil { return nil, ListFilesOutput{}, err } - thoughtID = &parsedThoughtID - if project != nil && thought.ProjectID != nil && *thought.ProjectID != project.ID { + thoughtID = &thought.ID + if project != nil && thought.ProjectID != nil && *thought.ProjectID != project.NumericID { return nil, ListFilesOutput{}, errInvalidInput("project does not match the linked thought's project") } if project == nil && thought.ProjectID != nil { - project = &thoughttypes.Project{ID: *thought.ProjectID} + project = &thoughttypes.Project{NumericID: *thought.ProjectID} } } @@ -323,7 +324,7 @@ func (t *FilesTool) List(ctx context.Context, req *mcp.CallToolRequest, in ListF return nil, ListFilesOutput{}, err } if project != nil { - _ = t.store.TouchProject(ctx, project.ID) + _ = t.store.TouchProject(ctx, project.NumericID) } return nil, ListFilesOutput{Files: files}, nil @@ -343,7 +344,7 @@ func (t *FilesTool) SaveDecoded(ctx context.Context, req *mcp.CallToolRequest, i return SaveFileOutput{}, err } - var thoughtID *uuid.UUID + var thoughtNumericID *int64 var projectID = projectIDPtr(project) if rawThoughtID := strings.TrimSpace(in.ThoughtID); rawThoughtID != "" { parsedThoughtID, err := parseUUID(rawThoughtID) @@ -354,9 +355,9 @@ func (t *FilesTool) SaveDecoded(ctx context.Context, req *mcp.CallToolRequest, i if err != nil { return SaveFileOutput{}, err } - thoughtID = &parsedThoughtID + thoughtNumericID = &thought.ID projectID = thought.ProjectID - if project != nil && thought.ProjectID != nil && *thought.ProjectID != project.ID { + if project != nil && thought.ProjectID != nil && *thought.ProjectID != project.NumericID { return SaveFileOutput{}, errInvalidInput("project does not match the linked thought's project") } } @@ -374,9 +375,7 @@ func (t *FilesTool) SaveDecoded(ctx context.Context, req *mcp.CallToolRequest, i SHA256: hex.EncodeToString(sum[:]), Content: in.Content, ProjectID: projectID, - } - if thoughtID != nil { - file.ThoughtID = thoughtID + ThoughtID: thoughtNumericID, } created, err := t.store.InsertStoredFile(ctx, file) @@ -398,7 +397,7 @@ func (t *FilesTool) SaveDecoded(ctx context.Context, req *mcp.CallToolRequest, i func thoughtAttachmentFromFile(file thoughttypes.StoredFile) thoughttypes.ThoughtAttachment { return thoughttypes.ThoughtAttachment{ - FileID: file.ID, + FileID: file.GUID, Name: file.Name, MediaType: file.MediaType, Kind: file.Kind, @@ -498,11 +497,11 @@ func normalizeFileKind(explicit string, mediaType string) string { } } -func projectIDPtr(project *thoughttypes.Project) *uuid.UUID { +func projectIDPtr(project *thoughttypes.Project) *int64 { if project == nil { return nil } - return &project.ID + return &project.NumericID } func normalizeFileLimit(limit int) int { diff --git a/internal/tools/helpers.go b/internal/tools/helpers.go index 0048c55..b0363dd 100644 --- a/internal/tools/helpers.go +++ b/internal/tools/helpers.go @@ -3,6 +3,7 @@ package tools import ( "context" "fmt" + "strconv" "strings" "github.com/google/uuid" @@ -34,6 +35,14 @@ func parseUUID(id string) (uuid.UUID, error) { return parsed, nil } +func parseID(id string) (int64, error) { + n, err := strconv.ParseInt(strings.TrimSpace(id), 10, 64) + if err != nil { + return 0, fmt.Errorf("invalid numeric id %q", id) + } + return n, nil +} + func sessionID(req *mcp.CallToolRequest) (string, error) { if req == nil || req.Session == nil || req.Session.ID() == "" { return "", newMCPError( diff --git a/internal/tools/learnings.go b/internal/tools/learnings.go index d0f2c17..3afdbfe 100644 --- a/internal/tools/learnings.go +++ b/internal/tools/learnings.go @@ -4,7 +4,6 @@ import ( "context" "strings" - "github.com/google/uuid" "github.com/modelcontextprotocol/go-sdk/mcp" "git.warky.dev/wdevs/amcs/internal/config" @@ -31,11 +30,11 @@ type AddLearningInput struct { SourceType string `json:"source_type,omitempty"` SourceRef string `json:"source_ref,omitempty"` Project string `json:"project,omitempty" jsonschema:"project name or id; falls back to active session project"` - RelatedThoughtID *uuid.UUID `json:"related_thought_id,omitempty"` - RelatedSkillID *uuid.UUID `json:"related_skill_id,omitempty"` - ReviewedBy *string `json:"reviewed_by,omitempty"` - DuplicateOfLearningID *uuid.UUID `json:"duplicate_of_learning_id,omitempty"` - SupersedesLearningID *uuid.UUID `json:"supersedes_learning_id,omitempty"` + RelatedThoughtID *int64 `json:"related_thought_id,omitempty"` + RelatedSkillID *int64 `json:"related_skill_id,omitempty"` + ReviewedBy *string `json:"reviewed_by,omitempty"` + DuplicateOfLearningID *int64 `json:"duplicate_of_learning_id,omitempty"` + SupersedesLearningID *int64 `json:"supersedes_learning_id,omitempty"` Tags []string `json:"tags,omitempty"` } @@ -44,7 +43,7 @@ type AddLearningOutput struct { } type GetLearningInput struct { - ID uuid.UUID `json:"id" jsonschema:"learning id"` + ID int64 `json:"id" jsonschema:"learning id"` } type GetLearningOutput struct { @@ -105,7 +104,7 @@ func (t *LearningsTool) Add(ctx context.Context, req *mcp.CallToolRequest, in Ad learning.ActionRequired = *in.ActionRequired } if project != nil { - learning.ProjectID = &project.ID + learning.ProjectID = &project.NumericID } created, err := t.store.CreateLearning(ctx, learning) @@ -147,7 +146,7 @@ func (t *LearningsTool) List(ctx context.Context, req *mcp.CallToolRequest, in L Query: strings.TrimSpace(in.Query), } if project != nil { - filter.ProjectID = &project.ID + filter.ProjectID = &project.NumericID } items, err := t.store.ListLearnings(ctx, filter) diff --git a/internal/tools/learnings_test.go b/internal/tools/learnings_test.go index b271b59..b29695e 100644 --- a/internal/tools/learnings_test.go +++ b/internal/tools/learnings_test.go @@ -5,7 +5,6 @@ import ( "testing" "git.warky.dev/wdevs/amcs/internal/mcperrors" - "github.com/google/uuid" ) func TestLearningsAddRequiresSummary(t *testing.T) { @@ -37,7 +36,7 @@ func TestLearningsMethodsRequireConfiguredStore(t *testing.T) { }) t.Run("get", func(t *testing.T) { - _, _, err := tool.Get(context.Background(), nil, GetLearningInput{ID: uuid.New()}) + _, _, err := tool.Get(context.Background(), nil, GetLearningInput{ID: 0}) if err == nil { t.Fatal("Get() error = nil, want error") } diff --git a/internal/tools/links.go b/internal/tools/links.go index a61d501..2e78478 100644 --- a/internal/tools/links.go +++ b/internal/tools/links.go @@ -2,6 +2,7 @@ package tools import ( "context" + "fmt" "strings" "github.com/modelcontextprotocol/go-sdk/mcp" @@ -97,9 +98,9 @@ func (t *LinksTool) Related(ctx context.Context, _ *mcp.CallToolRequest, in Rela } related := make([]RelatedThought, 0, len(linked)+t.search.DefaultLimit) - seen := map[string]struct{}{thought.ID.String(): {}} + seen := map[string]struct{}{fmt.Sprint(thought.ID): {}} for _, item := range linked { - key := item.Thought.ID.String() + key := fmt.Sprint(item.Thought.ID) seen[key] = struct{}{} related = append(related, RelatedThought{ ID: key, @@ -117,12 +118,12 @@ func (t *LinksTool) Related(ctx context.Context, _ *mcp.CallToolRequest, in Rela } if includeSemantic { - semantic, err := semanticSearch(ctx, t.store, t.embeddings, t.search, thought.Content, t.search.DefaultLimit, t.search.DefaultThreshold, thought.ProjectID, &thought.ID) + semantic, err := semanticSearch(ctx, t.store, t.embeddings, t.search, thought.Content, t.search.DefaultLimit, t.search.DefaultThreshold, thought.ProjectID, &thought.GUID) if err != nil { return nil, RelatedOutput{}, err } for _, item := range semantic { - key := item.ID.String() + key := fmt.Sprint(item.ID) if _, ok := seen[key]; ok { continue } diff --git a/internal/tools/list.go b/internal/tools/list.go index e8bc890..34658d1 100644 --- a/internal/tools/list.go +++ b/internal/tools/list.go @@ -4,7 +4,6 @@ import ( "context" "strings" - "github.com/google/uuid" "github.com/modelcontextprotocol/go-sdk/mcp" "git.warky.dev/wdevs/amcs/internal/config" @@ -43,9 +42,9 @@ func (t *ListTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in List return nil, ListOutput{}, err } - var projectID *uuid.UUID + var projectID *int64 if project != nil { - projectID = &project.ID + projectID = &project.NumericID } thoughts, err := t.store.ListThoughts(ctx, thoughttypes.ListFilter{ @@ -61,7 +60,7 @@ func (t *ListTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in List return nil, ListOutput{}, err } if project != nil { - _ = t.store.TouchProject(ctx, project.ID) + _ = t.store.TouchProject(ctx, project.NumericID) } return nil, ListOutput{Thoughts: thoughts}, nil diff --git a/internal/tools/metadata_retry.go b/internal/tools/metadata_retry.go index d11c26f..bf33f31 100644 --- a/internal/tools/metadata_retry.go +++ b/internal/tools/metadata_retry.go @@ -2,11 +2,11 @@ package tools import ( "context" + "fmt" "log/slog" "sync" "time" - "github.com/google/uuid" "github.com/modelcontextprotocol/go-sdk/mcp" "golang.org/x/sync/semaphore" @@ -37,18 +37,18 @@ type RetryMetadataTool struct { type RetryLocker struct { mu sync.Mutex - locks map[uuid.UUID]time.Time + locks map[int64]time.Time } func NewRetryLocker() *RetryLocker { - return &RetryLocker{locks: map[uuid.UUID]time.Time{}} + return &RetryLocker{locks: map[int64]time.Time{}} } -func (l *RetryLocker) Acquire(id uuid.UUID, ttl time.Duration) bool { +func (l *RetryLocker) Acquire(id int64, ttl time.Duration) bool { l.mu.Lock() defer l.mu.Unlock() if l.locks == nil { - l.locks = map[uuid.UUID]time.Time{} + l.locks = map[int64]time.Time{} } now := time.Now() if exp, ok := l.locks[id]; ok && exp.After(now) { @@ -58,7 +58,7 @@ func (l *RetryLocker) Acquire(id uuid.UUID, ttl time.Duration) bool { return true } -func (l *RetryLocker) Release(id uuid.UUID) { +func (l *RetryLocker) Release(id int64) { l.mu.Lock() defer l.mu.Unlock() delete(l.locks, id) @@ -111,23 +111,24 @@ func (t *RetryMetadataTool) Handle(ctx context.Context, req *mcp.CallToolRequest return t.retryer.Handle(ctx, req, in) } -func (r *MetadataRetryer) QueueThought(id uuid.UUID) { +func (r *MetadataRetryer) QueueThought(id int64) { go func() { started := time.Now() + idStr := fmt.Sprint(id) if !r.lock.Acquire(id, 15*time.Minute) { return } defer r.lock.Release(id) r.logger.Info("background metadata started", - slog.String("thought_id", id.String()), + slog.String("thought_id", idStr), slog.String("provider", r.metadata.PrimaryProvider()), slog.String("model", r.metadata.PrimaryModel()), ) updated, err := r.retryOne(r.backgroundCtx, id) if err != nil { r.logger.Warn("background metadata error", - slog.String("thought_id", id.String()), + slog.String("thought_id", idStr), slog.String("provider", r.metadata.PrimaryProvider()), slog.String("model", r.metadata.PrimaryModel()), slog.Duration("duration", time.Since(started)), @@ -136,7 +137,7 @@ func (r *MetadataRetryer) QueueThought(id uuid.UUID) { return } r.logger.Info("background metadata complete", - slog.String("thought_id", id.String()), + slog.String("thought_id", idStr), slog.String("provider", r.metadata.PrimaryProvider()), slog.String("model", r.metadata.PrimaryModel()), slog.Bool("updated", updated), @@ -156,9 +157,9 @@ func (r *MetadataRetryer) Handle(ctx context.Context, req *mcp.CallToolRequest, return nil, RetryMetadataOutput{}, err } - var projectID *uuid.UUID + var projectID *int64 if project != nil { - projectID = &project.ID + projectID = &project.NumericID } thoughts, err := r.store.ListThoughtsPendingMetadataRetry(ctx, limit, projectID, in.IncludeArchived, in.OlderThanDays) @@ -205,7 +206,7 @@ func (r *MetadataRetryer) Handle(ctx context.Context, req *mcp.CallToolRequest, r.lock.Release(thought.ID) if err != nil { mu.Lock() - out.Failures = append(out.Failures, RetryMetadataFailure{ID: thought.ID.String(), Error: err.Error()}) + out.Failures = append(out.Failures, RetryMetadataFailure{ID: fmt.Sprint(thought.ID), Error: err.Error()}) mu.Unlock() return } @@ -228,8 +229,8 @@ func (r *MetadataRetryer) Handle(ctx context.Context, req *mcp.CallToolRequest, return nil, out, nil } -func (r *MetadataRetryer) retryOne(ctx context.Context, id uuid.UUID) (bool, error) { - thought, err := r.store.GetThought(ctx, id) +func (r *MetadataRetryer) retryOne(ctx context.Context, id int64) (bool, error) { + thought, err := r.store.GetThoughtByID(ctx, id) if err != nil { return false, err } diff --git a/internal/tools/plans.go b/internal/tools/plans.go index 31dd44b..7e9b6d9 100644 --- a/internal/tools/plans.go +++ b/internal/tools/plans.go @@ -5,7 +5,6 @@ import ( "strings" "time" - "github.com/google/uuid" "github.com/modelcontextprotocol/go-sdk/mcp" "git.warky.dev/wdevs/amcs/internal/config" @@ -27,15 +26,15 @@ func NewPlansTool(db *store.DB, sessions *session.ActiveProjects, cfg config.Sea // --- I/O types --- type CreatePlanInput struct { - Title string `json:"title" jsonschema:"plan title"` - Description string `json:"description,omitempty"` - Status string `json:"status,omitempty" jsonschema:"draft|active|blocked|completed|cancelled|superseded"` - Priority string `json:"priority,omitempty" jsonschema:"low|medium|high|critical"` - Project string `json:"project,omitempty" jsonschema:"project name or id; falls back to active session project"` - Owner string `json:"owner,omitempty"` - DueDate string `json:"due_date,omitempty" jsonschema:"RFC3339 timestamp"` - SupersedesPlanID *uuid.UUID `json:"supersedes_plan_id,omitempty"` - Tags []string `json:"tags,omitempty"` + Title string `json:"title" jsonschema:"plan title"` + Description string `json:"description,omitempty"` + Status string `json:"status,omitempty" jsonschema:"draft|active|blocked|completed|cancelled|superseded"` + Priority string `json:"priority,omitempty" jsonschema:"low|medium|high|critical"` + Project string `json:"project,omitempty" jsonschema:"project name or id; falls back to active session project"` + Owner string `json:"owner,omitempty"` + DueDate string `json:"due_date,omitempty" jsonschema:"RFC3339 timestamp"` + SupersedesPlanID *int64 `json:"supersedes_plan_id,omitempty"` + Tags []string `json:"tags,omitempty"` } type CreatePlanOutput struct { @@ -43,7 +42,7 @@ type CreatePlanOutput struct { } type GetPlanInput struct { - ID uuid.UUID `json:"id" jsonschema:"plan id"` + ID int64 `json:"id" jsonschema:"plan id"` } type GetPlanOutput struct { @@ -51,21 +50,21 @@ type GetPlanOutput struct { } type UpdatePlanInput struct { - ID uuid.UUID `json:"id" jsonschema:"plan id"` - Title string `json:"title,omitempty"` - Description string `json:"description,omitempty"` - Status string `json:"status,omitempty" jsonschema:"draft|active|blocked|completed|cancelled|superseded"` - Priority string `json:"priority,omitempty" jsonschema:"low|medium|high|critical"` - Owner *string `json:"owner,omitempty" jsonschema:"empty string clears the owner"` - DueDate string `json:"due_date,omitempty" jsonschema:"RFC3339; omit to keep, 'clear' to remove"` - ClearDueDate bool `json:"clear_due_date,omitempty"` - CompletedAt string `json:"completed_at,omitempty" jsonschema:"RFC3339; omit to keep, 'clear' to remove"` - ClearCompletedAt bool `json:"clear_completed_at,omitempty"` - ReviewedBy *string `json:"reviewed_by,omitempty" jsonschema:"empty string clears the reviewer"` - MarkReviewed bool `json:"mark_reviewed,omitempty" jsonschema:"set last_reviewed_at to now"` - SupersedesPlanID *uuid.UUID `json:"supersedes_plan_id,omitempty"` - ClearSupersedesPlanID bool `json:"clear_supersedes_plan_id,omitempty"` - Tags *[]string `json:"tags,omitempty" jsonschema:"replaces all tags when provided; pass [] to clear"` + ID int64 `json:"id" jsonschema:"plan id"` + Title string `json:"title,omitempty"` + Description string `json:"description,omitempty"` + Status string `json:"status,omitempty" jsonschema:"draft|active|blocked|completed|cancelled|superseded"` + Priority string `json:"priority,omitempty" jsonschema:"low|medium|high|critical"` + Owner *string `json:"owner,omitempty" jsonschema:"empty string clears the owner"` + DueDate string `json:"due_date,omitempty" jsonschema:"RFC3339; omit to keep, 'clear' to remove"` + ClearDueDate bool `json:"clear_due_date,omitempty"` + CompletedAt string `json:"completed_at,omitempty" jsonschema:"RFC3339; omit to keep, 'clear' to remove"` + ClearCompletedAt bool `json:"clear_completed_at,omitempty"` + ReviewedBy *string `json:"reviewed_by,omitempty" jsonschema:"empty string clears the reviewer"` + MarkReviewed bool `json:"mark_reviewed,omitempty" jsonschema:"set last_reviewed_at to now"` + SupersedesPlanID *int64 `json:"supersedes_plan_id,omitempty"` + ClearSupersedesPlanID bool `json:"clear_supersedes_plan_id,omitempty"` + Tags *[]string `json:"tags,omitempty" jsonschema:"replaces all tags when provided; pass [] to clear"` } type UpdatePlanOutput struct { @@ -73,7 +72,7 @@ type UpdatePlanOutput struct { } type DeletePlanInput struct { - ID uuid.UUID `json:"id" jsonschema:"plan id"` + ID int64 `json:"id" jsonschema:"plan id"` } type DeletePlanOutput struct { @@ -95,13 +94,13 @@ type ListPlansOutput struct { } type PlanDependencyInput struct { - PlanID uuid.UUID `json:"plan_id" jsonschema:"the plan that depends on another"` - DependsOnPlanID uuid.UUID `json:"depends_on_plan_id" jsonschema:"the plan that must complete first"` + PlanID int64 `json:"plan_id" jsonschema:"the plan that depends on another"` + DependsOnPlanID int64 `json:"depends_on_plan_id" jsonschema:"the plan that must complete first"` } type PlanRelatedInput struct { - PlanAID uuid.UUID `json:"plan_a_id"` - PlanBID uuid.UUID `json:"plan_b_id"` + PlanAID int64 `json:"plan_a_id"` + PlanBID int64 `json:"plan_b_id"` } type PlanLinkOutput struct { @@ -109,12 +108,12 @@ type PlanLinkOutput struct { } type PlanSkillInput struct { - PlanID uuid.UUID `json:"plan_id"` - SkillID uuid.UUID `json:"skill_id"` + PlanID int64 `json:"plan_id"` + SkillID int64 `json:"skill_id"` } type ListPlanSkillsInput struct { - PlanID uuid.UUID `json:"plan_id"` + PlanID int64 `json:"plan_id"` } type ListPlanSkillsOutput struct { @@ -122,12 +121,12 @@ type ListPlanSkillsOutput struct { } type PlanGuardrailInput struct { - PlanID uuid.UUID `json:"plan_id"` - GuardrailID uuid.UUID `json:"guardrail_id"` + PlanID int64 `json:"plan_id"` + GuardrailID int64 `json:"guardrail_id"` } type ListPlanGuardrailsInput struct { - PlanID uuid.UUID `json:"plan_id"` + PlanID int64 `json:"plan_id"` } type ListPlanGuardrailsOutput struct { @@ -157,7 +156,7 @@ func (t *PlansTool) Create(ctx context.Context, req *mcp.CallToolRequest, in Cre Tags: normalizeStringSlice(in.Tags), } if project != nil { - plan.ProjectID = &project.ID + plan.ProjectID = &project.NumericID } if v := strings.TrimSpace(in.DueDate); v != "" { t, err := time.Parse(time.RFC3339, v) @@ -249,7 +248,7 @@ func (t *PlansTool) List(ctx context.Context, req *mcp.CallToolRequest, in ListP Query: strings.TrimSpace(in.Query), } if project != nil { - filter.ProjectID = &project.ID + filter.ProjectID = &project.NumericID } plans, err := t.store.ListPlans(ctx, filter) diff --git a/internal/tools/projects.go b/internal/tools/projects.go index 4d0998b..eed87d4 100644 --- a/internal/tools/projects.go +++ b/internal/tools/projects.go @@ -79,7 +79,7 @@ func (t *ProjectsTool) SetActive(ctx context.Context, req *mcp.CallToolRequest, return nil, SetActiveProjectOutput{}, err } t.sessions.Set(sid, project.ID) - _ = t.store.TouchProject(ctx, project.ID) + _ = t.store.TouchProject(ctx, project.NumericID) return nil, SetActiveProjectOutput{Project: *project}, nil } diff --git a/internal/tools/recall.go b/internal/tools/recall.go index 16fb784..d392098 100644 --- a/internal/tools/recall.go +++ b/internal/tools/recall.go @@ -5,7 +5,6 @@ import ( "fmt" "strings" - "github.com/google/uuid" "github.com/modelcontextprotocol/go-sdk/mcp" "git.warky.dev/wdevs/amcs/internal/ai" @@ -49,9 +48,9 @@ func (t *RecallTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in Re limit := normalizeLimit(in.Limit, t.search) - var projectID *uuid.UUID + var projectID *int64 if project != nil { - projectID = &project.ID + projectID = &project.NumericID } semantic, err := semanticSearch(ctx, t.store, t.embeddings, t.search, query, limit, t.search.DefaultThreshold, projectID, nil) @@ -66,7 +65,7 @@ func (t *RecallTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in Re items := make([]ContextItem, 0, limit*2) seen := map[string]struct{}{} for _, result := range semantic { - key := result.ID.String() + key := fmt.Sprint(result.ID) seen[key] = struct{}{} items = append(items, ContextItem{ ID: key, @@ -77,7 +76,7 @@ func (t *RecallTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in Re }) } for _, thought := range recent { - key := thought.ID.String() + key := fmt.Sprint(thought.ID) if _, ok := seen[key]; ok { continue } @@ -97,7 +96,7 @@ func (t *RecallTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in Re header := "Recalled context" if project != nil { header = fmt.Sprintf("Recalled context for %s", project.Name) - _ = t.store.TouchProject(ctx, project.ID) + _ = t.store.TouchProject(ctx, project.NumericID) } return nil, RecallOutput{ diff --git a/internal/tools/reparse_metadata.go b/internal/tools/reparse_metadata.go index 7b5e31c..e4d0977 100644 --- a/internal/tools/reparse_metadata.go +++ b/internal/tools/reparse_metadata.go @@ -2,12 +2,12 @@ package tools import ( "context" + "fmt" "log/slog" "reflect" "sync" "time" - "github.com/google/uuid" "github.com/modelcontextprotocol/go-sdk/mcp" "golang.org/x/sync/semaphore" @@ -68,9 +68,9 @@ func (t *ReparseMetadataTool) Handle(ctx context.Context, req *mcp.CallToolReque return nil, ReparseMetadataOutput{}, err } - var projectID *uuid.UUID + var projectID *int64 if project != nil { - projectID = &project.ID + projectID = &project.NumericID } thoughts, err := t.store.ListThoughtsForMetadataReparse(ctx, limit, projectID, in.IncludeArchived, in.OlderThanDays) @@ -114,7 +114,7 @@ func (t *ReparseMetadataTool) Handle(ctx context.Context, req *mcp.CallToolReque mu.Lock() out.Normalized++ mu.Unlock() - t.logger.Warn("metadata reparse extract failed, using normalized existing metadata", slog.String("thought_id", thought.ID.String()), slog.String("error", extractErr.Error())) + t.logger.Warn("metadata reparse extract failed, using normalized existing metadata", slog.String("thought_id", fmt.Sprint(thought.ID)), slog.String("error", extractErr.Error())) } else { normalizedTarget = metadata.MarkMetadataComplete(metadata.SanitizeExtracted(extracted), t.capture, attemptedAt) normalizedTarget.Attachments = thought.Metadata.Attachments @@ -130,11 +130,11 @@ func (t *ReparseMetadataTool) Handle(ctx context.Context, req *mcp.CallToolReque return } - if _, updateErr := t.store.UpdateThought(ctx, thought.ID, thought.Content, nil, "", normalizedTarget, thought.ProjectID); updateErr != nil { + if _, updateErr := t.store.UpdateThought(ctx, thought.GUID, thought.Content, nil, "", normalizedTarget, thought.ProjectID); updateErr != nil { mu.Lock() - out.Failures = append(out.Failures, ReparseMetadataFailure{ID: thought.ID.String(), Error: updateErr.Error()}) + out.Failures = append(out.Failures, ReparseMetadataFailure{ID: fmt.Sprint(thought.ID), Error: updateErr.Error()}) mu.Unlock() - t.logger.Warn("metadata reparse update failed", slog.String("thought_id", thought.ID.String()), slog.String("error", updateErr.Error())) + t.logger.Warn("metadata reparse update failed", slog.String("thought_id", fmt.Sprint(thought.ID)), slog.String("error", updateErr.Error())) return } diff --git a/internal/tools/retrieval.go b/internal/tools/retrieval.go index 5d51c18..0fcb32a 100644 --- a/internal/tools/retrieval.go +++ b/internal/tools/retrieval.go @@ -23,7 +23,7 @@ func semanticSearch( query string, limit int, threshold float64, - projectID *uuid.UUID, + projectID *int64, excludeID *uuid.UUID, ) ([]thoughttypes.SearchResult, error) { model := embeddings.PrimaryModel() diff --git a/internal/tools/search.go b/internal/tools/search.go index 6aade33..7fa79be 100644 --- a/internal/tools/search.go +++ b/internal/tools/search.go @@ -4,7 +4,6 @@ import ( "context" "strings" - "github.com/google/uuid" "github.com/modelcontextprotocol/go-sdk/mcp" "git.warky.dev/wdevs/amcs/internal/ai" @@ -50,10 +49,10 @@ func (t *SearchTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in Se return nil, SearchOutput{}, err } - var projectID *uuid.UUID + var projectID *int64 if project != nil { - projectID = &project.ID - _ = t.store.TouchProject(ctx, project.ID) + projectID = &project.NumericID + _ = t.store.TouchProject(ctx, project.NumericID) } results, err := semanticSearch(ctx, t.store, t.embeddings, t.search, query, limit, threshold, projectID, nil) diff --git a/internal/tools/skills.go b/internal/tools/skills.go index 7564bc3..537d0cb 100644 --- a/internal/tools/skills.go +++ b/internal/tools/skills.go @@ -4,7 +4,6 @@ import ( "context" "strings" - "github.com/google/uuid" "github.com/modelcontextprotocol/go-sdk/mcp" "git.warky.dev/wdevs/amcs/internal/session" @@ -59,7 +58,7 @@ func (t *SkillsTool) AddSkill(ctx context.Context, _ *mcp.CallToolRequest, in Ad // remove_skill type RemoveSkillInput struct { - ID uuid.UUID `json:"id" jsonschema:"skill id to remove"` + ID int64 `json:"id" jsonschema:"skill id to remove"` } type RemoveSkillOutput struct { @@ -147,7 +146,7 @@ func (t *SkillsTool) AddGuardrail(ctx context.Context, _ *mcp.CallToolRequest, i // remove_guardrail type RemoveGuardrailInput struct { - ID uuid.UUID `json:"id" jsonschema:"guardrail id to remove"` + ID int64 `json:"id" jsonschema:"guardrail id to remove"` } type RemoveGuardrailOutput struct { @@ -186,13 +185,13 @@ func (t *SkillsTool) ListGuardrails(ctx context.Context, _ *mcp.CallToolRequest, // add_project_skill type AddProjectSkillInput struct { - Project string `json:"project,omitempty" jsonschema:"project name or id (uses active project if omitted)"` - SkillID uuid.UUID `json:"skill_id" jsonschema:"skill id to link"` + Project string `json:"project,omitempty" jsonschema:"project name or id (uses active project if omitted)"` + SkillID int64 `json:"skill_id" jsonschema:"skill id to link"` } type AddProjectSkillOutput struct { - ProjectID uuid.UUID `json:"project_id"` - SkillID uuid.UUID `json:"skill_id"` + ProjectID int64 `json:"project_id"` + SkillID int64 `json:"skill_id"` } func (t *SkillsTool) AddProjectSkill(ctx context.Context, req *mcp.CallToolRequest, in AddProjectSkillInput) (*mcp.CallToolResult, AddProjectSkillOutput, error) { @@ -200,17 +199,17 @@ func (t *SkillsTool) AddProjectSkill(ctx context.Context, req *mcp.CallToolReque if err != nil { return nil, AddProjectSkillOutput{}, err } - if err := t.store.AddProjectSkill(ctx, project.ID, in.SkillID); err != nil { + if err := t.store.AddProjectSkill(ctx, project.NumericID, in.SkillID); err != nil { return nil, AddProjectSkillOutput{}, err } - return nil, AddProjectSkillOutput{ProjectID: project.ID, SkillID: in.SkillID}, nil + return nil, AddProjectSkillOutput{ProjectID: project.NumericID, SkillID: in.SkillID}, nil } // remove_project_skill type RemoveProjectSkillInput struct { - Project string `json:"project,omitempty" jsonschema:"project name or id (uses active project if omitted)"` - SkillID uuid.UUID `json:"skill_id" jsonschema:"skill id to unlink"` + Project string `json:"project,omitempty" jsonschema:"project name or id (uses active project if omitted)"` + SkillID int64 `json:"skill_id" jsonschema:"skill id to unlink"` } type RemoveProjectSkillOutput struct { @@ -222,7 +221,7 @@ func (t *SkillsTool) RemoveProjectSkill(ctx context.Context, req *mcp.CallToolRe if err != nil { return nil, RemoveProjectSkillOutput{}, err } - if err := t.store.RemoveProjectSkill(ctx, project.ID, in.SkillID); err != nil { + if err := t.store.RemoveProjectSkill(ctx, project.NumericID, in.SkillID); err != nil { return nil, RemoveProjectSkillOutput{}, err } return nil, RemoveProjectSkillOutput{Removed: true}, nil @@ -235,7 +234,7 @@ type ListProjectSkillsInput struct { } type ListProjectSkillsOutput struct { - ProjectID uuid.UUID `json:"project_id"` + ProjectID int64 `json:"project_id"` Skills []ext.AgentSkill `json:"skills"` } @@ -244,26 +243,26 @@ func (t *SkillsTool) ListProjectSkills(ctx context.Context, req *mcp.CallToolReq if err != nil { return nil, ListProjectSkillsOutput{}, err } - skills, err := t.store.ListProjectSkills(ctx, project.ID) + skills, err := t.store.ListProjectSkills(ctx, project.NumericID) if err != nil { return nil, ListProjectSkillsOutput{}, err } if skills == nil { skills = []ext.AgentSkill{} } - return nil, ListProjectSkillsOutput{ProjectID: project.ID, Skills: skills}, nil + return nil, ListProjectSkillsOutput{ProjectID: project.NumericID, Skills: skills}, nil } // add_project_guardrail type AddProjectGuardrailInput struct { - Project string `json:"project,omitempty" jsonschema:"project name or id (uses active project if omitted)"` - GuardrailID uuid.UUID `json:"guardrail_id" jsonschema:"guardrail id to link"` + Project string `json:"project,omitempty" jsonschema:"project name or id (uses active project if omitted)"` + GuardrailID int64 `json:"guardrail_id" jsonschema:"guardrail id to link"` } type AddProjectGuardrailOutput struct { - ProjectID uuid.UUID `json:"project_id"` - GuardrailID uuid.UUID `json:"guardrail_id"` + ProjectID int64 `json:"project_id"` + GuardrailID int64 `json:"guardrail_id"` } func (t *SkillsTool) AddProjectGuardrail(ctx context.Context, req *mcp.CallToolRequest, in AddProjectGuardrailInput) (*mcp.CallToolResult, AddProjectGuardrailOutput, error) { @@ -271,17 +270,17 @@ func (t *SkillsTool) AddProjectGuardrail(ctx context.Context, req *mcp.CallToolR if err != nil { return nil, AddProjectGuardrailOutput{}, err } - if err := t.store.AddProjectGuardrail(ctx, project.ID, in.GuardrailID); err != nil { + if err := t.store.AddProjectGuardrail(ctx, project.NumericID, in.GuardrailID); err != nil { return nil, AddProjectGuardrailOutput{}, err } - return nil, AddProjectGuardrailOutput{ProjectID: project.ID, GuardrailID: in.GuardrailID}, nil + return nil, AddProjectGuardrailOutput{ProjectID: project.NumericID, GuardrailID: in.GuardrailID}, nil } // remove_project_guardrail type RemoveProjectGuardrailInput struct { - Project string `json:"project,omitempty" jsonschema:"project name or id (uses active project if omitted)"` - GuardrailID uuid.UUID `json:"guardrail_id" jsonschema:"guardrail id to unlink"` + Project string `json:"project,omitempty" jsonschema:"project name or id (uses active project if omitted)"` + GuardrailID int64 `json:"guardrail_id" jsonschema:"guardrail id to unlink"` } type RemoveProjectGuardrailOutput struct { @@ -293,7 +292,7 @@ func (t *SkillsTool) RemoveProjectGuardrail(ctx context.Context, req *mcp.CallTo if err != nil { return nil, RemoveProjectGuardrailOutput{}, err } - if err := t.store.RemoveProjectGuardrail(ctx, project.ID, in.GuardrailID); err != nil { + if err := t.store.RemoveProjectGuardrail(ctx, project.NumericID, in.GuardrailID); err != nil { return nil, RemoveProjectGuardrailOutput{}, err } return nil, RemoveProjectGuardrailOutput{Removed: true}, nil @@ -306,7 +305,7 @@ type ListProjectGuardrailsInput struct { } type ListProjectGuardrailsOutput struct { - ProjectID uuid.UUID `json:"project_id"` + ProjectID int64 `json:"project_id"` Guardrails []ext.AgentGuardrail `json:"guardrails"` } @@ -315,12 +314,12 @@ func (t *SkillsTool) ListProjectGuardrails(ctx context.Context, req *mcp.CallToo if err != nil { return nil, ListProjectGuardrailsOutput{}, err } - guardrails, err := t.store.ListProjectGuardrails(ctx, project.ID) + guardrails, err := t.store.ListProjectGuardrails(ctx, project.NumericID) if err != nil { return nil, ListProjectGuardrailsOutput{}, err } if guardrails == nil { guardrails = []ext.AgentGuardrail{} } - return nil, ListProjectGuardrailsOutput{ProjectID: project.ID, Guardrails: guardrails}, nil + return nil, ListProjectGuardrailsOutput{ProjectID: project.NumericID, Guardrails: guardrails}, nil } diff --git a/internal/tools/summarize.go b/internal/tools/summarize.go index 3762bce..805c250 100644 --- a/internal/tools/summarize.go +++ b/internal/tools/summarize.go @@ -4,7 +4,6 @@ import ( "context" "strings" - "github.com/google/uuid" "github.com/modelcontextprotocol/go-sdk/mcp" "git.warky.dev/wdevs/amcs/internal/ai" @@ -49,9 +48,9 @@ func (t *SummarizeTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in count := 0 if query != "" { - var projectID *uuid.UUID + var projectID *int64 if project != nil { - projectID = &project.ID + projectID = &project.NumericID } results, err := semanticSearch(ctx, t.store, t.embeddings, t.search, query, limit, t.search.DefaultThreshold, projectID, nil) if err != nil { @@ -62,9 +61,9 @@ func (t *SummarizeTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in } count = len(results) } else { - var projectID *uuid.UUID + var projectID *int64 if project != nil { - projectID = &project.ID + projectID = &project.NumericID } thoughts, err := t.store.RecentThoughts(ctx, projectID, limit, in.Days) if err != nil { @@ -83,7 +82,7 @@ func (t *SummarizeTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in return nil, SummarizeOutput{}, err } if project != nil { - _ = t.store.TouchProject(ctx, project.ID) + _ = t.store.TouchProject(ctx, project.NumericID) } return nil, SummarizeOutput{Summary: summary, Count: count}, nil diff --git a/internal/tools/update.go b/internal/tools/update.go index 4865128..c3611bc 100644 --- a/internal/tools/update.go +++ b/internal/tools/update.go @@ -83,7 +83,7 @@ func (t *UpdateTool) Handle(ctx context.Context, _ *mcp.CallToolRequest, in Upda if err != nil { return nil, UpdateOutput{}, err } - projectID = &project.ID + projectID = &project.NumericID } updated, err := t.store.UpdateThought(ctx, id, content, embedding, embeddingModel, mergedMetadata, projectID) diff --git a/internal/types/extensions.go b/internal/types/extensions.go index ad48872..c428b2b 100644 --- a/internal/types/extensions.go +++ b/internal/types/extensions.go @@ -217,7 +217,8 @@ type ContactHistory struct { // Agent Skills & Guardrails type AgentSkill struct { - ID uuid.UUID `json:"id"` + ID int64 `json:"id"` + GUID uuid.UUID `json:"guid"` Name string `json:"name"` Description string `json:"description,omitempty"` Content string `json:"content"` @@ -227,7 +228,8 @@ type AgentSkill struct { } type AgentGuardrail struct { - ID uuid.UUID `json:"id"` + ID int64 `json:"id"` + GUID uuid.UUID `json:"guid"` Name string `json:"name"` Description string `json:"description,omitempty"` Content string `json:"content"` @@ -245,12 +247,13 @@ type ChatMessage struct { } type ChatHistory struct { - ID uuid.UUID `json:"id"` + ID int64 `json:"id"` + GUID uuid.UUID `json:"guid"` SessionID string `json:"session_id"` Title string `json:"title,omitempty"` Channel string `json:"channel,omitempty"` AgentID string `json:"agent_id,omitempty"` - ProjectID *uuid.UUID `json:"project_id,omitempty"` + ProjectID *int64 `json:"project_id,omitempty"` Messages []ChatMessage `json:"messages"` Summary string `json:"summary,omitempty"` Metadata map[string]any `json:"metadata"` diff --git a/internal/types/learning.go b/internal/types/learning.go index f0b986a..421a46b 100644 --- a/internal/types/learning.go +++ b/internal/types/learning.go @@ -33,7 +33,8 @@ const ( ) type Learning struct { - ID uuid.UUID `json:"id"` + ID int64 `json:"id"` + GUID uuid.UUID `json:"guid"` Summary string `json:"summary"` Details string `json:"details"` Category string `json:"category"` @@ -44,13 +45,13 @@ type Learning struct { ActionRequired bool `json:"action_required"` SourceType string `json:"source_type,omitempty"` SourceRef string `json:"source_ref,omitempty"` - ProjectID *uuid.UUID `json:"project_id,omitempty"` - RelatedThoughtID *uuid.UUID `json:"related_thought_id,omitempty"` - RelatedSkillID *uuid.UUID `json:"related_skill_id,omitempty"` + ProjectID *int64 `json:"project_id,omitempty"` + RelatedThoughtID *int64 `json:"related_thought_id,omitempty"` + RelatedSkillID *int64 `json:"related_skill_id,omitempty"` ReviewedBy *string `json:"reviewed_by,omitempty"` ReviewedAt *time.Time `json:"reviewed_at,omitempty"` - DuplicateOfLearningID *uuid.UUID `json:"duplicate_of_learning_id,omitempty"` - SupersedesLearningID *uuid.UUID `json:"supersedes_learning_id,omitempty"` + DuplicateOfLearningID *int64 `json:"duplicate_of_learning_id,omitempty"` + SupersedesLearningID *int64 `json:"supersedes_learning_id,omitempty"` Tags []string `json:"tags"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` @@ -58,7 +59,7 @@ type Learning struct { type LearningFilter struct { Limit int - ProjectID *uuid.UUID + ProjectID *int64 Category string Area string Status string diff --git a/internal/types/plan.go b/internal/types/plan.go index 78290b1..a2e7b11 100644 --- a/internal/types/plan.go +++ b/internal/types/plan.go @@ -27,18 +27,19 @@ const ( ) type Plan struct { - ID uuid.UUID `json:"id"` + ID int64 `json:"id"` + GUID uuid.UUID `json:"guid"` Title string `json:"title"` Description string `json:"description"` Status PlanStatus `json:"status"` Priority PlanPriority `json:"priority"` - ProjectID *uuid.UUID `json:"project_id,omitempty"` + ProjectID *int64 `json:"project_id,omitempty"` Owner string `json:"owner,omitempty"` DueDate *time.Time `json:"due_date,omitempty"` CompletedAt *time.Time `json:"completed_at,omitempty"` ReviewedBy string `json:"reviewed_by,omitempty"` LastReviewedAt *time.Time `json:"last_reviewed_at,omitempty"` - SupersedesPlanID *uuid.UUID `json:"supersedes_plan_id,omitempty"` + SupersedesPlanID *int64 `json:"supersedes_plan_id,omitempty"` Tags []string `json:"tags"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` @@ -56,7 +57,7 @@ type PlanDetail struct { type PlanFilter struct { Limit int - ProjectID *uuid.UUID + ProjectID *int64 Status string Priority string Owner string @@ -77,7 +78,7 @@ type PlanUpdate struct { ClearCompletedAt bool ReviewedBy *string // "" to clear MarkReviewed bool // sets last_reviewed_at = now() - SupersedesPlanID *uuid.UUID + SupersedesPlanID *int64 ClearSupersedesPlanID bool Tags *[]string // nil = no change; replace when non-nil } diff --git a/internal/types/project.go b/internal/types/project.go index 633c03c..d5eefc9 100644 --- a/internal/types/project.go +++ b/internal/types/project.go @@ -9,11 +9,12 @@ import ( type ThoughtPatch struct { Content *string `json:"content,omitempty"` Metadata ThoughtMetadata `json:"metadata,omitempty"` - Project *uuid.UUID `json:"project_id,omitempty"` + Project *int64 `json:"project_id,omitempty"` } type Project struct { ID uuid.UUID `json:"id"` + NumericID int64 `json:"-"` Name string `json:"name"` Description string `json:"description,omitempty"` CreatedAt time.Time `json:"created_at"` diff --git a/internal/types/thought.go b/internal/types/thought.go index e122e29..4f01af9 100644 --- a/internal/types/thought.go +++ b/internal/types/thought.go @@ -30,9 +30,10 @@ type ThoughtAttachment struct { } type StoredFile struct { - ID uuid.UUID `json:"id"` - ThoughtID *uuid.UUID `json:"thought_id,omitempty"` - ProjectID *uuid.UUID `json:"project_id,omitempty"` + ID int64 `json:"id"` + GUID uuid.UUID `json:"guid"` + ThoughtID *int64 `json:"thought_id,omitempty"` + ProjectID *int64 `json:"project_id,omitempty"` Name string `json:"name"` MediaType string `json:"media_type"` Kind string `json:"kind"` @@ -46,25 +47,26 @@ type StoredFile struct { type StoredFileFilter struct { Limit int - ThoughtID *uuid.UUID - ProjectID *uuid.UUID + ThoughtID *int64 + ProjectID *int64 Kind string } type Thought struct { - ID uuid.UUID `json:"id"` + ID int64 `json:"id"` + GUID uuid.UUID `json:"guid"` Content string `json:"content"` Embedding []float32 `json:"embedding,omitempty"` EmbeddingStatus string `json:"embedding_status,omitempty"` Metadata ThoughtMetadata `json:"metadata"` - ProjectID *uuid.UUID `json:"project_id,omitempty"` + ProjectID *int64 `json:"project_id,omitempty"` ArchivedAt *time.Time `json:"archived_at,omitempty"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } type SearchResult struct { - ID uuid.UUID `json:"id"` + ID int64 `json:"id"` Content string `json:"content"` Metadata ThoughtMetadata `json:"metadata"` Similarity float64 `json:"similarity"` @@ -77,7 +79,7 @@ type ListFilter struct { Topic string Person string Days int - ProjectID *uuid.UUID + ProjectID *int64 IncludeArchived bool } diff --git a/migrations/015_bigserial_guid_migration.sql b/migrations/015_bigserial_guid_migration.sql new file mode 100644 index 0000000..7404481 --- /dev/null +++ b/migrations/015_bigserial_guid_migration.sql @@ -0,0 +1,338 @@ +-- Migration: Convert uuid PKs to bigserial, rename old uuid id to guid, convert FK columns to bigint +-- Tables with uuid PK → bigserial: agent_skills, agent_guardrails, chat_histories, learnings, plans +-- Tables with serial → bigserial: thought_links, plan_dependencies, plan_related_plans, plan_skills, plan_guardrails, project_skills, project_guardrails +-- FK columns: all uuid FK columns converted to bigint referencing .id + +BEGIN; + +-- ============================================================ +-- STEP 1: Drop all FK constraints affected by this migration +-- ============================================================ + +ALTER TABLE public.thoughts DROP CONSTRAINT IF EXISTS thoughts_project_id_fkey; +ALTER TABLE public.embeddings DROP CONSTRAINT IF EXISTS embeddings_thought_id_fkey; +ALTER TABLE public.stored_files DROP CONSTRAINT IF EXISTS stored_files_thought_id_fkey; +ALTER TABLE public.stored_files DROP CONSTRAINT IF EXISTS stored_files_project_id_fkey; +ALTER TABLE public.project_skills DROP CONSTRAINT IF EXISTS project_skills_project_id_fkey; +ALTER TABLE public.project_skills DROP CONSTRAINT IF EXISTS project_skills_skill_id_fkey; +ALTER TABLE public.project_guardrails DROP CONSTRAINT IF EXISTS project_guardrails_project_id_fkey; +ALTER TABLE public.project_guardrails DROP CONSTRAINT IF EXISTS project_guardrails_guardrail_id_fkey; +ALTER TABLE public.chat_histories DROP CONSTRAINT IF EXISTS chat_histories_project_id_fkey; +ALTER TABLE public.learnings DROP CONSTRAINT IF EXISTS learnings_project_id_fkey; +ALTER TABLE public.learnings DROP CONSTRAINT IF EXISTS learnings_related_thought_id_fkey; +ALTER TABLE public.learnings DROP CONSTRAINT IF EXISTS learnings_related_skill_id_fkey; +ALTER TABLE public.learnings DROP CONSTRAINT IF EXISTS learnings_duplicate_of_learning_id_fkey; +ALTER TABLE public.learnings DROP CONSTRAINT IF EXISTS learnings_supersedes_learning_id_fkey; +ALTER TABLE public.plans DROP CONSTRAINT IF EXISTS plans_project_id_fkey; +ALTER TABLE public.plans DROP CONSTRAINT IF EXISTS plans_supersedes_plan_id_fkey; +ALTER TABLE public.plan_dependencies DROP CONSTRAINT IF EXISTS plan_dependencies_plan_id_fkey; +ALTER TABLE public.plan_dependencies DROP CONSTRAINT IF EXISTS plan_dependencies_depends_on_plan_id_fkey; +ALTER TABLE public.plan_related_plans DROP CONSTRAINT IF EXISTS plan_related_plans_plan_a_id_fkey; +ALTER TABLE public.plan_related_plans DROP CONSTRAINT IF EXISTS plan_related_plans_plan_b_id_fkey; +ALTER TABLE public.plan_skills DROP CONSTRAINT IF EXISTS plan_skills_plan_id_fkey; +ALTER TABLE public.plan_skills DROP CONSTRAINT IF EXISTS plan_skills_skill_id_fkey; +ALTER TABLE public.plan_guardrails DROP CONSTRAINT IF EXISTS plan_guardrails_plan_id_fkey; +ALTER TABLE public.plan_guardrails DROP CONSTRAINT IF EXISTS plan_guardrails_guardrail_id_fkey; + +-- ============================================================ +-- STEP 2: Drop PK constraints on uuid-pk tables +-- ============================================================ + +ALTER TABLE public.agent_skills DROP CONSTRAINT IF EXISTS agent_skills_pkey; +ALTER TABLE public.agent_guardrails DROP CONSTRAINT IF EXISTS agent_guardrails_pkey; +ALTER TABLE public.chat_histories DROP CONSTRAINT IF EXISTS chat_histories_pkey; +ALTER TABLE public.learnings DROP CONSTRAINT IF EXISTS learnings_pkey; +ALTER TABLE public.plans DROP CONSTRAINT IF EXISTS plans_pkey; + +-- ============================================================ +-- STEP 3: Rename uuid id → guid on formerly uuid-pk tables +-- ============================================================ + +ALTER TABLE public.agent_skills RENAME COLUMN id TO guid; +ALTER TABLE public.agent_guardrails RENAME COLUMN id TO guid; +ALTER TABLE public.chat_histories RENAME COLUMN id TO guid; +ALTER TABLE public.learnings RENAME COLUMN id TO guid; +ALTER TABLE public.plans RENAME COLUMN id TO guid; + +-- ============================================================ +-- STEP 4: Add bigserial id columns to formerly uuid-pk tables +-- ============================================================ + +ALTER TABLE public.agent_skills ADD COLUMN id bigserial; +ALTER TABLE public.agent_guardrails ADD COLUMN id bigserial; +ALTER TABLE public.chat_histories ADD COLUMN id bigserial; +ALTER TABLE public.learnings ADD COLUMN id bigserial; +ALTER TABLE public.plans ADD COLUMN id bigserial; + +-- ============================================================ +-- STEP 5: Add new bigint FK columns (prefixed _new) where uuid FKs exist +-- ============================================================ + +-- thoughts.project_id (uuid → bigint via projects.guid) +ALTER TABLE public.thoughts ADD COLUMN project_id_new bigint; +UPDATE public.thoughts t SET project_id_new = p.id FROM public.projects p WHERE p.guid = t.project_id; + +-- embeddings.thought_id (uuid → bigint via thoughts.guid) +ALTER TABLE public.embeddings ADD COLUMN thought_id_new bigint; +UPDATE public.embeddings e SET thought_id_new = t.id FROM public.thoughts t WHERE t.guid = e.thought_id; + +-- stored_files.thought_id (uuid → bigint via thoughts.guid) +ALTER TABLE public.stored_files ADD COLUMN thought_id_new bigint; +UPDATE public.stored_files f SET thought_id_new = t.id FROM public.thoughts t WHERE t.guid = f.thought_id; + +-- stored_files.project_id (uuid → bigint via projects.guid) +ALTER TABLE public.stored_files ADD COLUMN project_id_new bigint; +UPDATE public.stored_files f SET project_id_new = p.id FROM public.projects p WHERE p.guid = f.project_id; + +-- project_skills.project_id (uuid → bigint via projects.guid) +ALTER TABLE public.project_skills ADD COLUMN project_id_new bigint; +UPDATE public.project_skills ps SET project_id_new = p.id FROM public.projects p WHERE p.guid = ps.project_id; + +-- project_skills.skill_id (uuid → bigint via agent_skills.guid) +ALTER TABLE public.project_skills ADD COLUMN skill_id_new bigint; +UPDATE public.project_skills ps SET skill_id_new = s.id FROM public.agent_skills s WHERE s.guid = ps.skill_id; + +-- project_guardrails.project_id (uuid → bigint via projects.guid) +ALTER TABLE public.project_guardrails ADD COLUMN project_id_new bigint; +UPDATE public.project_guardrails pg SET project_id_new = p.id FROM public.projects p WHERE p.guid = pg.project_id; + +-- project_guardrails.guardrail_id (uuid → bigint via agent_guardrails.guid) +ALTER TABLE public.project_guardrails ADD COLUMN guardrail_id_new bigint; +UPDATE public.project_guardrails pg SET guardrail_id_new = g.id FROM public.agent_guardrails g WHERE g.guid = pg.guardrail_id; + +-- chat_histories.project_id (uuid → bigint via projects.guid) +ALTER TABLE public.chat_histories ADD COLUMN project_id_new bigint; +UPDATE public.chat_histories ch SET project_id_new = p.id FROM public.projects p WHERE p.guid = ch.project_id; + +-- learnings.project_id (uuid → bigint via projects.guid) +ALTER TABLE public.learnings ADD COLUMN project_id_new bigint; +UPDATE public.learnings l SET project_id_new = p.id FROM public.projects p WHERE p.guid = l.project_id; + +-- learnings.related_thought_id (uuid → bigint via thoughts.guid) +ALTER TABLE public.learnings ADD COLUMN related_thought_id_new bigint; +UPDATE public.learnings l SET related_thought_id_new = t.id FROM public.thoughts t WHERE t.guid = l.related_thought_id; + +-- learnings.related_skill_id (uuid → bigint via agent_skills.guid) +ALTER TABLE public.learnings ADD COLUMN related_skill_id_new bigint; +UPDATE public.learnings l SET related_skill_id_new = s.id FROM public.agent_skills s WHERE s.guid = l.related_skill_id; + +-- learnings.duplicate_of_learning_id (uuid → bigint via learnings.guid) +ALTER TABLE public.learnings ADD COLUMN duplicate_of_learning_id_new bigint; +UPDATE public.learnings l SET duplicate_of_learning_id_new = l2.id FROM public.learnings l2 WHERE l2.guid = l.duplicate_of_learning_id; + +-- learnings.supersedes_learning_id (uuid → bigint via learnings.guid) +ALTER TABLE public.learnings ADD COLUMN supersedes_learning_id_new bigint; +UPDATE public.learnings l SET supersedes_learning_id_new = l2.id FROM public.learnings l2 WHERE l2.guid = l.supersedes_learning_id; + +-- plans.project_id (uuid → bigint via projects.guid) +ALTER TABLE public.plans ADD COLUMN project_id_new bigint; +UPDATE public.plans pl SET project_id_new = p.id FROM public.projects p WHERE p.guid = pl.project_id; + +-- plans.supersedes_plan_id (uuid → bigint via plans.guid) +ALTER TABLE public.plans ADD COLUMN supersedes_plan_id_new bigint; +UPDATE public.plans pl SET supersedes_plan_id_new = pl2.id FROM public.plans pl2 WHERE pl2.guid = pl.supersedes_plan_id; + +-- plan_dependencies.plan_id (uuid → bigint via plans.guid) +ALTER TABLE public.plan_dependencies ADD COLUMN plan_id_new bigint; +UPDATE public.plan_dependencies pd SET plan_id_new = pl.id FROM public.plans pl WHERE pl.guid = pd.plan_id; + +-- plan_dependencies.depends_on_plan_id (uuid → bigint via plans.guid) +ALTER TABLE public.plan_dependencies ADD COLUMN depends_on_plan_id_new bigint; +UPDATE public.plan_dependencies pd SET depends_on_plan_id_new = pl.id FROM public.plans pl WHERE pl.guid = pd.depends_on_plan_id; + +-- plan_related_plans.plan_a_id (uuid → bigint via plans.guid) +ALTER TABLE public.plan_related_plans ADD COLUMN plan_a_id_new bigint; +UPDATE public.plan_related_plans pr SET plan_a_id_new = pl.id FROM public.plans pl WHERE pl.guid = pr.plan_a_id; + +-- plan_related_plans.plan_b_id (uuid → bigint via plans.guid) +ALTER TABLE public.plan_related_plans ADD COLUMN plan_b_id_new bigint; +UPDATE public.plan_related_plans pr SET plan_b_id_new = pl.id FROM public.plans pl WHERE pl.guid = pr.plan_b_id; + +-- plan_skills.plan_id (uuid → bigint via plans.guid) +ALTER TABLE public.plan_skills ADD COLUMN plan_id_new bigint; +UPDATE public.plan_skills ps SET plan_id_new = pl.id FROM public.plans pl WHERE pl.guid = ps.plan_id; + +-- plan_skills.skill_id (uuid → bigint via agent_skills.guid) +ALTER TABLE public.plan_skills ADD COLUMN skill_id_new bigint; +UPDATE public.plan_skills ps SET skill_id_new = s.id FROM public.agent_skills s WHERE s.guid = ps.skill_id; + +-- plan_guardrails.plan_id (uuid → bigint via plans.guid) +ALTER TABLE public.plan_guardrails ADD COLUMN plan_id_new bigint; +UPDATE public.plan_guardrails pg SET plan_id_new = pl.id FROM public.plans pl WHERE pl.guid = pg.plan_id; + +-- plan_guardrails.guardrail_id (uuid → bigint via agent_guardrails.guid) +ALTER TABLE public.plan_guardrails ADD COLUMN guardrail_id_new bigint; +UPDATE public.plan_guardrails pg SET guardrail_id_new = g.id FROM public.agent_guardrails g WHERE g.guid = pg.guardrail_id; + +-- ============================================================ +-- STEP 6: Drop old uuid FK columns +-- ============================================================ + +ALTER TABLE public.thoughts DROP COLUMN project_id; +ALTER TABLE public.embeddings DROP COLUMN thought_id; +ALTER TABLE public.stored_files DROP COLUMN thought_id; +ALTER TABLE public.stored_files DROP COLUMN project_id; +ALTER TABLE public.project_skills DROP COLUMN project_id; +ALTER TABLE public.project_skills DROP COLUMN skill_id; +ALTER TABLE public.project_guardrails DROP COLUMN project_id; +ALTER TABLE public.project_guardrails DROP COLUMN guardrail_id; +ALTER TABLE public.chat_histories DROP COLUMN project_id; +ALTER TABLE public.learnings DROP COLUMN project_id; +ALTER TABLE public.learnings DROP COLUMN related_thought_id; +ALTER TABLE public.learnings DROP COLUMN related_skill_id; +ALTER TABLE public.learnings DROP COLUMN duplicate_of_learning_id; +ALTER TABLE public.learnings DROP COLUMN supersedes_learning_id; +ALTER TABLE public.plans DROP COLUMN project_id; +ALTER TABLE public.plans DROP COLUMN supersedes_plan_id; +ALTER TABLE public.plan_dependencies DROP COLUMN plan_id; +ALTER TABLE public.plan_dependencies DROP COLUMN depends_on_plan_id; +ALTER TABLE public.plan_related_plans DROP COLUMN plan_a_id; +ALTER TABLE public.plan_related_plans DROP COLUMN plan_b_id; +ALTER TABLE public.plan_skills DROP COLUMN plan_id; +ALTER TABLE public.plan_skills DROP COLUMN skill_id; +ALTER TABLE public.plan_guardrails DROP COLUMN plan_id; +ALTER TABLE public.plan_guardrails DROP COLUMN guardrail_id; + +-- ============================================================ +-- STEP 7: Rename _new columns to final names +-- ============================================================ + +ALTER TABLE public.thoughts RENAME COLUMN project_id_new TO project_id; +ALTER TABLE public.embeddings RENAME COLUMN thought_id_new TO thought_id; +ALTER TABLE public.stored_files RENAME COLUMN thought_id_new TO thought_id; +ALTER TABLE public.stored_files RENAME COLUMN project_id_new TO project_id; +ALTER TABLE public.project_skills RENAME COLUMN project_id_new TO project_id; +ALTER TABLE public.project_skills RENAME COLUMN skill_id_new TO skill_id; +ALTER TABLE public.project_guardrails RENAME COLUMN project_id_new TO project_id; +ALTER TABLE public.project_guardrails RENAME COLUMN guardrail_id_new TO guardrail_id; +ALTER TABLE public.chat_histories RENAME COLUMN project_id_new TO project_id; +ALTER TABLE public.learnings RENAME COLUMN project_id_new TO project_id; +ALTER TABLE public.learnings RENAME COLUMN related_thought_id_new TO related_thought_id; +ALTER TABLE public.learnings RENAME COLUMN related_skill_id_new TO related_skill_id; +ALTER TABLE public.learnings RENAME COLUMN duplicate_of_learning_id_new TO duplicate_of_learning_id; +ALTER TABLE public.learnings RENAME COLUMN supersedes_learning_id_new TO supersedes_learning_id; +ALTER TABLE public.plans RENAME COLUMN project_id_new TO project_id; +ALTER TABLE public.plans RENAME COLUMN supersedes_plan_id_new TO supersedes_plan_id; +ALTER TABLE public.plan_dependencies RENAME COLUMN plan_id_new TO plan_id; +ALTER TABLE public.plan_dependencies RENAME COLUMN depends_on_plan_id_new TO depends_on_plan_id; +ALTER TABLE public.plan_related_plans RENAME COLUMN plan_a_id_new TO plan_a_id; +ALTER TABLE public.plan_related_plans RENAME COLUMN plan_b_id_new TO plan_b_id; +ALTER TABLE public.plan_skills RENAME COLUMN plan_id_new TO plan_id; +ALTER TABLE public.plan_skills RENAME COLUMN skill_id_new TO skill_id; +ALTER TABLE public.plan_guardrails RENAME COLUMN plan_id_new TO plan_id; +ALTER TABLE public.plan_guardrails RENAME COLUMN guardrail_id_new TO guardrail_id; + +-- ============================================================ +-- STEP 8: Upgrade serial → bigserial (alter sequence type) +-- ============================================================ + +-- thought_links +ALTER SEQUENCE IF EXISTS thought_links_id_seq AS bigint; +ALTER TABLE public.thought_links ALTER COLUMN id TYPE bigint; + +-- plan_dependencies +ALTER SEQUENCE IF EXISTS plan_dependencies_id_seq AS bigint; +ALTER TABLE public.plan_dependencies ALTER COLUMN id TYPE bigint; + +-- plan_related_plans +ALTER SEQUENCE IF EXISTS plan_related_plans_id_seq AS bigint; +ALTER TABLE public.plan_related_plans ALTER COLUMN id TYPE bigint; + +-- plan_skills +ALTER SEQUENCE IF EXISTS plan_skills_id_seq AS bigint; +ALTER TABLE public.plan_skills ALTER COLUMN id TYPE bigint; + +-- plan_guardrails +ALTER SEQUENCE IF EXISTS plan_guardrails_id_seq AS bigint; +ALTER TABLE public.plan_guardrails ALTER COLUMN id TYPE bigint; + +-- project_skills +ALTER SEQUENCE IF EXISTS project_skills_id_seq AS bigint; +ALTER TABLE public.project_skills ALTER COLUMN id TYPE bigint; + +-- project_guardrails +ALTER SEQUENCE IF EXISTS project_guardrails_id_seq AS bigint; +ALTER TABLE public.project_guardrails ALTER COLUMN id TYPE bigint; + +-- ============================================================ +-- STEP 9: Add PK constraints to formerly uuid-pk tables +-- ============================================================ + +ALTER TABLE public.agent_skills ADD CONSTRAINT agent_skills_pkey PRIMARY KEY (id); +ALTER TABLE public.agent_guardrails ADD CONSTRAINT agent_guardrails_pkey PRIMARY KEY (id); +ALTER TABLE public.chat_histories ADD CONSTRAINT chat_histories_pkey PRIMARY KEY (id); +ALTER TABLE public.learnings ADD CONSTRAINT learnings_pkey PRIMARY KEY (id); +ALTER TABLE public.plans ADD CONSTRAINT plans_pkey PRIMARY KEY (id); + +-- Add unique constraint on guid columns +ALTER TABLE public.agent_skills ADD CONSTRAINT agent_skills_guid_key UNIQUE (guid); +ALTER TABLE public.agent_guardrails ADD CONSTRAINT agent_guardrails_guid_key UNIQUE (guid); +ALTER TABLE public.chat_histories ADD CONSTRAINT chat_histories_guid_key UNIQUE (guid); +ALTER TABLE public.learnings ADD CONSTRAINT learnings_guid_key UNIQUE (guid); +ALTER TABLE public.plans ADD CONSTRAINT plans_guid_key UNIQUE (guid); + +-- ============================================================ +-- STEP 10: Re-add FK constraints +-- ============================================================ + +ALTER TABLE public.thoughts + ADD CONSTRAINT thoughts_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id); + +ALTER TABLE public.embeddings + ADD CONSTRAINT embeddings_thought_id_fkey FOREIGN KEY (thought_id) REFERENCES public.thoughts(id); + +ALTER TABLE public.stored_files + ADD CONSTRAINT stored_files_thought_id_fkey FOREIGN KEY (thought_id) REFERENCES public.thoughts(id); +ALTER TABLE public.stored_files + ADD CONSTRAINT stored_files_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id); + +ALTER TABLE public.project_skills + ADD CONSTRAINT project_skills_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE CASCADE; +ALTER TABLE public.project_skills + ADD CONSTRAINT project_skills_skill_id_fkey FOREIGN KEY (skill_id) REFERENCES public.agent_skills(id) ON DELETE CASCADE; + +ALTER TABLE public.project_guardrails + ADD CONSTRAINT project_guardrails_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE CASCADE; +ALTER TABLE public.project_guardrails + ADD CONSTRAINT project_guardrails_guardrail_id_fkey FOREIGN KEY (guardrail_id) REFERENCES public.agent_guardrails(id) ON DELETE CASCADE; + +ALTER TABLE public.chat_histories + ADD CONSTRAINT chat_histories_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE SET NULL; + +ALTER TABLE public.learnings + ADD CONSTRAINT learnings_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE SET NULL; +ALTER TABLE public.learnings + ADD CONSTRAINT learnings_related_thought_id_fkey FOREIGN KEY (related_thought_id) REFERENCES public.thoughts(id) ON DELETE SET NULL; +ALTER TABLE public.learnings + ADD CONSTRAINT learnings_related_skill_id_fkey FOREIGN KEY (related_skill_id) REFERENCES public.agent_skills(id) ON DELETE SET NULL; +ALTER TABLE public.learnings + ADD CONSTRAINT learnings_duplicate_of_learning_id_fkey FOREIGN KEY (duplicate_of_learning_id) REFERENCES public.learnings(id) ON DELETE SET NULL; +ALTER TABLE public.learnings + ADD CONSTRAINT learnings_supersedes_learning_id_fkey FOREIGN KEY (supersedes_learning_id) REFERENCES public.learnings(id) ON DELETE SET NULL; + +ALTER TABLE public.plans + ADD CONSTRAINT plans_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE SET NULL; +ALTER TABLE public.plans + ADD CONSTRAINT plans_supersedes_plan_id_fkey FOREIGN KEY (supersedes_plan_id) REFERENCES public.plans(id) ON DELETE SET NULL; + +ALTER TABLE public.plan_dependencies + ADD CONSTRAINT plan_dependencies_plan_id_fkey FOREIGN KEY (plan_id) REFERENCES public.plans(id) ON DELETE CASCADE; +ALTER TABLE public.plan_dependencies + ADD CONSTRAINT plan_dependencies_depends_on_plan_id_fkey FOREIGN KEY (depends_on_plan_id) REFERENCES public.plans(id) ON DELETE CASCADE; + +ALTER TABLE public.plan_related_plans + ADD CONSTRAINT plan_related_plans_plan_a_id_fkey FOREIGN KEY (plan_a_id) REFERENCES public.plans(id) ON DELETE CASCADE; +ALTER TABLE public.plan_related_plans + ADD CONSTRAINT plan_related_plans_plan_b_id_fkey FOREIGN KEY (plan_b_id) REFERENCES public.plans(id) ON DELETE CASCADE; + +ALTER TABLE public.plan_skills + ADD CONSTRAINT plan_skills_plan_id_fkey FOREIGN KEY (plan_id) REFERENCES public.plans(id) ON DELETE CASCADE; +ALTER TABLE public.plan_skills + ADD CONSTRAINT plan_skills_skill_id_fkey FOREIGN KEY (skill_id) REFERENCES public.agent_skills(id) ON DELETE CASCADE; + +ALTER TABLE public.plan_guardrails + ADD CONSTRAINT plan_guardrails_plan_id_fkey FOREIGN KEY (plan_id) REFERENCES public.plans(id) ON DELETE CASCADE; +ALTER TABLE public.plan_guardrails + ADD CONSTRAINT plan_guardrails_guardrail_id_fkey FOREIGN KEY (guardrail_id) REFERENCES public.agent_guardrails(id) ON DELETE CASCADE; + +COMMIT; diff --git a/migrations/020_generated_schema.sql b/migrations/020_generated_schema.sql index 5a90b6c..726fb38 100644 --- a/migrations/020_generated_schema.sql +++ b/migrations/020_generated_schema.sql @@ -38,6 +38,13 @@ CREATE SEQUENCE IF NOT EXISTS public.identity_stored_files_id START 1 CACHE 1; +CREATE SEQUENCE IF NOT EXISTS public.identity_chat_histories_id + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1 + CACHE 1; + CREATE SEQUENCE IF NOT EXISTS public.identity_tool_annotations_id INCREMENT 1 MINVALUE 1 @@ -45,6 +52,20 @@ CREATE SEQUENCE IF NOT EXISTS public.identity_tool_annotations_id START 1 CACHE 1; +CREATE SEQUENCE IF NOT EXISTS public.identity_learnings_id + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1 + CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS public.identity_plans_id + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1 + CACHE 1; + CREATE SEQUENCE IF NOT EXISTS public.identity_plan_dependencies_id INCREMENT 1 MINVALUE 1 @@ -73,6 +94,20 @@ CREATE SEQUENCE IF NOT EXISTS public.identity_plan_guardrails_id START 1 CACHE 1; +CREATE SEQUENCE IF NOT EXISTS public.identity_agent_skills_id + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1 + CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS public.identity_agent_guardrails_id + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1 + CACHE 1; + CREATE SEQUENCE IF NOT EXISTS public.identity_project_skills_id INCREMENT 1 MINVALUE 1 @@ -88,49 +123,14 @@ CREATE SEQUENCE IF NOT EXISTS public.identity_project_guardrails_id CACHE 1; -- Tables for schema: public -CREATE TABLE IF NOT EXISTS public.family_members ( - birth_date date, - created_at timestamptz NOT NULL DEFAULT now(), - id uuid NOT NULL DEFAULT gen_random_uuid(), - name text NOT NULL, - notes text, - relationship text -); - -CREATE TABLE IF NOT EXISTS public.activities ( - activity_type text, - created_at timestamptz NOT NULL DEFAULT now(), - day_of_week text, - end_date date, - end_time time, - family_member_id uuid, - id uuid NOT NULL DEFAULT gen_random_uuid(), - location text, - notes text, - start_date date, - start_time time, - title text NOT NULL -); - -CREATE TABLE IF NOT EXISTS public.important_dates ( - created_at timestamptz NOT NULL DEFAULT now(), - date_value date NOT NULL, - family_member_id uuid, - id uuid NOT NULL DEFAULT gen_random_uuid(), - notes text, - recurring_yearly boolean NOT NULL DEFAULT false, - reminder_days_before integer NOT NULL DEFAULT 7, - title text NOT NULL -); - CREATE TABLE IF NOT EXISTS public.thoughts ( archived_at timestamptz, content text NOT NULL, created_at timestamptz DEFAULT now(), guid uuid NOT NULL DEFAULT gen_random_uuid(), id bigserial NOT NULL, - metadata jsonb DEFAULT '{}'::jsonb, - project_id uuid, + metadata jsonb DEFAULT '''{}''::jsonb', + project_id bigint, updated_at timestamptz DEFAULT now() ); @@ -146,7 +146,7 @@ CREATE TABLE IF NOT EXISTS public.projects ( CREATE TABLE IF NOT EXISTS public.thought_links ( created_at timestamptz DEFAULT now(), from_id bigint NOT NULL, - id serial NOT NULL, + id bigserial NOT NULL, relation text NOT NULL, to_id bigint NOT NULL ); @@ -158,51 +158,10 @@ CREATE TABLE IF NOT EXISTS public.embeddings ( guid uuid NOT NULL DEFAULT gen_random_uuid(), id bigserial NOT NULL, model text NOT NULL, - thought_id uuid NOT NULL, + thought_id bigint NOT NULL, updated_at timestamptz DEFAULT now() ); -CREATE TABLE IF NOT EXISTS public.professional_contacts ( - company text, - created_at timestamptz NOT NULL DEFAULT now(), - email text, - follow_up_date date, - how_we_met text, - id uuid NOT NULL DEFAULT gen_random_uuid(), - last_contacted timestamptz, - linkedin_url text, - name text NOT NULL, - notes text, - phone text, - tags text[] NOT NULL DEFAULT '{}', - title text, - updated_at timestamptz NOT NULL DEFAULT now() -); - -CREATE TABLE IF NOT EXISTS public.contact_interactions ( - contact_id uuid NOT NULL, - created_at timestamptz NOT NULL DEFAULT now(), - follow_up_needed boolean NOT NULL DEFAULT false, - follow_up_notes text, - id uuid NOT NULL DEFAULT gen_random_uuid(), - interaction_type text NOT NULL, - occurred_at timestamptz NOT NULL DEFAULT now(), - summary text NOT NULL -); - -CREATE TABLE IF NOT EXISTS public.opportunities ( - contact_id uuid, - created_at timestamptz NOT NULL DEFAULT now(), - description text, - expected_close_date date, - id uuid NOT NULL DEFAULT gen_random_uuid(), - notes text, - stage text NOT NULL DEFAULT 'identified', - title text NOT NULL, - updated_at timestamptz NOT NULL DEFAULT now(), - value decimal(12,2) -); - CREATE TABLE IF NOT EXISTS public.stored_files ( content bytea NOT NULL, created_at timestamptz NOT NULL DEFAULT now(), @@ -212,105 +171,22 @@ CREATE TABLE IF NOT EXISTS public.stored_files ( kind text NOT NULL DEFAULT 'file', media_type text NOT NULL, name text NOT NULL, - project_id uuid, + project_id bigint, sha256 text NOT NULL, size_bytes bigint NOT NULL, - thought_id uuid, + thought_id bigint, updated_at timestamptz NOT NULL DEFAULT now() ); -CREATE TABLE IF NOT EXISTS public.household_items ( - category text, - created_at timestamptz NOT NULL DEFAULT now(), - details jsonb NOT NULL DEFAULT '{}', - id uuid NOT NULL DEFAULT gen_random_uuid(), - location text, - name text NOT NULL, - notes text, - updated_at timestamptz NOT NULL DEFAULT now() -); - -CREATE TABLE IF NOT EXISTS public.household_vendors ( - created_at timestamptz NOT NULL DEFAULT now(), - email text, - id uuid NOT NULL DEFAULT gen_random_uuid(), - last_used date, - name text NOT NULL, - notes text, - phone text, - rating integer, - service_type text, - website text -); - -CREATE TABLE IF NOT EXISTS public.maintenance_tasks ( - category text, - created_at timestamptz NOT NULL DEFAULT now(), - frequency_days integer, - id uuid NOT NULL DEFAULT gen_random_uuid(), - last_completed timestamptz, - name text NOT NULL, - next_due timestamptz, - notes text, - priority text NOT NULL DEFAULT 'medium', - updated_at timestamptz NOT NULL DEFAULT now() -); - -CREATE TABLE IF NOT EXISTS public.maintenance_logs ( - completed_at timestamptz NOT NULL DEFAULT now(), - cost decimal(10,2), - id uuid NOT NULL DEFAULT gen_random_uuid(), - next_action text, - notes text, - performed_by text, - task_id uuid NOT NULL -); - -CREATE TABLE IF NOT EXISTS public.recipes ( - cook_time_minutes integer, - created_at timestamptz NOT NULL DEFAULT now(), - cuisine text, - id uuid NOT NULL DEFAULT gen_random_uuid(), - ingredients jsonb NOT NULL DEFAULT '[]', - instructions jsonb NOT NULL DEFAULT '[]', - name text NOT NULL, - notes text, - prep_time_minutes integer, - rating integer, - servings integer, - tags text[] NOT NULL DEFAULT '{}', - updated_at timestamptz NOT NULL DEFAULT now() -); - -CREATE TABLE IF NOT EXISTS public.meal_plans ( - created_at timestamptz NOT NULL DEFAULT now(), - custom_meal text, - day_of_week text NOT NULL, - id uuid NOT NULL DEFAULT gen_random_uuid(), - meal_type text NOT NULL, - notes text, - recipe_id uuid, - servings integer, - week_start date NOT NULL -); - -CREATE TABLE IF NOT EXISTS public.shopping_lists ( - created_at timestamptz NOT NULL DEFAULT now(), - id uuid NOT NULL DEFAULT gen_random_uuid(), - items jsonb NOT NULL DEFAULT '[]', - notes text, - updated_at timestamptz NOT NULL DEFAULT now(), - week_start date NOT NULL -); - CREATE TABLE IF NOT EXISTS public.chat_histories ( agent_id text, channel text, created_at timestamptz NOT NULL DEFAULT now(), - id uuid NOT NULL DEFAULT gen_random_uuid(), - messages jsonb NOT NULL DEFAULT '[]', - metadata jsonb NOT NULL DEFAULT '{}', - project_id uuid, + guid uuid NOT NULL DEFAULT gen_random_uuid(), + id bigserial NOT NULL, + messages jsonb NOT NULL DEFAULT '''[', + metadata jsonb NOT NULL DEFAULT '''{}''', + project_id bigint, session_id text NOT NULL, summary text, title text, @@ -332,20 +208,21 @@ CREATE TABLE IF NOT EXISTS public.learnings ( confidence text NOT NULL DEFAULT 'hypothesis', created_at timestamptz NOT NULL DEFAULT now(), details text NOT NULL DEFAULT '', - duplicate_of_learning_id uuid, - id uuid NOT NULL DEFAULT gen_random_uuid(), + duplicate_of_learning_id bigint, + guid uuid NOT NULL DEFAULT gen_random_uuid(), + id bigserial NOT NULL, priority text NOT NULL DEFAULT 'medium', - project_id uuid, - related_skill_id uuid, - related_thought_id uuid, + project_id bigint, + related_skill_id bigint, + related_thought_id bigint, reviewed_at timestamptz, reviewed_by text, source_ref text, source_type text, status text NOT NULL DEFAULT 'pending', summary text NOT NULL, - supersedes_learning_id uuid, - tags text[] NOT NULL DEFAULT '{}', + supersedes_learning_id bigint, + tags text, updated_at timestamptz NOT NULL DEFAULT now() ); @@ -354,54 +231,56 @@ CREATE TABLE IF NOT EXISTS public.plans ( created_at timestamptz NOT NULL DEFAULT now(), description text NOT NULL DEFAULT '', due_date timestamptz, - id uuid NOT NULL DEFAULT gen_random_uuid(), + guid uuid NOT NULL DEFAULT gen_random_uuid(), + id bigserial NOT NULL, last_reviewed_at timestamptz, owner text, priority text NOT NULL DEFAULT 'medium', - project_id uuid, + project_id bigint, reviewed_by text, status text NOT NULL DEFAULT 'draft', - supersedes_plan_id uuid, - tags text[] NOT NULL DEFAULT '{}', + supersedes_plan_id bigint, + tags text, title text NOT NULL, updated_at timestamptz NOT NULL DEFAULT now() ); CREATE TABLE IF NOT EXISTS public.plan_dependencies ( created_at timestamptz NOT NULL DEFAULT now(), - depends_on_plan_id uuid NOT NULL, - id serial NOT NULL, - plan_id uuid NOT NULL + depends_on_plan_id bigint NOT NULL, + id bigserial NOT NULL, + plan_id bigint NOT NULL ); CREATE TABLE IF NOT EXISTS public.plan_related_plans ( created_at timestamptz NOT NULL DEFAULT now(), - id serial NOT NULL, - plan_a_id uuid NOT NULL, - plan_b_id uuid NOT NULL + id bigserial NOT NULL, + plan_a_id bigint NOT NULL, + plan_b_id bigint NOT NULL ); CREATE TABLE IF NOT EXISTS public.plan_skills ( created_at timestamptz NOT NULL DEFAULT now(), - id serial NOT NULL, - plan_id uuid NOT NULL, - skill_id uuid NOT NULL + id bigserial NOT NULL, + plan_id bigint NOT NULL, + skill_id bigint NOT NULL ); CREATE TABLE IF NOT EXISTS public.plan_guardrails ( created_at timestamptz NOT NULL DEFAULT now(), - guardrail_id uuid NOT NULL, - id serial NOT NULL, - plan_id uuid NOT NULL + guardrail_id bigint NOT NULL, + id bigserial NOT NULL, + plan_id bigint NOT NULL ); CREATE TABLE IF NOT EXISTS public.agent_skills ( content text NOT NULL, created_at timestamptz NOT NULL DEFAULT now(), description text NOT NULL DEFAULT '', - id uuid NOT NULL DEFAULT gen_random_uuid(), + guid uuid NOT NULL DEFAULT gen_random_uuid(), + id bigserial NOT NULL, name text NOT NULL, - tags text[] NOT NULL DEFAULT '{}', + tags text, updated_at timestamptz NOT NULL DEFAULT now() ); @@ -409,366 +288,29 @@ CREATE TABLE IF NOT EXISTS public.agent_guardrails ( content text NOT NULL, created_at timestamptz NOT NULL DEFAULT now(), description text NOT NULL DEFAULT '', - id uuid NOT NULL DEFAULT gen_random_uuid(), + guid uuid NOT NULL DEFAULT gen_random_uuid(), + id bigserial NOT NULL, name text NOT NULL, severity text NOT NULL DEFAULT 'medium', - tags text[] NOT NULL DEFAULT '{}', + tags text, updated_at timestamptz NOT NULL DEFAULT now() ); CREATE TABLE IF NOT EXISTS public.project_skills ( created_at timestamptz NOT NULL DEFAULT now(), - id serial NOT NULL, - project_id uuid NOT NULL, - skill_id uuid NOT NULL + id bigserial NOT NULL, + project_id bigint NOT NULL, + skill_id bigint NOT NULL ); CREATE TABLE IF NOT EXISTS public.project_guardrails ( created_at timestamptz NOT NULL DEFAULT now(), - guardrail_id uuid NOT NULL, - id serial NOT NULL, - project_id uuid NOT NULL + guardrail_id bigint NOT NULL, + id bigserial NOT NULL, + project_id bigint NOT NULL ); -- Add missing columns for schema: public -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'family_members' - AND column_name = 'birth_date' - ) THEN - ALTER TABLE public.family_members ADD COLUMN birth_date date; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'family_members' - AND column_name = 'created_at' - ) THEN - ALTER TABLE public.family_members ADD COLUMN created_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'family_members' - AND column_name = 'id' - ) THEN - ALTER TABLE public.family_members ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'family_members' - AND column_name = 'name' - ) THEN - ALTER TABLE public.family_members ADD COLUMN name text NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'family_members' - AND column_name = 'notes' - ) THEN - ALTER TABLE public.family_members ADD COLUMN notes text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'family_members' - AND column_name = 'relationship' - ) THEN - ALTER TABLE public.family_members ADD COLUMN relationship text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'activities' - AND column_name = 'activity_type' - ) THEN - ALTER TABLE public.activities ADD COLUMN activity_type text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'activities' - AND column_name = 'created_at' - ) THEN - ALTER TABLE public.activities ADD COLUMN created_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'activities' - AND column_name = 'day_of_week' - ) THEN - ALTER TABLE public.activities ADD COLUMN day_of_week text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'activities' - AND column_name = 'end_date' - ) THEN - ALTER TABLE public.activities ADD COLUMN end_date date; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'activities' - AND column_name = 'end_time' - ) THEN - ALTER TABLE public.activities ADD COLUMN end_time time; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'activities' - AND column_name = 'family_member_id' - ) THEN - ALTER TABLE public.activities ADD COLUMN family_member_id uuid; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'activities' - AND column_name = 'id' - ) THEN - ALTER TABLE public.activities ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'activities' - AND column_name = 'location' - ) THEN - ALTER TABLE public.activities ADD COLUMN location text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'activities' - AND column_name = 'notes' - ) THEN - ALTER TABLE public.activities ADD COLUMN notes text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'activities' - AND column_name = 'start_date' - ) THEN - ALTER TABLE public.activities ADD COLUMN start_date date; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'activities' - AND column_name = 'start_time' - ) THEN - ALTER TABLE public.activities ADD COLUMN start_time time; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'activities' - AND column_name = 'title' - ) THEN - ALTER TABLE public.activities ADD COLUMN title text NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'important_dates' - AND column_name = 'created_at' - ) THEN - ALTER TABLE public.important_dates ADD COLUMN created_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'important_dates' - AND column_name = 'date_value' - ) THEN - ALTER TABLE public.important_dates ADD COLUMN date_value date NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'important_dates' - AND column_name = 'family_member_id' - ) THEN - ALTER TABLE public.important_dates ADD COLUMN family_member_id uuid; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'important_dates' - AND column_name = 'id' - ) THEN - ALTER TABLE public.important_dates ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'important_dates' - AND column_name = 'notes' - ) THEN - ALTER TABLE public.important_dates ADD COLUMN notes text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'important_dates' - AND column_name = 'recurring_yearly' - ) THEN - ALTER TABLE public.important_dates ADD COLUMN recurring_yearly boolean NOT NULL DEFAULT false; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'important_dates' - AND column_name = 'reminder_days_before' - ) THEN - ALTER TABLE public.important_dates ADD COLUMN reminder_days_before integer NOT NULL DEFAULT 7; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'important_dates' - AND column_name = 'title' - ) THEN - ALTER TABLE public.important_dates ADD COLUMN title text NOT NULL; - END IF; -END; -$$; - DO $$ BEGIN IF NOT EXISTS ( @@ -842,7 +384,7 @@ BEGIN AND table_name = 'thoughts' AND column_name = 'metadata' ) THEN - ALTER TABLE public.thoughts ADD COLUMN metadata jsonb DEFAULT '{}'::jsonb; + ALTER TABLE public.thoughts ADD COLUMN metadata jsonb DEFAULT '''{}''::jsonb'; END IF; END; $$; @@ -855,7 +397,7 @@ BEGIN AND table_name = 'thoughts' AND column_name = 'project_id' ) THEN - ALTER TABLE public.thoughts ADD COLUMN project_id uuid; + ALTER TABLE public.thoughts ADD COLUMN project_id bigint; END IF; END; $$; @@ -985,7 +527,7 @@ BEGIN AND table_name = 'thought_links' AND column_name = 'id' ) THEN - ALTER TABLE public.thought_links ADD COLUMN id serial NOT NULL; + ALTER TABLE public.thought_links ADD COLUMN id bigserial NOT NULL; END IF; END; $$; @@ -1102,7 +644,7 @@ BEGIN AND table_name = 'embeddings' AND column_name = 'thought_id' ) THEN - ALTER TABLE public.embeddings ADD COLUMN thought_id uuid NOT NULL; + ALTER TABLE public.embeddings ADD COLUMN thought_id bigint NOT NULL; END IF; END; $$; @@ -1120,422 +662,6 @@ BEGIN END; $$; -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'company' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN company text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'created_at' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN created_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'email' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN email text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'follow_up_date' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN follow_up_date date; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'how_we_met' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN how_we_met text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'id' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'last_contacted' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN last_contacted timestamptz; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'linkedin_url' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN linkedin_url text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'name' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN name text NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'notes' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN notes text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'phone' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN phone text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'tags' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN tags text[] NOT NULL DEFAULT '{}'; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'title' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN title text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND column_name = 'updated_at' - ) THEN - ALTER TABLE public.professional_contacts ADD COLUMN updated_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'contact_interactions' - AND column_name = 'contact_id' - ) THEN - ALTER TABLE public.contact_interactions ADD COLUMN contact_id uuid NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'contact_interactions' - AND column_name = 'created_at' - ) THEN - ALTER TABLE public.contact_interactions ADD COLUMN created_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'contact_interactions' - AND column_name = 'follow_up_needed' - ) THEN - ALTER TABLE public.contact_interactions ADD COLUMN follow_up_needed boolean NOT NULL DEFAULT false; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'contact_interactions' - AND column_name = 'follow_up_notes' - ) THEN - ALTER TABLE public.contact_interactions ADD COLUMN follow_up_notes text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'contact_interactions' - AND column_name = 'id' - ) THEN - ALTER TABLE public.contact_interactions ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'contact_interactions' - AND column_name = 'interaction_type' - ) THEN - ALTER TABLE public.contact_interactions ADD COLUMN interaction_type text NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'contact_interactions' - AND column_name = 'occurred_at' - ) THEN - ALTER TABLE public.contact_interactions ADD COLUMN occurred_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'contact_interactions' - AND column_name = 'summary' - ) THEN - ALTER TABLE public.contact_interactions ADD COLUMN summary text NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'opportunities' - AND column_name = 'contact_id' - ) THEN - ALTER TABLE public.opportunities ADD COLUMN contact_id uuid; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'opportunities' - AND column_name = 'created_at' - ) THEN - ALTER TABLE public.opportunities ADD COLUMN created_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'opportunities' - AND column_name = 'description' - ) THEN - ALTER TABLE public.opportunities ADD COLUMN description text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'opportunities' - AND column_name = 'expected_close_date' - ) THEN - ALTER TABLE public.opportunities ADD COLUMN expected_close_date date; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'opportunities' - AND column_name = 'id' - ) THEN - ALTER TABLE public.opportunities ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'opportunities' - AND column_name = 'notes' - ) THEN - ALTER TABLE public.opportunities ADD COLUMN notes text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'opportunities' - AND column_name = 'stage' - ) THEN - ALTER TABLE public.opportunities ADD COLUMN stage text NOT NULL DEFAULT 'identified'; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'opportunities' - AND column_name = 'title' - ) THEN - ALTER TABLE public.opportunities ADD COLUMN title text NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'opportunities' - AND column_name = 'updated_at' - ) THEN - ALTER TABLE public.opportunities ADD COLUMN updated_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'opportunities' - AND column_name = 'value' - ) THEN - ALTER TABLE public.opportunities ADD COLUMN value decimal(12,2); - END IF; -END; -$$; - DO $$ BEGIN IF NOT EXISTS ( @@ -1648,7 +774,7 @@ BEGIN AND table_name = 'stored_files' AND column_name = 'project_id' ) THEN - ALTER TABLE public.stored_files ADD COLUMN project_id uuid; + ALTER TABLE public.stored_files ADD COLUMN project_id bigint; END IF; END; $$; @@ -1687,7 +813,7 @@ BEGIN AND table_name = 'stored_files' AND column_name = 'thought_id' ) THEN - ALTER TABLE public.stored_files ADD COLUMN thought_id uuid; + ALTER TABLE public.stored_files ADD COLUMN thought_id bigint; END IF; END; $$; @@ -1705,825 +831,6 @@ BEGIN END; $$; -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_items' - AND column_name = 'category' - ) THEN - ALTER TABLE public.household_items ADD COLUMN category text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_items' - AND column_name = 'created_at' - ) THEN - ALTER TABLE public.household_items ADD COLUMN created_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_items' - AND column_name = 'details' - ) THEN - ALTER TABLE public.household_items ADD COLUMN details jsonb NOT NULL DEFAULT '{}'; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_items' - AND column_name = 'id' - ) THEN - ALTER TABLE public.household_items ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_items' - AND column_name = 'location' - ) THEN - ALTER TABLE public.household_items ADD COLUMN location text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_items' - AND column_name = 'name' - ) THEN - ALTER TABLE public.household_items ADD COLUMN name text NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_items' - AND column_name = 'notes' - ) THEN - ALTER TABLE public.household_items ADD COLUMN notes text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_items' - AND column_name = 'updated_at' - ) THEN - ALTER TABLE public.household_items ADD COLUMN updated_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_vendors' - AND column_name = 'created_at' - ) THEN - ALTER TABLE public.household_vendors ADD COLUMN created_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_vendors' - AND column_name = 'email' - ) THEN - ALTER TABLE public.household_vendors ADD COLUMN email text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_vendors' - AND column_name = 'id' - ) THEN - ALTER TABLE public.household_vendors ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_vendors' - AND column_name = 'last_used' - ) THEN - ALTER TABLE public.household_vendors ADD COLUMN last_used date; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_vendors' - AND column_name = 'name' - ) THEN - ALTER TABLE public.household_vendors ADD COLUMN name text NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_vendors' - AND column_name = 'notes' - ) THEN - ALTER TABLE public.household_vendors ADD COLUMN notes text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_vendors' - AND column_name = 'phone' - ) THEN - ALTER TABLE public.household_vendors ADD COLUMN phone text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_vendors' - AND column_name = 'rating' - ) THEN - ALTER TABLE public.household_vendors ADD COLUMN rating integer; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_vendors' - AND column_name = 'service_type' - ) THEN - ALTER TABLE public.household_vendors ADD COLUMN service_type text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'household_vendors' - AND column_name = 'website' - ) THEN - ALTER TABLE public.household_vendors ADD COLUMN website text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_tasks' - AND column_name = 'category' - ) THEN - ALTER TABLE public.maintenance_tasks ADD COLUMN category text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_tasks' - AND column_name = 'created_at' - ) THEN - ALTER TABLE public.maintenance_tasks ADD COLUMN created_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_tasks' - AND column_name = 'frequency_days' - ) THEN - ALTER TABLE public.maintenance_tasks ADD COLUMN frequency_days integer; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_tasks' - AND column_name = 'id' - ) THEN - ALTER TABLE public.maintenance_tasks ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_tasks' - AND column_name = 'last_completed' - ) THEN - ALTER TABLE public.maintenance_tasks ADD COLUMN last_completed timestamptz; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_tasks' - AND column_name = 'name' - ) THEN - ALTER TABLE public.maintenance_tasks ADD COLUMN name text NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_tasks' - AND column_name = 'next_due' - ) THEN - ALTER TABLE public.maintenance_tasks ADD COLUMN next_due timestamptz; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_tasks' - AND column_name = 'notes' - ) THEN - ALTER TABLE public.maintenance_tasks ADD COLUMN notes text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_tasks' - AND column_name = 'priority' - ) THEN - ALTER TABLE public.maintenance_tasks ADD COLUMN priority text NOT NULL DEFAULT 'medium'; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_tasks' - AND column_name = 'updated_at' - ) THEN - ALTER TABLE public.maintenance_tasks ADD COLUMN updated_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_logs' - AND column_name = 'completed_at' - ) THEN - ALTER TABLE public.maintenance_logs ADD COLUMN completed_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_logs' - AND column_name = 'cost' - ) THEN - ALTER TABLE public.maintenance_logs ADD COLUMN cost decimal(10,2); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_logs' - AND column_name = 'id' - ) THEN - ALTER TABLE public.maintenance_logs ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_logs' - AND column_name = 'next_action' - ) THEN - ALTER TABLE public.maintenance_logs ADD COLUMN next_action text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_logs' - AND column_name = 'notes' - ) THEN - ALTER TABLE public.maintenance_logs ADD COLUMN notes text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_logs' - AND column_name = 'performed_by' - ) THEN - ALTER TABLE public.maintenance_logs ADD COLUMN performed_by text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'maintenance_logs' - AND column_name = 'task_id' - ) THEN - ALTER TABLE public.maintenance_logs ADD COLUMN task_id uuid NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND column_name = 'cook_time_minutes' - ) THEN - ALTER TABLE public.recipes ADD COLUMN cook_time_minutes integer; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND column_name = 'created_at' - ) THEN - ALTER TABLE public.recipes ADD COLUMN created_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND column_name = 'cuisine' - ) THEN - ALTER TABLE public.recipes ADD COLUMN cuisine text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND column_name = 'id' - ) THEN - ALTER TABLE public.recipes ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND column_name = 'ingredients' - ) THEN - ALTER TABLE public.recipes ADD COLUMN ingredients jsonb NOT NULL DEFAULT '[]'; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND column_name = 'instructions' - ) THEN - ALTER TABLE public.recipes ADD COLUMN instructions jsonb NOT NULL DEFAULT '[]'; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND column_name = 'name' - ) THEN - ALTER TABLE public.recipes ADD COLUMN name text NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND column_name = 'notes' - ) THEN - ALTER TABLE public.recipes ADD COLUMN notes text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND column_name = 'prep_time_minutes' - ) THEN - ALTER TABLE public.recipes ADD COLUMN prep_time_minutes integer; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND column_name = 'rating' - ) THEN - ALTER TABLE public.recipes ADD COLUMN rating integer; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND column_name = 'servings' - ) THEN - ALTER TABLE public.recipes ADD COLUMN servings integer; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND column_name = 'tags' - ) THEN - ALTER TABLE public.recipes ADD COLUMN tags text[] NOT NULL DEFAULT '{}'; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND column_name = 'updated_at' - ) THEN - ALTER TABLE public.recipes ADD COLUMN updated_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'meal_plans' - AND column_name = 'created_at' - ) THEN - ALTER TABLE public.meal_plans ADD COLUMN created_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'meal_plans' - AND column_name = 'custom_meal' - ) THEN - ALTER TABLE public.meal_plans ADD COLUMN custom_meal text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'meal_plans' - AND column_name = 'day_of_week' - ) THEN - ALTER TABLE public.meal_plans ADD COLUMN day_of_week text NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'meal_plans' - AND column_name = 'id' - ) THEN - ALTER TABLE public.meal_plans ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'meal_plans' - AND column_name = 'meal_type' - ) THEN - ALTER TABLE public.meal_plans ADD COLUMN meal_type text NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'meal_plans' - AND column_name = 'notes' - ) THEN - ALTER TABLE public.meal_plans ADD COLUMN notes text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'meal_plans' - AND column_name = 'recipe_id' - ) THEN - ALTER TABLE public.meal_plans ADD COLUMN recipe_id uuid; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'meal_plans' - AND column_name = 'servings' - ) THEN - ALTER TABLE public.meal_plans ADD COLUMN servings integer; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'meal_plans' - AND column_name = 'week_start' - ) THEN - ALTER TABLE public.meal_plans ADD COLUMN week_start date NOT NULL; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'shopping_lists' - AND column_name = 'created_at' - ) THEN - ALTER TABLE public.shopping_lists ADD COLUMN created_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'shopping_lists' - AND column_name = 'id' - ) THEN - ALTER TABLE public.shopping_lists ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'shopping_lists' - AND column_name = 'items' - ) THEN - ALTER TABLE public.shopping_lists ADD COLUMN items jsonb NOT NULL DEFAULT '[]'; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'shopping_lists' - AND column_name = 'notes' - ) THEN - ALTER TABLE public.shopping_lists ADD COLUMN notes text; - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'shopping_lists' - AND column_name = 'updated_at' - ) THEN - ALTER TABLE public.shopping_lists ADD COLUMN updated_at timestamptz NOT NULL DEFAULT now(); - END IF; -END; -$$; - -DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'shopping_lists' - AND column_name = 'week_start' - ) THEN - ALTER TABLE public.shopping_lists ADD COLUMN week_start date NOT NULL; - END IF; -END; -$$; - DO $$ BEGIN IF NOT EXISTS ( @@ -2563,6 +870,19 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'chat_histories' + AND column_name = 'guid' + ) THEN + ALTER TABLE public.chat_histories ADD COLUMN guid uuid NOT NULL DEFAULT gen_random_uuid(); + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -2571,7 +891,7 @@ BEGIN AND table_name = 'chat_histories' AND column_name = 'id' ) THEN - ALTER TABLE public.chat_histories ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); + ALTER TABLE public.chat_histories ADD COLUMN id bigserial NOT NULL; END IF; END; $$; @@ -2584,7 +904,7 @@ BEGIN AND table_name = 'chat_histories' AND column_name = 'messages' ) THEN - ALTER TABLE public.chat_histories ADD COLUMN messages jsonb NOT NULL DEFAULT '[]'; + ALTER TABLE public.chat_histories ADD COLUMN messages jsonb NOT NULL DEFAULT '''['; END IF; END; $$; @@ -2597,7 +917,7 @@ BEGIN AND table_name = 'chat_histories' AND column_name = 'metadata' ) THEN - ALTER TABLE public.chat_histories ADD COLUMN metadata jsonb NOT NULL DEFAULT '{}'; + ALTER TABLE public.chat_histories ADD COLUMN metadata jsonb NOT NULL DEFAULT '''{}'''; END IF; END; $$; @@ -2610,7 +930,7 @@ BEGIN AND table_name = 'chat_histories' AND column_name = 'project_id' ) THEN - ALTER TABLE public.chat_histories ADD COLUMN project_id uuid; + ALTER TABLE public.chat_histories ADD COLUMN project_id bigint; END IF; END; $$; @@ -2818,7 +1138,20 @@ BEGIN AND table_name = 'learnings' AND column_name = 'duplicate_of_learning_id' ) THEN - ALTER TABLE public.learnings ADD COLUMN duplicate_of_learning_id uuid; + ALTER TABLE public.learnings ADD COLUMN duplicate_of_learning_id bigint; + END IF; +END; +$$; + +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'learnings' + AND column_name = 'guid' + ) THEN + ALTER TABLE public.learnings ADD COLUMN guid uuid NOT NULL DEFAULT gen_random_uuid(); END IF; END; $$; @@ -2831,7 +1164,7 @@ BEGIN AND table_name = 'learnings' AND column_name = 'id' ) THEN - ALTER TABLE public.learnings ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); + ALTER TABLE public.learnings ADD COLUMN id bigserial NOT NULL; END IF; END; $$; @@ -2857,7 +1190,7 @@ BEGIN AND table_name = 'learnings' AND column_name = 'project_id' ) THEN - ALTER TABLE public.learnings ADD COLUMN project_id uuid; + ALTER TABLE public.learnings ADD COLUMN project_id bigint; END IF; END; $$; @@ -2870,7 +1203,7 @@ BEGIN AND table_name = 'learnings' AND column_name = 'related_skill_id' ) THEN - ALTER TABLE public.learnings ADD COLUMN related_skill_id uuid; + ALTER TABLE public.learnings ADD COLUMN related_skill_id bigint; END IF; END; $$; @@ -2883,7 +1216,7 @@ BEGIN AND table_name = 'learnings' AND column_name = 'related_thought_id' ) THEN - ALTER TABLE public.learnings ADD COLUMN related_thought_id uuid; + ALTER TABLE public.learnings ADD COLUMN related_thought_id bigint; END IF; END; $$; @@ -2974,7 +1307,7 @@ BEGIN AND table_name = 'learnings' AND column_name = 'supersedes_learning_id' ) THEN - ALTER TABLE public.learnings ADD COLUMN supersedes_learning_id uuid; + ALTER TABLE public.learnings ADD COLUMN supersedes_learning_id bigint; END IF; END; $$; @@ -2987,7 +1320,7 @@ BEGIN AND table_name = 'learnings' AND column_name = 'tags' ) THEN - ALTER TABLE public.learnings ADD COLUMN tags text[] NOT NULL DEFAULT '{}'; + ALTER TABLE public.learnings ADD COLUMN tags text; END IF; END; $$; @@ -3057,6 +1390,19 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'plans' + AND column_name = 'guid' + ) THEN + ALTER TABLE public.plans ADD COLUMN guid uuid NOT NULL DEFAULT gen_random_uuid(); + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -3065,7 +1411,7 @@ BEGIN AND table_name = 'plans' AND column_name = 'id' ) THEN - ALTER TABLE public.plans ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); + ALTER TABLE public.plans ADD COLUMN id bigserial NOT NULL; END IF; END; $$; @@ -3117,7 +1463,7 @@ BEGIN AND table_name = 'plans' AND column_name = 'project_id' ) THEN - ALTER TABLE public.plans ADD COLUMN project_id uuid; + ALTER TABLE public.plans ADD COLUMN project_id bigint; END IF; END; $$; @@ -3156,7 +1502,7 @@ BEGIN AND table_name = 'plans' AND column_name = 'supersedes_plan_id' ) THEN - ALTER TABLE public.plans ADD COLUMN supersedes_plan_id uuid; + ALTER TABLE public.plans ADD COLUMN supersedes_plan_id bigint; END IF; END; $$; @@ -3169,7 +1515,7 @@ BEGIN AND table_name = 'plans' AND column_name = 'tags' ) THEN - ALTER TABLE public.plans ADD COLUMN tags text[] NOT NULL DEFAULT '{}'; + ALTER TABLE public.plans ADD COLUMN tags text; END IF; END; $$; @@ -3221,7 +1567,7 @@ BEGIN AND table_name = 'plan_dependencies' AND column_name = 'depends_on_plan_id' ) THEN - ALTER TABLE public.plan_dependencies ADD COLUMN depends_on_plan_id uuid NOT NULL; + ALTER TABLE public.plan_dependencies ADD COLUMN depends_on_plan_id bigint NOT NULL; END IF; END; $$; @@ -3234,7 +1580,7 @@ BEGIN AND table_name = 'plan_dependencies' AND column_name = 'id' ) THEN - ALTER TABLE public.plan_dependencies ADD COLUMN id serial NOT NULL; + ALTER TABLE public.plan_dependencies ADD COLUMN id bigserial NOT NULL; END IF; END; $$; @@ -3247,7 +1593,7 @@ BEGIN AND table_name = 'plan_dependencies' AND column_name = 'plan_id' ) THEN - ALTER TABLE public.plan_dependencies ADD COLUMN plan_id uuid NOT NULL; + ALTER TABLE public.plan_dependencies ADD COLUMN plan_id bigint NOT NULL; END IF; END; $$; @@ -3273,7 +1619,7 @@ BEGIN AND table_name = 'plan_related_plans' AND column_name = 'id' ) THEN - ALTER TABLE public.plan_related_plans ADD COLUMN id serial NOT NULL; + ALTER TABLE public.plan_related_plans ADD COLUMN id bigserial NOT NULL; END IF; END; $$; @@ -3286,7 +1632,7 @@ BEGIN AND table_name = 'plan_related_plans' AND column_name = 'plan_a_id' ) THEN - ALTER TABLE public.plan_related_plans ADD COLUMN plan_a_id uuid NOT NULL; + ALTER TABLE public.plan_related_plans ADD COLUMN plan_a_id bigint NOT NULL; END IF; END; $$; @@ -3299,7 +1645,7 @@ BEGIN AND table_name = 'plan_related_plans' AND column_name = 'plan_b_id' ) THEN - ALTER TABLE public.plan_related_plans ADD COLUMN plan_b_id uuid NOT NULL; + ALTER TABLE public.plan_related_plans ADD COLUMN plan_b_id bigint NOT NULL; END IF; END; $$; @@ -3325,7 +1671,7 @@ BEGIN AND table_name = 'plan_skills' AND column_name = 'id' ) THEN - ALTER TABLE public.plan_skills ADD COLUMN id serial NOT NULL; + ALTER TABLE public.plan_skills ADD COLUMN id bigserial NOT NULL; END IF; END; $$; @@ -3338,7 +1684,7 @@ BEGIN AND table_name = 'plan_skills' AND column_name = 'plan_id' ) THEN - ALTER TABLE public.plan_skills ADD COLUMN plan_id uuid NOT NULL; + ALTER TABLE public.plan_skills ADD COLUMN plan_id bigint NOT NULL; END IF; END; $$; @@ -3351,7 +1697,7 @@ BEGIN AND table_name = 'plan_skills' AND column_name = 'skill_id' ) THEN - ALTER TABLE public.plan_skills ADD COLUMN skill_id uuid NOT NULL; + ALTER TABLE public.plan_skills ADD COLUMN skill_id bigint NOT NULL; END IF; END; $$; @@ -3377,7 +1723,7 @@ BEGIN AND table_name = 'plan_guardrails' AND column_name = 'guardrail_id' ) THEN - ALTER TABLE public.plan_guardrails ADD COLUMN guardrail_id uuid NOT NULL; + ALTER TABLE public.plan_guardrails ADD COLUMN guardrail_id bigint NOT NULL; END IF; END; $$; @@ -3390,7 +1736,7 @@ BEGIN AND table_name = 'plan_guardrails' AND column_name = 'id' ) THEN - ALTER TABLE public.plan_guardrails ADD COLUMN id serial NOT NULL; + ALTER TABLE public.plan_guardrails ADD COLUMN id bigserial NOT NULL; END IF; END; $$; @@ -3403,7 +1749,7 @@ BEGIN AND table_name = 'plan_guardrails' AND column_name = 'plan_id' ) THEN - ALTER TABLE public.plan_guardrails ADD COLUMN plan_id uuid NOT NULL; + ALTER TABLE public.plan_guardrails ADD COLUMN plan_id bigint NOT NULL; END IF; END; $$; @@ -3447,6 +1793,19 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'agent_skills' + AND column_name = 'guid' + ) THEN + ALTER TABLE public.agent_skills ADD COLUMN guid uuid NOT NULL DEFAULT gen_random_uuid(); + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -3455,7 +1814,7 @@ BEGIN AND table_name = 'agent_skills' AND column_name = 'id' ) THEN - ALTER TABLE public.agent_skills ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); + ALTER TABLE public.agent_skills ADD COLUMN id bigserial NOT NULL; END IF; END; $$; @@ -3481,7 +1840,7 @@ BEGIN AND table_name = 'agent_skills' AND column_name = 'tags' ) THEN - ALTER TABLE public.agent_skills ADD COLUMN tags text[] NOT NULL DEFAULT '{}'; + ALTER TABLE public.agent_skills ADD COLUMN tags text; END IF; END; $$; @@ -3538,6 +1897,19 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'agent_guardrails' + AND column_name = 'guid' + ) THEN + ALTER TABLE public.agent_guardrails ADD COLUMN guid uuid NOT NULL DEFAULT gen_random_uuid(); + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -3546,7 +1918,7 @@ BEGIN AND table_name = 'agent_guardrails' AND column_name = 'id' ) THEN - ALTER TABLE public.agent_guardrails ADD COLUMN id uuid NOT NULL DEFAULT gen_random_uuid(); + ALTER TABLE public.agent_guardrails ADD COLUMN id bigserial NOT NULL; END IF; END; $$; @@ -3585,7 +1957,7 @@ BEGIN AND table_name = 'agent_guardrails' AND column_name = 'tags' ) THEN - ALTER TABLE public.agent_guardrails ADD COLUMN tags text[] NOT NULL DEFAULT '{}'; + ALTER TABLE public.agent_guardrails ADD COLUMN tags text; END IF; END; $$; @@ -3624,7 +1996,7 @@ BEGIN AND table_name = 'project_skills' AND column_name = 'id' ) THEN - ALTER TABLE public.project_skills ADD COLUMN id serial NOT NULL; + ALTER TABLE public.project_skills ADD COLUMN id bigserial NOT NULL; END IF; END; $$; @@ -3637,7 +2009,7 @@ BEGIN AND table_name = 'project_skills' AND column_name = 'project_id' ) THEN - ALTER TABLE public.project_skills ADD COLUMN project_id uuid NOT NULL; + ALTER TABLE public.project_skills ADD COLUMN project_id bigint NOT NULL; END IF; END; $$; @@ -3650,7 +2022,7 @@ BEGIN AND table_name = 'project_skills' AND column_name = 'skill_id' ) THEN - ALTER TABLE public.project_skills ADD COLUMN skill_id uuid NOT NULL; + ALTER TABLE public.project_skills ADD COLUMN skill_id bigint NOT NULL; END IF; END; $$; @@ -3676,7 +2048,7 @@ BEGIN AND table_name = 'project_guardrails' AND column_name = 'guardrail_id' ) THEN - ALTER TABLE public.project_guardrails ADD COLUMN guardrail_id uuid NOT NULL; + ALTER TABLE public.project_guardrails ADD COLUMN guardrail_id bigint NOT NULL; END IF; END; $$; @@ -3689,7 +2061,7 @@ BEGIN AND table_name = 'project_guardrails' AND column_name = 'id' ) THEN - ALTER TABLE public.project_guardrails ADD COLUMN id serial NOT NULL; + ALTER TABLE public.project_guardrails ADD COLUMN id bigserial NOT NULL; END IF; END; $$; @@ -3702,96 +2074,12 @@ BEGIN AND table_name = 'project_guardrails' AND column_name = 'project_id' ) THEN - ALTER TABLE public.project_guardrails ADD COLUMN project_id uuid NOT NULL; + ALTER TABLE public.project_guardrails ADD COLUMN project_id bigint NOT NULL; END IF; END; $$; -- Primary keys for schema: public -DO $$ -DECLARE - auto_pk_name text; -BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'family_members' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('family_members_pkey', 'public_family_members_pkey'); - - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.family_members DROP CONSTRAINT ' || quote_ident(auto_pk_name); - END IF; - - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'family_members' - AND constraint_name = 'pk_public_family_members' - ) THEN - ALTER TABLE public.family_members ADD CONSTRAINT pk_public_family_members PRIMARY KEY (id); - END IF; -END; -$$; - -DO $$ -DECLARE - auto_pk_name text; -BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'activities' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('activities_pkey', 'public_activities_pkey'); - - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.activities DROP CONSTRAINT ' || quote_ident(auto_pk_name); - END IF; - - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'activities' - AND constraint_name = 'pk_public_activities' - ) THEN - ALTER TABLE public.activities ADD CONSTRAINT pk_public_activities PRIMARY KEY (id); - END IF; -END; -$$; - -DO $$ -DECLARE - auto_pk_name text; -BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'important_dates' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('important_dates_pkey', 'public_important_dates_pkey'); - - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.important_dates DROP CONSTRAINT ' || quote_ident(auto_pk_name); - END IF; - - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'important_dates' - AND constraint_name = 'pk_public_important_dates' - ) THEN - ALTER TABLE public.important_dates ADD CONSTRAINT pk_public_important_dates PRIMARY KEY (id); - END IF; -END; -$$; - DO $$ DECLARE auto_pk_name text; @@ -3904,90 +2192,6 @@ BEGIN END; $$; -DO $$ -DECLARE - auto_pk_name text; -BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('professional_contacts_pkey', 'public_professional_contacts_pkey'); - - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.professional_contacts DROP CONSTRAINT ' || quote_ident(auto_pk_name); - END IF; - - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'professional_contacts' - AND constraint_name = 'pk_public_professional_contacts' - ) THEN - ALTER TABLE public.professional_contacts ADD CONSTRAINT pk_public_professional_contacts PRIMARY KEY (id); - END IF; -END; -$$; - -DO $$ -DECLARE - auto_pk_name text; -BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'contact_interactions' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('contact_interactions_pkey', 'public_contact_interactions_pkey'); - - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.contact_interactions DROP CONSTRAINT ' || quote_ident(auto_pk_name); - END IF; - - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'contact_interactions' - AND constraint_name = 'pk_public_contact_interactions' - ) THEN - ALTER TABLE public.contact_interactions ADD CONSTRAINT pk_public_contact_interactions PRIMARY KEY (id); - END IF; -END; -$$; - -DO $$ -DECLARE - auto_pk_name text; -BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'opportunities' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('opportunities_pkey', 'public_opportunities_pkey'); - - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.opportunities DROP CONSTRAINT ' || quote_ident(auto_pk_name); - END IF; - - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'opportunities' - AND constraint_name = 'pk_public_opportunities' - ) THEN - ALTER TABLE public.opportunities ADD CONSTRAINT pk_public_opportunities PRIMARY KEY (id); - END IF; -END; -$$; - DO $$ DECLARE auto_pk_name text; @@ -4016,202 +2220,6 @@ BEGIN END; $$; -DO $$ -DECLARE - auto_pk_name text; -BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'household_items' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('household_items_pkey', 'public_household_items_pkey'); - - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.household_items DROP CONSTRAINT ' || quote_ident(auto_pk_name); - END IF; - - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'household_items' - AND constraint_name = 'pk_public_household_items' - ) THEN - ALTER TABLE public.household_items ADD CONSTRAINT pk_public_household_items PRIMARY KEY (id); - END IF; -END; -$$; - -DO $$ -DECLARE - auto_pk_name text; -BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'household_vendors' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('household_vendors_pkey', 'public_household_vendors_pkey'); - - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.household_vendors DROP CONSTRAINT ' || quote_ident(auto_pk_name); - END IF; - - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'household_vendors' - AND constraint_name = 'pk_public_household_vendors' - ) THEN - ALTER TABLE public.household_vendors ADD CONSTRAINT pk_public_household_vendors PRIMARY KEY (id); - END IF; -END; -$$; - -DO $$ -DECLARE - auto_pk_name text; -BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'maintenance_tasks' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('maintenance_tasks_pkey', 'public_maintenance_tasks_pkey'); - - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.maintenance_tasks DROP CONSTRAINT ' || quote_ident(auto_pk_name); - END IF; - - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'maintenance_tasks' - AND constraint_name = 'pk_public_maintenance_tasks' - ) THEN - ALTER TABLE public.maintenance_tasks ADD CONSTRAINT pk_public_maintenance_tasks PRIMARY KEY (id); - END IF; -END; -$$; - -DO $$ -DECLARE - auto_pk_name text; -BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'maintenance_logs' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('maintenance_logs_pkey', 'public_maintenance_logs_pkey'); - - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.maintenance_logs DROP CONSTRAINT ' || quote_ident(auto_pk_name); - END IF; - - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'maintenance_logs' - AND constraint_name = 'pk_public_maintenance_logs' - ) THEN - ALTER TABLE public.maintenance_logs ADD CONSTRAINT pk_public_maintenance_logs PRIMARY KEY (id); - END IF; -END; -$$; - -DO $$ -DECLARE - auto_pk_name text; -BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('recipes_pkey', 'public_recipes_pkey'); - - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.recipes DROP CONSTRAINT ' || quote_ident(auto_pk_name); - END IF; - - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'recipes' - AND constraint_name = 'pk_public_recipes' - ) THEN - ALTER TABLE public.recipes ADD CONSTRAINT pk_public_recipes PRIMARY KEY (id); - END IF; -END; -$$; - -DO $$ -DECLARE - auto_pk_name text; -BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'meal_plans' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('meal_plans_pkey', 'public_meal_plans_pkey'); - - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.meal_plans DROP CONSTRAINT ' || quote_ident(auto_pk_name); - END IF; - - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'meal_plans' - AND constraint_name = 'pk_public_meal_plans' - ) THEN - ALTER TABLE public.meal_plans ADD CONSTRAINT pk_public_meal_plans PRIMARY KEY (id); - END IF; -END; -$$; - -DO $$ -DECLARE - auto_pk_name text; -BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'shopping_lists' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('shopping_lists_pkey', 'public_shopping_lists_pkey'); - - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.shopping_lists DROP CONSTRAINT ' || quote_ident(auto_pk_name); - END IF; - - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'shopping_lists' - AND constraint_name = 'pk_public_shopping_lists' - ) THEN - ALTER TABLE public.shopping_lists ADD CONSTRAINT pk_public_shopping_lists PRIMARY KEY (id); - END IF; -END; -$$; - DO $$ DECLARE auto_pk_name text; @@ -4549,21 +2557,12 @@ END; $$; -- Indexes for schema: public -CREATE INDEX IF NOT EXISTS idx_activities_start_date_end_date - ON public.activities USING btree (start_date, end_date); - CREATE INDEX IF NOT EXISTS idx_thought_links_from_id_to_id_relation ON public.thought_links USING btree (from_id, to_id, relation); CREATE UNIQUE INDEX IF NOT EXISTS uidx_embeddings_thought_id_model ON public.embeddings USING btree (thought_id, model); -CREATE INDEX IF NOT EXISTS idx_contact_interactions_contact_id_occurred_at - ON public.contact_interactions USING btree (contact_id, occurred_at); - -CREATE INDEX IF NOT EXISTS idx_maintenance_logs_task_id_completed_at - ON public.maintenance_logs USING btree (task_id, completed_at); - CREATE INDEX IF NOT EXISTS idx_learnings_details ON public.learnings USING gin (details gin_trgm_ops); @@ -4574,7 +2573,7 @@ CREATE INDEX IF NOT EXISTS idx_learnings_tags ON public.learnings USING gin (tags gin_trgm_ops); CREATE INDEX IF NOT EXISTS idx_plans_tags - ON public.plans USING gin (tags); + ON public.plans USING gin (tags gin_trgm_ops); CREATE INDEX IF NOT EXISTS idx_plans_title ON public.plans USING gin (title gin_trgm_ops); @@ -4668,10 +2667,10 @@ BEGIN IF NOT EXISTS ( SELECT 1 FROM information_schema.table_constraints WHERE table_schema = 'public' - AND table_name = 'shopping_lists' - AND constraint_name = 'ukey_shopping_lists_week_start' + AND table_name = 'chat_histories' + AND constraint_name = 'ukey_chat_histories_guid' ) THEN - ALTER TABLE public.shopping_lists ADD CONSTRAINT ukey_shopping_lists_week_start UNIQUE (week_start); + ALTER TABLE public.chat_histories ADD CONSTRAINT ukey_chat_histories_guid UNIQUE (guid); END IF; END; $$; @@ -4689,6 +2688,45 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.table_constraints + WHERE table_schema = 'public' + AND table_name = 'learnings' + AND constraint_name = 'ukey_learnings_guid' + ) THEN + ALTER TABLE public.learnings ADD CONSTRAINT ukey_learnings_guid UNIQUE (guid); + END IF; +END; +$$; + +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.table_constraints + WHERE table_schema = 'public' + AND table_name = 'plans' + AND constraint_name = 'ukey_plans_guid' + ) THEN + ALTER TABLE public.plans ADD CONSTRAINT ukey_plans_guid UNIQUE (guid); + END IF; +END; +$$; + +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.table_constraints + WHERE table_schema = 'public' + AND table_name = 'agent_skills' + AND constraint_name = 'ukey_agent_skills_guid' + ) THEN + ALTER TABLE public.agent_skills ADD CONSTRAINT ukey_agent_skills_guid UNIQUE (guid); + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -4702,6 +2740,19 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.table_constraints + WHERE table_schema = 'public' + AND table_name = 'agent_guardrails' + AND constraint_name = 'ukey_agent_guardrails_guid' + ) THEN + ALTER TABLE public.agent_guardrails ADD CONSTRAINT ukey_agent_guardrails_guid UNIQUE (guid); + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -4718,38 +2769,6 @@ $$; -- Check constraints for schema: public -- Foreign keys for schema: public DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'activities' - AND constraint_name = 'fk_activities_family_member_id' - ) THEN - ALTER TABLE public.activities - ADD CONSTRAINT fk_activities_family_member_id - FOREIGN KEY (family_member_id) - REFERENCES public.family_members (id) - ON DELETE NO ACTION - ON UPDATE NO ACTION; - END IF; -END; -$$;DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'important_dates' - AND constraint_name = 'fk_important_dates_family_member_id' - ) THEN - ALTER TABLE public.important_dates - ADD CONSTRAINT fk_important_dates_family_member_id - FOREIGN KEY (family_member_id) - REFERENCES public.family_members (id) - ON DELETE NO ACTION - ON UPDATE NO ACTION; - END IF; -END; -$$;DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM information_schema.table_constraints @@ -4760,7 +2779,7 @@ BEGIN ALTER TABLE public.thoughts ADD CONSTRAINT fk_thoughts_project_id FOREIGN KEY (project_id) - REFERENCES public.projects (guid) + REFERENCES public.projects (id) ON DELETE NO ACTION ON UPDATE NO ACTION; END IF; @@ -4808,39 +2827,7 @@ BEGIN ALTER TABLE public.embeddings ADD CONSTRAINT fk_embeddings_thought_id FOREIGN KEY (thought_id) - REFERENCES public.thoughts (guid) - ON DELETE NO ACTION - ON UPDATE NO ACTION; - END IF; -END; -$$;DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'contact_interactions' - AND constraint_name = 'fk_contact_interactions_contact_id' - ) THEN - ALTER TABLE public.contact_interactions - ADD CONSTRAINT fk_contact_interactions_contact_id - FOREIGN KEY (contact_id) - REFERENCES public.professional_contacts (id) - ON DELETE NO ACTION - ON UPDATE NO ACTION; - END IF; -END; -$$;DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'opportunities' - AND constraint_name = 'fk_opportunities_contact_id' - ) THEN - ALTER TABLE public.opportunities - ADD CONSTRAINT fk_opportunities_contact_id - FOREIGN KEY (contact_id) - REFERENCES public.professional_contacts (id) + REFERENCES public.thoughts (id) ON DELETE NO ACTION ON UPDATE NO ACTION; END IF; @@ -4856,7 +2843,7 @@ BEGIN ALTER TABLE public.stored_files ADD CONSTRAINT fk_stored_files_project_id FOREIGN KEY (project_id) - REFERENCES public.projects (guid) + REFERENCES public.projects (id) ON DELETE NO ACTION ON UPDATE NO ACTION; END IF; @@ -4872,39 +2859,7 @@ BEGIN ALTER TABLE public.stored_files ADD CONSTRAINT fk_stored_files_thought_id FOREIGN KEY (thought_id) - REFERENCES public.thoughts (guid) - ON DELETE NO ACTION - ON UPDATE NO ACTION; - END IF; -END; -$$;DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'maintenance_logs' - AND constraint_name = 'fk_maintenance_logs_task_id' - ) THEN - ALTER TABLE public.maintenance_logs - ADD CONSTRAINT fk_maintenance_logs_task_id - FOREIGN KEY (task_id) - REFERENCES public.maintenance_tasks (id) - ON DELETE NO ACTION - ON UPDATE NO ACTION; - END IF; -END; -$$;DO $$ -BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'meal_plans' - AND constraint_name = 'fk_meal_plans_recipe_id' - ) THEN - ALTER TABLE public.meal_plans - ADD CONSTRAINT fk_meal_plans_recipe_id - FOREIGN KEY (recipe_id) - REFERENCES public.recipes (id) + REFERENCES public.thoughts (id) ON DELETE NO ACTION ON UPDATE NO ACTION; END IF; @@ -4920,7 +2875,7 @@ BEGIN ALTER TABLE public.chat_histories ADD CONSTRAINT fk_chat_histories_project_id FOREIGN KEY (project_id) - REFERENCES public.projects (guid) + REFERENCES public.projects (id) ON DELETE NO ACTION ON UPDATE NO ACTION; END IF; @@ -4952,7 +2907,7 @@ BEGIN ALTER TABLE public.learnings ADD CONSTRAINT fk_learnings_project_id FOREIGN KEY (project_id) - REFERENCES public.projects (guid) + REFERENCES public.projects (id) ON DELETE NO ACTION ON UPDATE NO ACTION; END IF; @@ -4984,7 +2939,7 @@ BEGIN ALTER TABLE public.learnings ADD CONSTRAINT fk_learnings_related_thought_id FOREIGN KEY (related_thought_id) - REFERENCES public.thoughts (guid) + REFERENCES public.thoughts (id) ON DELETE NO ACTION ON UPDATE NO ACTION; END IF; @@ -5016,7 +2971,7 @@ BEGIN ALTER TABLE public.plans ADD CONSTRAINT fk_plans_project_id FOREIGN KEY (project_id) - REFERENCES public.projects (guid) + REFERENCES public.projects (id) ON DELETE NO ACTION ON UPDATE NO ACTION; END IF; @@ -5176,7 +3131,7 @@ BEGIN ALTER TABLE public.project_skills ADD CONSTRAINT fk_project_skills_project_id FOREIGN KEY (project_id) - REFERENCES public.projects (guid) + REFERENCES public.projects (id) ON DELETE NO ACTION ON UPDATE NO ACTION; END IF; @@ -5224,7 +3179,7 @@ BEGIN ALTER TABLE public.project_guardrails ADD CONSTRAINT fk_project_guardrails_project_id FOREIGN KEY (project_id) - REFERENCES public.projects (guid) + REFERENCES public.projects (id) ON DELETE NO ACTION ON UPDATE NO ACTION; END IF; @@ -5326,6 +3281,25 @@ BEGIN END; $$; DO $$ +DECLARE + m_cnt bigint; +BEGIN + IF EXISTS ( + SELECT 1 FROM pg_class c + INNER JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE c.relname = 'identity_chat_histories_id' + AND n.nspname = 'public' + AND c.relkind = 'S' + ) THEN + SELECT COALESCE(MAX(id), 0) + 1 + FROM public.chat_histories + INTO m_cnt; + + PERFORM setval('public.identity_chat_histories_id'::regclass, m_cnt); + END IF; +END; +$$; +DO $$ DECLARE m_cnt bigint; BEGIN @@ -5345,6 +3319,44 @@ BEGIN END; $$; DO $$ +DECLARE + m_cnt bigint; +BEGIN + IF EXISTS ( + SELECT 1 FROM pg_class c + INNER JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE c.relname = 'identity_learnings_id' + AND n.nspname = 'public' + AND c.relkind = 'S' + ) THEN + SELECT COALESCE(MAX(id), 0) + 1 + FROM public.learnings + INTO m_cnt; + + PERFORM setval('public.identity_learnings_id'::regclass, m_cnt); + END IF; +END; +$$; +DO $$ +DECLARE + m_cnt bigint; +BEGIN + IF EXISTS ( + SELECT 1 FROM pg_class c + INNER JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE c.relname = 'identity_plans_id' + AND n.nspname = 'public' + AND c.relkind = 'S' + ) THEN + SELECT COALESCE(MAX(id), 0) + 1 + FROM public.plans + INTO m_cnt; + + PERFORM setval('public.identity_plans_id'::regclass, m_cnt); + END IF; +END; +$$; +DO $$ DECLARE m_cnt bigint; BEGIN @@ -5421,6 +3433,44 @@ BEGIN END; $$; DO $$ +DECLARE + m_cnt bigint; +BEGIN + IF EXISTS ( + SELECT 1 FROM pg_class c + INNER JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE c.relname = 'identity_agent_skills_id' + AND n.nspname = 'public' + AND c.relkind = 'S' + ) THEN + SELECT COALESCE(MAX(id), 0) + 1 + FROM public.agent_skills + INTO m_cnt; + + PERFORM setval('public.identity_agent_skills_id'::regclass, m_cnt); + END IF; +END; +$$; +DO $$ +DECLARE + m_cnt bigint; +BEGIN + IF EXISTS ( + SELECT 1 FROM pg_class c + INNER JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE c.relname = 'identity_agent_guardrails_id' + AND n.nspname = 'public' + AND c.relkind = 'S' + ) THEN + SELECT COALESCE(MAX(id), 0) + 1 + FROM public.agent_guardrails + INTO m_cnt; + + PERFORM setval('public.identity_agent_guardrails_id'::regclass, m_cnt); + END IF; +END; +$$; +DO $$ DECLARE m_cnt bigint; BEGIN @@ -5469,19 +3519,6 @@ $$; - - - - - - - - - - - - - diff --git a/schema/core.dbml b/schema/core.dbml index 70ef5c1..c44f6c0 100644 --- a/schema/core.dbml +++ b/schema/core.dbml @@ -5,7 +5,7 @@ Table thoughts { metadata jsonb [default: `'{}'::jsonb`] created_at timestamptz [default: `now()`] updated_at timestamptz [default: `now()`] - project_id uuid [ref: > projects.guid] + project_id bigint [ref: > projects.id] archived_at timestamptz } @@ -19,7 +19,7 @@ Table projects { } Table thought_links { - id serial [pk] + id bigserial [pk] from_id bigint [not null, ref: > thoughts.id] to_id bigint [not null, ref: > thoughts.id] relation text [not null] @@ -35,7 +35,7 @@ Table thought_links { Table embeddings { id bigserial [pk] guid uuid [unique, not null, default: `gen_random_uuid()`] - thought_id uuid [not null, ref: > thoughts.guid] + thought_id bigint [not null, ref: > thoughts.id] model text [not null] dim int [not null] embedding vector [not null] diff --git a/schema/files.dbml b/schema/files.dbml index 74062fd..8df0d13 100644 --- a/schema/files.dbml +++ b/schema/files.dbml @@ -1,8 +1,8 @@ Table stored_files { id bigserial [pk] guid uuid [unique, not null, default: `gen_random_uuid()`] - thought_id uuid [ref: > thoughts.guid] - project_id uuid [ref: > projects.guid] + thought_id bigint [ref: > thoughts.id] + project_id bigint [ref: > projects.id] name text [not null] media_type text [not null] kind text [not null, default: 'file'] @@ -21,5 +21,5 @@ Table stored_files { } // Cross-file refs (for relspecgo merge) -Ref: stored_files.thought_id > thoughts.guid [delete: set null] -Ref: stored_files.project_id > projects.guid [delete: set null] +Ref: stored_files.thought_id > thoughts.id [delete: set null] +Ref: stored_files.project_id > projects.id [delete: set null] diff --git a/schema/meta.dbml b/schema/meta.dbml index f83200d..5945e10 100644 --- a/schema/meta.dbml +++ b/schema/meta.dbml @@ -1,10 +1,11 @@ Table chat_histories { - id uuid [pk, default: `gen_random_uuid()`] + id bigserial [pk] + guid uuid [unique, not null, default: `gen_random_uuid()`] session_id text [not null] title text channel text agent_id text - project_id uuid [ref: > projects.guid] + project_id bigint [ref: > projects.id] messages jsonb [not null, default: `'[]'`] summary text metadata jsonb [not null, default: `'{}'`] @@ -29,10 +30,11 @@ Table tool_annotations { } // Cross-file refs (for relspecgo merge) -Ref: chat_histories.project_id > projects.guid [delete: set null] +Ref: chat_histories.project_id > projects.id [delete: set null] Table learnings { - id uuid [pk, default: `gen_random_uuid()`] + id bigserial [pk] + guid uuid [unique, not null, default: `gen_random_uuid()`] summary text [not null] details text [not null, default: ''] category text [not null, default: 'insight'] @@ -43,13 +45,13 @@ Table learnings { action_required boolean [not null, default: false] source_type text source_ref text - project_id uuid [ref: > projects.guid] - related_thought_id uuid [ref: > thoughts.guid] - related_skill_id uuid [ref: > agent_skills.id] + project_id bigint [ref: > projects.id] + related_thought_id bigint [ref: > thoughts.id] + related_skill_id bigint [ref: > agent_skills.id] reviewed_by text reviewed_at timestamptz - duplicate_of_learning_id uuid [ref: > learnings.id] - supersedes_learning_id uuid [ref: > learnings.id] + duplicate_of_learning_id bigint [ref: > learnings.id] + supersedes_learning_id bigint [ref: > learnings.id] tags "text[]" [not null, default: `'{}'`] created_at timestamptz [not null, default: `now()`] updated_at timestamptz [not null, default: `now()`] @@ -68,8 +70,8 @@ Table learnings { } // Cross-file refs (for relspecgo merge) -Ref: learnings.project_id > projects.guid [delete: set null] -Ref: learnings.related_thought_id > thoughts.guid [delete: set null] +Ref: learnings.project_id > projects.id [delete: set null] +Ref: learnings.related_thought_id > thoughts.id [delete: set null] Ref: learnings.related_skill_id > agent_skills.id [delete: set null] Ref: learnings.duplicate_of_learning_id > learnings.id [delete: set null] Ref: learnings.supersedes_learning_id > learnings.id [delete: set null] diff --git a/schema/plans.dbml b/schema/plans.dbml index f886b82..3e658f9 100644 --- a/schema/plans.dbml +++ b/schema/plans.dbml @@ -1,16 +1,17 @@ Table plans { - id uuid [pk, default: `gen_random_uuid()`] + id bigserial [pk] + guid uuid [unique, not null, default: `gen_random_uuid()`] title text [not null] description text [not null, default: ''] status text [not null, default: 'draft'] // draft, active, blocked, completed, cancelled, superseded priority text [not null, default: 'medium'] // low, medium, high, critical - project_id uuid [ref: > projects.guid] + project_id bigint [ref: > projects.id] owner text due_date timestamptz completed_at timestamptz reviewed_by text last_reviewed_at timestamptz - supersedes_plan_id uuid [ref: > plans.id] + supersedes_plan_id bigint [ref: > plans.id] tags "text[]" [not null, default: `'{}'`] created_at timestamptz [not null, default: `now()`] updated_at timestamptz [not null, default: `now()`] @@ -29,9 +30,9 @@ Table plans { // Directional: plan_id cannot proceed until depends_on_plan_id is complete Table plan_dependencies { - id serial [pk] - plan_id uuid [not null, ref: > plans.id] - depends_on_plan_id uuid [not null, ref: > plans.id] + id bigserial [pk] + plan_id bigint [not null, ref: > plans.id] + depends_on_plan_id bigint [not null, ref: > plans.id] created_at timestamptz [not null, default: `now()`] indexes { @@ -43,9 +44,9 @@ Table plan_dependencies { // Bidirectional: store with plan_a_id < plan_b_id to avoid duplicates Table plan_related_plans { - id serial [pk] - plan_a_id uuid [not null, ref: > plans.id] - plan_b_id uuid [not null, ref: > plans.id] + id bigserial [pk] + plan_a_id bigint [not null, ref: > plans.id] + plan_b_id bigint [not null, ref: > plans.id] created_at timestamptz [not null, default: `now()`] indexes { @@ -56,9 +57,9 @@ Table plan_related_plans { } Table plan_skills { - id serial [pk] - plan_id uuid [not null, ref: > plans.id] - skill_id uuid [not null, ref: > agent_skills.id] + id bigserial [pk] + plan_id bigint [not null, ref: > plans.id] + skill_id bigint [not null, ref: > agent_skills.id] created_at timestamptz [not null, default: `now()`] indexes { @@ -68,9 +69,9 @@ Table plan_skills { } Table plan_guardrails { - id serial [pk] - plan_id uuid [not null, ref: > plans.id] - guardrail_id uuid [not null, ref: > agent_guardrails.id] + id bigserial [pk] + plan_id bigint [not null, ref: > plans.id] + guardrail_id bigint [not null, ref: > agent_guardrails.id] created_at timestamptz [not null, default: `now()`] indexes { @@ -80,7 +81,7 @@ Table plan_guardrails { } // Cross-file refs (for relspecgo merge) -Ref: plans.project_id > projects.guid [delete: set null] +Ref: plans.project_id > projects.id [delete: set null] Ref: plans.supersedes_plan_id > plans.id [delete: set null] Ref: plan_dependencies.plan_id > plans.id [delete: cascade] Ref: plan_dependencies.depends_on_plan_id > plans.id [delete: cascade] diff --git a/schema/skills.dbml b/schema/skills.dbml index d23247a..725cbea 100644 --- a/schema/skills.dbml +++ b/schema/skills.dbml @@ -1,5 +1,6 @@ Table agent_skills { - id uuid [pk, default: `gen_random_uuid()`] + id bigserial [pk] + guid uuid [unique, not null, default: `gen_random_uuid()`] name text [unique, not null] description text [not null, default: ''] content text [not null] @@ -9,7 +10,8 @@ Table agent_skills { } Table agent_guardrails { - id uuid [pk, default: `gen_random_uuid()`] + id bigserial [pk] + guid uuid [unique, not null, default: `gen_random_uuid()`] name text [unique, not null] description text [not null, default: ''] content text [not null] @@ -20,9 +22,9 @@ Table agent_guardrails { } Table project_skills { - id serial [pk] - project_id uuid [not null, ref: > projects.guid] - skill_id uuid [not null, ref: > agent_skills.id] + id bigserial [pk] + project_id bigint [not null, ref: > projects.id] + skill_id bigint [not null, ref: > agent_skills.id] created_at timestamptz [not null, default: `now()`] indexes { @@ -32,9 +34,9 @@ Table project_skills { } Table project_guardrails { - id serial [pk] - project_id uuid [not null, ref: > projects.guid] - guardrail_id uuid [not null, ref: > agent_guardrails.id] + id bigserial [pk] + project_id bigint [not null, ref: > projects.id] + guardrail_id bigint [not null, ref: > agent_guardrails.id] created_at timestamptz [not null, default: `now()`] indexes { @@ -44,5 +46,7 @@ Table project_guardrails { } // Cross-file refs (for relspecgo merge) -Ref: project_skills.project_id > projects.guid [delete: cascade] -Ref: project_guardrails.project_id > projects.guid [delete: cascade] +Ref: project_skills.project_id > projects.id [delete: cascade] +Ref: project_skills.skill_id > agent_skills.id [delete: cascade] +Ref: project_guardrails.project_id > projects.id [delete: cascade] +Ref: project_guardrails.guardrail_id > agent_guardrails.id [delete: cascade]