workspacedb

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package workspacedb owns per-workspace SQLite database lifecycle helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImportLegacyJournal

func ImportLegacyJournal(ctx context.Context, homeDir, sourceID string, profiles []string) (resultErr error)

ImportLegacyJournal copies profile-owned rows before the source registration can be retired.

func MigrationStream

func MigrationStream() store.MigrationStream

MigrationStream returns the embedded workspace database migration stream.

Types

type DB

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

DB is an open per-workspace Compozy database handle.

func Open

func Open(ctx context.Context, opts Options) (*DB, error)

Open resolves the workspace identity and opens <home>/workspaces/<registration-id>/compozy.db.

func (*DB) Close

func (d *DB) Close(ctx context.Context) error

Close checkpoints the WAL and closes the database.

func (*DB) DB

func (d *DB) DB() *sql.DB

DB exposes the underlying SQL handle for storage packages.

func (*DB) InsertTerminalArtifact

func (d *DB) InsertTerminalArtifact(ctx context.Context, artifact TerminalArtifactWrite) error

InsertTerminalArtifact retains metadata for one command spill artifact.

func (*DB) InsertTerminalCommand

func (d *DB) InsertTerminalCommand(ctx context.Context, row TerminalCommandWrite) error

InsertTerminalCommand appends one immutable terminal command.

func (*DB) LinkTerminalRecording

func (d *DB) LinkTerminalRecording(ctx context.Context, recording TerminalRecordingWrite) error

LinkTerminalRecording inserts recording metadata and links covered commands atomically.

func (*DB) Path

func (d *DB) Path() string

Path reports the database path.

func (*DB) SweepExpiredTerminalFiles

func (d *DB) SweepExpiredTerminalFiles(
	ctx context.Context,
	expiresAt int64,
	remove func(string) error,
) error

SweepExpiredTerminalFiles removes expired rows after their unshared files are removed.

func (*DB) TerminalArtifact

func (d *DB) TerminalArtifact(ctx context.Context, id string) (TerminalArtifactRecord, error)

TerminalArtifact returns retained metadata by id.

func (*DB) TerminalCommandIDExists

func (d *DB) TerminalCommandIDExists(ctx context.Context, id string) (bool, error)

TerminalCommandIDExists reports whether an immutable command identity is already durable.

func (*DB) TerminalRecording

func (d *DB) TerminalRecording(ctx context.Context, id string) (TerminalRecordingRecord, error)

TerminalRecording returns retained recording metadata by id.

func (*DB) TerminalRecordingIDExists

func (d *DB) TerminalRecordingIDExists(ctx context.Context, id string) (bool, error)

TerminalRecordingIDExists reports whether an immutable recording identity is already durable.

func (*DB) WorkspaceID

func (d *DB) WorkspaceID() string

WorkspaceID reports the resolved workspace identity.

func (*DB) WorkspaceRoot

func (d *DB) WorkspaceRoot() string

WorkspaceRoot reports the workspace root used to open the database.

type Options

type Options struct {
	HomeDir       string
	WorkspaceID   string
	WorkspaceRoot string
}

Options configures a per-workspace database open.

type Pool

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

Pool owns lazy, reusable database handles for daemon-known workspaces.

func NewPool

func NewPool(homeDir string, resolveRoot RootResolver) (*Pool, error)

NewPool constructs an empty per-workspace database pool.

func (*Pool) Close

func (p *Pool) Close(ctx context.Context) error

Close closes every open workspace database exactly once.

func (*Pool) CloseWorkspace

func (p *Pool) CloseWorkspace(ctx context.Context, workspaceID string) error

CloseWorkspace closes and forgets one workspace handle.

func (*Pool) Open

func (p *Pool) Open(ctx context.Context, workspaceID string) (*DB, error)

Open returns the shared database for workspaceID, opening it on first use.

func (*Pool) PrepareWorkspaceRemoval

func (p *Pool) PrepareWorkspaceRemoval(
	ctx context.Context,
	workspaceID string,
) (*WorkspaceRemovalPreparation, error)

PrepareWorkspaceRemoval captures the database path independently of the project directory.

func (*Pool) RemoveWorkspace

func (p *Pool) RemoveWorkspace(ctx context.Context, workspaceID string) error

RemoveWorkspace closes one workspace database and removes its SQLite files.

type ResolvedRoot

type ResolvedRoot struct {
	RootDir     string
	WorkspaceID string
}

ResolvedRoot binds a public workspace registration to its durable on-disk identity.

type RootResolver

type RootResolver func(ctx context.Context, workspaceID string) (ResolvedRoot, error)

RootResolver resolves a public workspace id to its root and durable identity.

type TerminalArtifactRecord

type TerminalArtifactRecord struct {
	ID, CommandID, ProfileID, Digest, Path string
	TerminalID                             *string
	Bytes, ExpiresAt                       int64
}

TerminalArtifactRecord is stored metadata for one retained command artifact.

type TerminalArtifactWrite

type TerminalArtifactWrite struct {
	ID, CommandID, ProfileID, Digest, Path string
	TerminalID                             *string
	Bytes, ExpiresAt                       int64
}

TerminalArtifactWrite is the storage boundary for retained command output.

type TerminalCommandWrite

type TerminalCommandWrite struct {
	ID, ProfileID, ActorKind, ActorID string
	Command, Cwd, ExitCause           string
	DetectedBy, Approval              string
	TerminalID, SessionID, RunID      *string
	ArgvDigest, ExitSignal            *string
	RecordingID                       *string
	StartedAt, OutputBytes            int64
	DurationMs                        *int64
	ExitCode                          *int
	Truncated                         bool
}

TerminalCommandWrite is the storage boundary for one immutable command row.

type TerminalRecordingRecord

type TerminalRecordingRecord struct {
	ID, TerminalID, ProfileID, Digest, Path string
	StartedAt, Bytes, ExpiresAt             int64
	StoppedAt                               *int64
}

TerminalRecordingRecord is stored metadata for one retained recording.

type TerminalRecordingWrite

type TerminalRecordingWrite struct {
	ID, TerminalID, ProfileID, Digest, Path string
	StartedAt, Bytes, ExpiresAt             int64
	StoppedAt                               *int64
}

TerminalRecordingWrite is the storage boundary for one retained recording.

type WorkspaceRemovalPreparation

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

WorkspaceRemovalPreparation owns a sealed database removal until commit or rollback.

func (*WorkspaceRemovalPreparation) BeforeDelete

BeforeDelete seals this workspace against new database admission.

func (*WorkspaceRemovalPreparation) Commit

Commit closes the detached handle and removes its SQLite files. It is retry-safe.

func (*WorkspaceRemovalPreparation) Rollback

Rollback releases the admission seal without touching the database or files.

Directories

Path Synopsis
Package schema embeds the workspace database schema and migration directory.
Package schema embeds the workspace database schema and migration directory.

Jump to

Keyboard shortcuts

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