db

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const SchemaVersion = 5

SchemaVersion is the current database schema version

Variables

View Source
var Migrations = []Migration{

	{
		Version:     2,
		Description: "Add action_log table for undo support",
		SQL: `
CREATE TABLE IF NOT EXISTS action_log (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    session_id TEXT NOT NULL,
    action_type TEXT NOT NULL,
    entity_type TEXT NOT NULL,
    entity_id TEXT NOT NULL,
    previous_data TEXT DEFAULT '',
    new_data TEXT DEFAULT '',
    timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    undone INTEGER DEFAULT 0
);
CREATE INDEX IF NOT EXISTS idx_action_log_session ON action_log(session_id);
CREATE INDEX IF NOT EXISTS idx_action_log_timestamp ON action_log(timestamp);
`,
	},
	{
		Version:     3,
		Description: "Allow work session logs without issue_id",
		SQL: `
-- SQLite doesn't support ALTER COLUMN, so we need to recreate the table
CREATE TABLE logs_new (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    issue_id TEXT DEFAULT '',
    session_id TEXT NOT NULL,
    work_session_id TEXT DEFAULT '',
    message TEXT NOT NULL,
    type TEXT NOT NULL DEFAULT 'progress',
    timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO logs_new SELECT * FROM logs;
DROP TABLE logs;
ALTER TABLE logs_new RENAME TO logs;
CREATE INDEX IF NOT EXISTS idx_logs_issue ON logs(issue_id);
CREATE INDEX IF NOT EXISTS idx_logs_work_session ON logs(work_session_id);
`,
	},
	{
		Version:     4,
		Description: "Add minor flag to issues for self-reviewable tasks",
		SQL:         `ALTER TABLE issues ADD COLUMN minor INTEGER DEFAULT 0;`,
	},
	{
		Version:     5,
		Description: "Add created_branch to issues",
		SQL:         `ALTER TABLE issues ADD COLUMN created_branch TEXT DEFAULT '';`,
	},
}

Migrations is the list of all database migrations in order

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB wraps the database connection

func Initialize

func Initialize(baseDir string) (*DB, error)

Initialize creates the database and runs migrations

func Open

func Open(baseDir string) (*DB, error)

Open opens the database and runs any pending migrations

func (*DB) AddComment

func (db *DB) AddComment(comment *models.Comment) error

AddComment adds a comment to an issue

func (*DB) AddDependency

func (db *DB) AddDependency(issueID, dependsOnID, relationType string) error

AddDependency adds a dependency between issues

func (*DB) AddGitSnapshot

func (db *DB) AddGitSnapshot(snapshot *models.GitSnapshot) error

AddGitSnapshot records a git state snapshot

func (*DB) AddHandoff

func (db *DB) AddHandoff(handoff *models.Handoff) error

AddHandoff adds a handoff entry

func (*DB) AddLog

func (db *DB) AddLog(log *models.Log) error

AddLog adds a log entry to an issue

func (*DB) BaseDir

func (db *DB) BaseDir() string

BaseDir returns the base directory for the database

func (*DB) Close

func (db *DB) Close() error

Close closes the database

func (*DB) CreateIssue

func (db *DB) CreateIssue(issue *models.Issue) error

CreateIssue creates a new issue

func (*DB) CreateWorkSession

func (db *DB) CreateWorkSession(ws *models.WorkSession) error

CreateWorkSession creates a new work session

func (*DB) DeleteIssue

func (db *DB) DeleteIssue(id string) error

DeleteIssue soft-deletes an issue

func (*DB) GetActiveSessions

func (db *DB) GetActiveSessions(since time.Time) ([]string, error)

GetActiveSessions returns distinct session IDs with activity since the given time

func (*DB) GetBlockedBy

func (db *DB) GetBlockedBy(issueID string) ([]string, error)

GetBlockedBy returns what issues are blocked by this issue

func (*DB) GetComments

func (db *DB) GetComments(issueID string) ([]models.Comment, error)

GetComments retrieves comments for an issue

func (*DB) GetDependencies

func (db *DB) GetDependencies(issueID string) ([]string, error)

GetDependencies returns what an issue depends on

func (*DB) GetIssue

func (db *DB) GetIssue(id string) (*models.Issue, error)

GetIssue retrieves an issue by ID

func (*DB) GetIssueSessionLog

func (db *DB) GetIssueSessionLog(sessionID string) ([]string, error)

GetIssueSessionLog returns issues touched by a session

func (*DB) GetLastAction

func (db *DB) GetLastAction(sessionID string) (*models.ActionLog, error)

GetLastAction returns the most recent undoable action for a session

func (*DB) GetLatestHandoff

func (db *DB) GetLatestHandoff(issueID string) (*models.Handoff, error)

GetLatestHandoff retrieves the latest handoff for an issue

func (*DB) GetLinkedFiles

func (db *DB) GetLinkedFiles(issueID string) ([]models.IssueFile, error)

GetLinkedFiles returns files linked to an issue

func (*DB) GetLogs

func (db *DB) GetLogs(issueID string, limit int) ([]models.Log, error)

GetLogs retrieves logs for an issue, including work session logs

func (*DB) GetLogsByWorkSession

func (db *DB) GetLogsByWorkSession(wsID string) ([]models.Log, error)

GetLogsByWorkSession retrieves logs for a specific work session

func (*DB) GetRecentActions

func (db *DB) GetRecentActions(sessionID string, limit int) ([]models.ActionLog, error)

GetRecentActions returns recent actions for a session

func (*DB) GetRecentActionsAll

func (db *DB) GetRecentActionsAll(limit int) ([]models.ActionLog, error)

GetRecentActionsAll returns recent action_log entries across all sessions

func (*DB) GetRecentCommentsAll

func (db *DB) GetRecentCommentsAll(limit int) ([]models.Comment, error)

GetRecentCommentsAll returns recent comments across all issues

func (*DB) GetRecentHandoffs

func (db *DB) GetRecentHandoffs(limit int, since time.Time) ([]models.Handoff, error)

GetRecentHandoffs retrieves recent handoffs across all issues

func (*DB) GetRecentLogsAll

func (db *DB) GetRecentLogsAll(limit int) ([]models.Log, error)

GetRecentLogsAll returns recent logs across all issues

func (*DB) GetSchemaVersion

func (db *DB) GetSchemaVersion() (int, error)

GetSchemaVersion returns the current schema version from the database

func (*DB) GetStartSnapshot

func (db *DB) GetStartSnapshot(issueID string) (*models.GitSnapshot, error)

GetStartSnapshot returns the start snapshot for an issue

func (*DB) GetStats

func (db *DB) GetStats() (map[string]int, error)

GetStats returns database statistics

func (*DB) GetWorkSession

func (db *DB) GetWorkSession(id string) (*models.WorkSession, error)

GetWorkSession retrieves a work session

func (*DB) GetWorkSessionIssues

func (db *DB) GetWorkSessionIssues(wsID string) ([]string, error)

GetWorkSessionIssues returns issues tagged to a work session

func (*DB) LinkFile

func (db *DB) LinkFile(issueID, filePath string, role models.FileRole, sha string) error

LinkFile links a file to an issue

func (*DB) ListIssues

func (db *DB) ListIssues(opts ListIssuesOptions) ([]models.Issue, error)

ListIssues returns issues matching the filter

func (*DB) ListWorkSessions

func (db *DB) ListWorkSessions(limit int) ([]models.WorkSession, error)

ListWorkSessions returns recent work sessions

func (*DB) LogAction

func (db *DB) LogAction(action *models.ActionLog) error

LogAction records an action for undo support

func (*DB) MarkActionUndone

func (db *DB) MarkActionUndone(actionID int64) error

MarkActionUndone marks an action as undone

func (*DB) RemoveDependency

func (db *DB) RemoveDependency(issueID, dependsOnID string) error

RemoveDependency removes a dependency

func (*DB) RestoreIssue

func (db *DB) RestoreIssue(id string) error

RestoreIssue restores a soft-deleted issue

func (*DB) RunMigrations

func (db *DB) RunMigrations() (int, error)

RunMigrations runs any pending database migrations

func (*DB) SearchIssues

func (db *DB) SearchIssues(query string, opts ListIssuesOptions) ([]models.Issue, error)

SearchIssues performs full-text search across issues

func (*DB) SetSchemaVersion

func (db *DB) SetSchemaVersion(version int) error

SetSchemaVersion sets the schema version in the database

func (*DB) TagIssueToWorkSession

func (db *DB) TagIssueToWorkSession(wsID, issueID string) error

TagIssueToWorkSession links an issue to a work session

func (*DB) UnlinkFile

func (db *DB) UnlinkFile(issueID, filePath string) error

UnlinkFile removes a file link

func (*DB) UntagIssueFromWorkSession

func (db *DB) UntagIssueFromWorkSession(wsID, issueID string) error

UntagIssueFromWorkSession removes an issue from a work session

func (*DB) UpdateIssue

func (db *DB) UpdateIssue(issue *models.Issue) error

UpdateIssue updates an issue

func (*DB) UpdateWorkSession

func (db *DB) UpdateWorkSession(ws *models.WorkSession) error

UpdateWorkSession updates a work session

type ListIssuesOptions

type ListIssuesOptions struct {
	Status         []models.Status
	Type           []models.Type
	Priority       string
	Labels         []string
	IncludeDeleted bool
	OnlyDeleted    bool
	Search         string
	Implementer    string
	Reviewer       string
	ReviewableBy   string // Issues that this session can review
	ParentID       string
	PointsMin      int
	PointsMax      int
	CreatedAfter   time.Time
	CreatedBefore  time.Time
	UpdatedAfter   time.Time
	UpdatedBefore  time.Time
	ClosedAfter    time.Time
	ClosedBefore   time.Time
	SortBy         string
	SortDesc       bool
	Limit          int
	IDs            []string
}

ListIssuesOptions contains filter options for listing issues

type Migration

type Migration struct {
	Version     int
	Description string
	SQL         string
}

Migration defines a database migration

Jump to

Keyboard shortcuts

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