refactor(store,tools): migrate IDs from UUID to bigserial int64
Some checks failed
CI / build-and-test (push) Failing after -31m12s

All internal entity lookups now use bigserial primary keys (int64) while
GUIDs are retained for external/public identification. Updated store
functions (TouchProject, UpdateThoughtMetadata, AddThoughtAttachment) to
query by id instead of guid, added GetThoughtByID, changed semanticSearch
and all tool helpers to use *int64 project IDs, and updated retry/backfill
workers to use int64 thought IDs throughout.
This commit is contained in:
2026-05-03 11:43:34 +02:00
parent 9e6d05e055
commit 91239bcf4b
58 changed files with 1208 additions and 2774 deletions

View File

@@ -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 {