mirror of
https://github.com/Dvorinka/excalidraw-full.git
synced 2026-06-03 22:02:57 +00:00
fix(db): handle explicit null values in update requests
Docker Images / Build and push (push) Failing after 16s
Docker Images / Build and push (push) Failing after 16s
Introduce a `NullString` type to distinguish between JSON `null` and absent fields in `UpdateDrawingRequest`. This ensures that when a field is explicitly set to `null` in a request, the database can correctly process the update. Additionally, refactor the folder order migration to include proper `goose` up/down instructions.
This commit is contained in:
@@ -1,2 +1,7 @@
|
|||||||
ALTER TABLE workspace_folders ADD COLUMN IF NOT EXISTS sort_order INTEGER NOT NULL DEFAULT 0;
|
-- +goose Up
|
||||||
CREATE INDEX IF NOT EXISTS idx_workspace_folders_sort_order ON workspace_folders(team_id, sort_order);
|
ALTER TABLE workspace_folders ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;
|
||||||
|
CREATE INDEX idx_workspace_folders_sort_order ON workspace_folders(team_id, sort_order);
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
DROP INDEX IF EXISTS idx_workspace_folders_sort_order;
|
||||||
|
ALTER TABLE workspace_folders DROP COLUMN IF EXISTS sort_order;
|
||||||
|
|||||||
+30
-9
@@ -40,12 +40,33 @@ type CreateDrawingRequest struct {
|
|||||||
Snapshot json.RawMessage `json:"snapshot"`
|
Snapshot json.RawMessage `json:"snapshot"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NullString distinguishes JSON null (Valid=true, Value=nil) from absent field (Valid=false).
|
||||||
|
type NullString struct {
|
||||||
|
Value *string
|
||||||
|
Valid bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *NullString) UnmarshalJSON(data []byte) error {
|
||||||
|
if string(data) == "null" {
|
||||||
|
n.Value = nil
|
||||||
|
n.Valid = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var s string
|
||||||
|
if err := json.Unmarshal(data, &s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
n.Value = &s
|
||||||
|
n.Valid = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type UpdateDrawingRequest struct {
|
type UpdateDrawingRequest struct {
|
||||||
FolderID *string `json:"folder_id"`
|
FolderID NullString `json:"folder_id"`
|
||||||
ProjectID *string `json:"project_id"`
|
ProjectID NullString `json:"project_id"`
|
||||||
Title *string `json:"title"`
|
Title *string `json:"title"`
|
||||||
Description *string `json:"description"`
|
Description *string `json:"description"`
|
||||||
Visibility *string `json:"visibility"`
|
Visibility *string `json:"visibility"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateRevisionRequest struct {
|
type CreateRevisionRequest struct {
|
||||||
@@ -621,11 +642,11 @@ func (s *Store) UpdateDrawing(ctx context.Context, userID, drawingID string, req
|
|||||||
}
|
}
|
||||||
current.Visibility = *req.Visibility
|
current.Visibility = *req.Visibility
|
||||||
}
|
}
|
||||||
if req.FolderID != nil {
|
if req.FolderID.Valid {
|
||||||
current.FolderID = req.FolderID
|
current.FolderID = req.FolderID.Value
|
||||||
}
|
}
|
||||||
if req.ProjectID != nil {
|
if req.ProjectID.Valid {
|
||||||
current.ProjectID = req.ProjectID
|
current.ProjectID = req.ProjectID.Value
|
||||||
}
|
}
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
_, err = s.db.ExecContext(ctx, `UPDATE workspace_drawings
|
_, err = s.db.ExecContext(ctx, `UPDATE workspace_drawings
|
||||||
|
|||||||
Reference in New Issue
Block a user