fix(freedoc): widen freeform project_id to BIGINT for snowflake IDs
UI-11 POST /freeform-documents 500 when project_id exceeds int4. Align Go types + goose 00063 with projects.id BIGINT.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
-- +goose Up
|
||||
-- freeform_documents.project_id must match projects.id (BIGINT snowflake).
|
||||
-- Prior INT rejected inserts once project IDs exceeded int4 max (~2.1e9).
|
||||
|
||||
ALTER TABLE freeform_documents
|
||||
ALTER COLUMN project_id TYPE BIGINT;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE freeform_documents
|
||||
ALTER COLUMN project_id TYPE INT;
|
||||
@@ -59,6 +59,25 @@ func TestCreateDocument_ClientKeyIdempotentAndBootstrapsLedger(t *testing.T) {
|
||||
assert.NotEqual(t, detail.Document.DocID, otherUser.Document.DocID)
|
||||
}
|
||||
|
||||
func TestCreateDocument_AcceptsSnowflakeProjectID(t *testing.T) {
|
||||
// projects.id is BIGINT; freeform must accept IDs above int4 max (regression: int4 encode 500).
|
||||
const snowflakeProjectID int64 = 1789095399489
|
||||
svc := freedoc.NewService(nil, nil)
|
||||
detail, err := svc.CreateDocument(context.Background(), 42, freedoc.CreateFreeformDocRequest{
|
||||
ProjectID: snowflakeProjectID,
|
||||
Title: "snowflake.pdf",
|
||||
ContentMarkdown: "# snowflake\n",
|
||||
Space: "my_private",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, snowflakeProjectID, detail.Document.ProjectID)
|
||||
|
||||
list, err := svc.ListDocuments(context.Background(), 42, snowflakeProjectID, "my_private")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, list, 1)
|
||||
assert.Equal(t, snowflakeProjectID, list[0].ProjectID)
|
||||
}
|
||||
|
||||
func TestCreateDocument_RejectsEmptyContent(t *testing.T) {
|
||||
svc := freedoc.NewService(nil, nil)
|
||||
_, err := svc.CreateDocument(context.Background(), 1, freedoc.CreateFreeformDocRequest{
|
||||
|
||||
@@ -525,7 +525,7 @@ func (s *Service) GetDocument(ctx context.Context, userID int, docID string) (*F
|
||||
}
|
||||
|
||||
// ListDocuments 按空间与权限列出自由文档概要
|
||||
func (s *Service) ListDocuments(ctx context.Context, userID int, projectID int, space string) ([]FreeformDocSummary, error) {
|
||||
func (s *Service) ListDocuments(ctx context.Context, userID int, projectID int64, space string) ([]FreeformDocSummary, error) {
|
||||
if space != "my_private" && space != "project_shared" && space != "trash" {
|
||||
space = "my_private"
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ var (
|
||||
// FreeformDocument 自由私密/共享文档元数据
|
||||
type FreeformDocument struct {
|
||||
DocID string `json:"doc_id"`
|
||||
ProjectID int `json:"project_id"`
|
||||
ProjectID int64 `json:"project_id"`
|
||||
OwnerUserID int `json:"owner_user_id"`
|
||||
SourceMessageID *int64 `json:"source_message_id,omitempty"`
|
||||
SourceContentSHA256 string `json:"source_content_sha256"`
|
||||
@@ -53,7 +53,7 @@ type FreeformDocDetail struct {
|
||||
// FreeformDocSummary 列表项概要
|
||||
type FreeformDocSummary struct {
|
||||
DocID string `json:"doc_id"`
|
||||
ProjectID int `json:"project_id"`
|
||||
ProjectID int64 `json:"project_id"`
|
||||
OwnerUserID int `json:"owner_user_id"`
|
||||
Title string `json:"title"`
|
||||
Space string `json:"space"`
|
||||
@@ -66,14 +66,14 @@ type FreeformDocSummary struct {
|
||||
// CreateFromMessageRequest 从单条消息保存到私密文档请求
|
||||
type CreateFromMessageRequest struct {
|
||||
MessageID int64 `json:"message_id"`
|
||||
ProjectID int `json:"project_id"`
|
||||
ProjectID int64 `json:"project_id"`
|
||||
Title string `json:"title,omitempty"`
|
||||
ExpectedSHA256 string `json:"expected_sha256,omitempty"`
|
||||
}
|
||||
|
||||
// CreateFreeformDocRequest 直接创建空白/自定义自由文档请求(上传附件即时注册事实源)
|
||||
type CreateFreeformDocRequest struct {
|
||||
ProjectID int `json:"project_id"`
|
||||
ProjectID int64 `json:"project_id"`
|
||||
Title string `json:"title"`
|
||||
ContentMarkdown string `json:"content_markdown"`
|
||||
Space string `json:"space,omitempty"` // 默认 'my_private'
|
||||
|
||||
@@ -181,9 +181,11 @@ func (s *Server) handleListFreeformDocs(w http.ResponseWriter, r *http.Request)
|
||||
if space == "" {
|
||||
space = "my_private"
|
||||
}
|
||||
projectID := 0
|
||||
projectID := int64(0)
|
||||
if pStr := r.URL.Query().Get("project_id"); pStr != "" {
|
||||
projectID, _ = strconv.Atoi(pStr)
|
||||
if parsed, err := strconv.ParseInt(pStr, 10, 64); err == nil {
|
||||
projectID = parsed
|
||||
}
|
||||
}
|
||||
|
||||
list, err := s.freeDoc.ListDocuments(r.Context(), userID, projectID, space)
|
||||
|
||||
Reference in New Issue
Block a user