Schema already in 001_init.sql; this is just the Go store layer. IO markers are project-scoped wall-outlet terminators (a cable's "this end plugs into a wall socket outside the diagram" endpoint). Power-by-convention; no schema-level type enforcement. - CreateIOMarker validates frame_id is in the same project (cross-project ref → ErrInvalidInput), defaults label to "IO" when blank. - GetIOMarker is project-scoped — wrong-project read returns ErrNotFound. - UpdateIOMarker uses the FrameRef tri-state for frame_id (same as DeviceUpdate) so callers can clear it explicitly. - DeleteIOMarker is direct delete — ON DELETE SET NULL from the schema drops the io_markers.frame_id ref cleanly when the frame is deleted (verified by TestDeleteFrame_SetsIOMarkerFrameIDToNull). Snapshot now populates IOMarkers from the store; field type tightened from []any to []IOMarker. 7 new table-driven tests, all green with -race.
65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
package db
|
|
|
|
// Project is the top-level entity. One project ↔ one .excalidraw drawing.
|
|
type Project struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
DrawingName string `json:"drawing_name"`
|
|
Description string `json:"description"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
// CableType is global. Renaming/recolouring affects every project.
|
|
type CableType struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Color string `json:"color"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
// Frame is a sub-zone inside a project (`desk`, `rack`, …).
|
|
type Frame struct {
|
|
ID int64 `json:"id"`
|
|
ProjectID int64 `json:"project_id"`
|
|
Name string `json:"name"`
|
|
X float64 `json:"x"`
|
|
Y float64 `json:"y"`
|
|
Width float64 `json:"width"`
|
|
Height float64 `json:"height"`
|
|
ExcalidrawID *string `json:"excalidraw_id,omitempty"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
// Device is a hardware item inside a project, optionally inside a frame.
|
|
type Device struct {
|
|
ID int64 `json:"id"`
|
|
ProjectID int64 `json:"project_id"`
|
|
FrameID *int64 `json:"frame_id"` // nullable: device "outside" any frame
|
|
Name string `json:"name"`
|
|
Color string `json:"color"`
|
|
X float64 `json:"x"`
|
|
Y float64 `json:"y"`
|
|
Width float64 `json:"width"`
|
|
Height float64 `json:"height"`
|
|
ExcalidrawID *string `json:"excalidraw_id,omitempty"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
// Snapshot is the editor's one-shot loader payload for a single project.
|
|
// Arrays for collections still gated by future slices stay non-nil [] so
|
|
// JSON encodes as [] not null.
|
|
type Snapshot struct {
|
|
Project Project `json:"project"`
|
|
Frames []Frame `json:"frames"`
|
|
Devices []Device `json:"devices"`
|
|
Ports []any `json:"ports"`
|
|
Cables []any `json:"cables"`
|
|
IOMarkers []IOMarker `json:"io_markers"`
|
|
Bundles []any `json:"bundles"`
|
|
CableTypes []CableType `json:"cable_types"`
|
|
}
|