Help us shape the future of Go! Take the 2026 Go Developer Survey

rollback

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RollbackBeforeTurn

func RollbackBeforeTurn(ctx context.Context, db *gorm.DB, sessionID string, targetTurn int,
	repo *git.Repo, tcStore *Store) error

RollbackBeforeTurn 回退到 targetTurn 开始之前的状态。 撤销 [targetTurn, lastTurn] 区间所有变更:DB 元数据逆向 + git revert 章节文件。

三步策略(最小化不一致窗口):

  1. git revert --no-commit 暂存(可 revert 部分提前检测,不碰 DB)
  2. DB 事务 commit(失败则 git revert --abort)
  3. git commit(DB 已提交,这一步是纯 index→commit,极低失败概率)

Types

type Store

type Store struct {
	DB *gorm.DB
	// contains filtered or unexported fields
}

Store 管理 turn_commits 表的读写。

func NewStore

func NewStore(db *gorm.DB, logger *slog.Logger) *Store

NewStore 创建 Store 实例。

func (*Store) ListForRollback

func (s *Store) ListForRollback(ctx context.Context, sessionID string, targetTurn, lastTurn int) ([]TurnCommit, error)

ListForRollback 查询 [targetTurn, lastTurn] 区间内所有 git commit, 按 turn_id ASC, id ASC 返回(时间正序,传给 Revert 时外部会逆序)。 与 storage.RollbackTo / RollbackInTx 的语义和签名对齐。

type TurnCommit

type TurnCommit struct {
	ID         int64     `gorm:"column:id;primaryKey;autoIncrement"`
	SessionID  string    `gorm:"column:session_id;not null;uniqueIndex:uk_turn_commits"`
	TurnID     int       `gorm:"column:turn_id;not null;uniqueIndex:uk_turn_commits"`
	CommitType string    `gorm:"column:commit_type;not null;uniqueIndex:uk_turn_commits"` // "user" | "ai"
	CommitHash string    `gorm:"column:commit_hash;not null"`
	CreatedAt  time.Time `gorm:"column:created_at;autoCreateTime"`
}

TurnCommit 记录每个 turn 的 git commit hash,用于回退时精确定位。 每个 turn 最多两条记录:commit_type="user"(用户手动修改)和 commit_type="ai"(AI 修改)。

func (TurnCommit) TableName

func (TurnCommit) TableName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL