Skip to content

Commit b19f762

Browse files
jsell-rhclaude
andcommitted
fix(api-server): mark session_messages seq as read-only in Gorm model
The refactor from raw SQL to g2.Create(msg) in PR #1660 caused Gorm to include seq=0 in INSERT statements, colliding with the unique constraint when a seq=0 row already existed. The -> tag tells Gorm to omit seq from writes and let the Postgres DEFAULT nextval() fire, while still reading the value back via the RETURNING clause. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 61894f1 commit b19f762

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

components/ambient-api-server/plugins/sessions/message_model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "time"
55
type SessionMessage struct {
66
ID string `gorm:"column:id;primaryKey;type:varchar(36)" json:"id"`
77
SessionID string `gorm:"column:session_id;type:varchar(36)" json:"session_id"`
8-
Seq int64 `gorm:"column:seq" json:"seq"`
8+
Seq int64 `gorm:"column:seq;->" json:"seq"`
99
EventType string `gorm:"column:event_type;type:varchar(255)" json:"event_type"`
1010
Payload string `gorm:"column:payload;type:text" json:"payload"`
1111
CreatedAt time.Time `gorm:"column:created_at;type:timestamptz" json:"created_at"`

0 commit comments

Comments
 (0)