fix(canvas): 画布版本 - 合并 PR #528 防止旧内容覆盖并支持历史恢复

将画布 revision CAS 与历史快照接到 schema v23,保留当前顶栏积分弹窗和已有菜单入口。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
ddCat
2026-09-18 10:40:23 +08:00
69 changed files with 3571 additions and 293 deletions

View File

@@ -0,0 +1,25 @@
package model
import "time"
// CanvasSnapshot stores document structure only; media stays in Resource storage.
type CanvasSnapshot struct {
ID string `json:"id" gorm:"primaryKey;size:36"`
CanvasID string `json:"canvasId" gorm:"size:80;not null;uniqueIndex:idx_canvas_snapshot_revision,priority:1;index:idx_canvas_snapshot_created,priority:1"`
UserID string `json:"-" gorm:"size:36;not null;index"`
Revision int64 `json:"revision" gorm:"not null;uniqueIndex:idx_canvas_snapshot_revision,priority:2"`
Title string `json:"title" gorm:"size:240"`
NodeCount int `json:"nodeCount"`
ConnectionCount int `json:"connectionCount"`
PayloadBytes int `json:"payloadBytes"`
PayloadJSON string `json:"-" gorm:"type:text;not null"`
Reason string `json:"reason" gorm:"size:24"`
ContentUpdatedAt time.Time `json:"contentUpdatedAt"`
CreatedAt time.Time `json:"createdAt" gorm:"not null;index:idx_canvas_snapshot_created,priority:2"`
}
type CanvasSnapshotResource struct {
SnapshotID string `json:"-" gorm:"primaryKey;size:36"`
ResourceID string `json:"-" gorm:"primaryKey;size:36;index"`
Resource *Resource `json:"-" gorm:"foreignKey:ResourceID;constraint:OnDelete:RESTRICT"`
}

View File

@@ -374,6 +374,7 @@ type CanvasProject struct {
ProjectID string `json:"projectId,omitempty" gorm:"index;size:36;index:idx_canvas_projects_user_project_updated,priority:2"`
Title string `json:"title" gorm:"size:240"`
PayloadJSON string `json:"payloadJson" gorm:"type:text"`
Revision int64 `json:"revision" gorm:"not null;default:1"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt" gorm:"index:idx_canvas_projects_user_updated,priority:2;index:idx_canvas_projects_user_project_updated,priority:3"`
}