store

package
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentHash

func ContentHash(data string) string

ContentHash returns the hex-encoded SHA-256 hash of the given data.

func DefaultDataDir

func DefaultDataDir() (string, error)

DefaultDataDir returns ~/.local/share/nebi/ on Linux, platform equivalent elsewhere.

func MigrateServerDB

func MigrateServerDB(db *gorm.DB) error

MigrateServerDB creates store tables on an external DB (used by local-mode server).

func TomlContentHash

func TomlContentHash(data string) (string, error)

TomlContentHash parses data as TOML, canonicalizes it via sorted-key JSON, and returns the hex-encoded SHA-256 hash. This makes the hash insensitive to whitespace and formatting differences in the TOML source.

Types

type Config

type Config struct {
	ID        int    `gorm:"primarykey"`
	ServerURL string `gorm:"not null;default:''"`
}

Config is a singleton table for store configuration (server URL).

func (Config) TableName

func (Config) TableName() string

type CredentialStore added in v0.10.2

type CredentialStore interface {
	SetPassword(registryName, password string) error
	GetPassword(registryName string) (string, error)
	DeletePassword(registryName string) error
}

CredentialStore provides password storage for registry credentials.

func NewCredentialStore added in v0.10.2

func NewCredentialStore(dataDir string) CredentialStore

NewCredentialStore returns a KeyringStore if available, otherwise a FileCredentialStore. Prints a warning to stderr when falling back to file-based storage.

type Credentials

type Credentials struct {
	ID       int    `gorm:"primarykey"`
	Token    string `gorm:"not null;default:''"`
	Username string `gorm:"not null;default:''"`
}

Credentials stores auth info for the configured nebi server.

func (Credentials) TableName

func (Credentials) TableName() string

type FileCredentialStore added in v0.10.2

type FileCredentialStore struct {
	Path string
	// contains filtered or unexported fields
}

FileCredentialStore is a plaintext fallback for environments without a keychain.

func (*FileCredentialStore) DeletePassword added in v0.10.2

func (f *FileCredentialStore) DeletePassword(registryName string) error

func (*FileCredentialStore) GetPassword added in v0.10.2

func (f *FileCredentialStore) GetPassword(registryName string) (string, error)

func (*FileCredentialStore) SetPassword added in v0.10.2

func (f *FileCredentialStore) SetPassword(registryName, password string) error

type KeyringStore added in v0.10.2

type KeyringStore struct{}

KeyringStore stores credentials in the OS keychain via go-keyring.

func (*KeyringStore) DeletePassword added in v0.10.2

func (k *KeyringStore) DeletePassword(registryName string) error

func (*KeyringStore) GetPassword added in v0.10.2

func (k *KeyringStore) GetPassword(registryName string) (string, error)

func (*KeyringStore) SetPassword added in v0.10.2

func (k *KeyringStore) SetPassword(registryName, password string) error

type LocalPublication added in v0.10.2

type LocalPublication struct {
	ID          uuid.UUID      `gorm:"type:text;primary_key" json:"id"`
	WorkspaceID uuid.UUID      `gorm:"type:text;index;not null" json:"workspace_id"`
	RegistryID  uuid.UUID      `gorm:"type:text;index;not null" json:"registry_id"`
	Repository  string         `gorm:"not null" json:"repository"`
	Tag         string         `gorm:"not null" json:"tag"`
	Digest      string         `json:"digest"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"index" json:"-"`
}

LocalPublication records a workspace publication to an OCI registry from the CLI.

func (*LocalPublication) BeforeCreate added in v0.10.2

func (p *LocalPublication) BeforeCreate(tx *gorm.DB) error

BeforeCreate hook to generate UUID.

func (LocalPublication) TableName added in v0.10.2

func (LocalPublication) TableName() string

TableName ensures GORM uses the "local_publications" table.

type LocalRegistry added in v0.10.2

type LocalRegistry struct {
	ID        uuid.UUID      `gorm:"type:text;primary_key" json:"id"`
	Name      string         `gorm:"uniqueIndex;not null" json:"name"`
	URL       string         `gorm:"not null" json:"url"`
	Username  string         `json:"username"`
	IsDefault bool           `gorm:"default:false" json:"is_default"`
	Namespace string         `json:"namespace"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

LocalRegistry represents an OCI registry configured in the local CLI store. Credentials (passwords) are stored in the OS keychain, not in SQLite.

func (*LocalRegistry) BeforeCreate added in v0.10.2

func (r *LocalRegistry) BeforeCreate(tx *gorm.DB) error

BeforeCreate hook to generate UUID.

func (LocalRegistry) TableName added in v0.10.2

func (LocalRegistry) TableName() string

TableName ensures GORM uses the "local_registries" table.

type LocalUser added in v0.10.3

type LocalUser struct {
	ID           uuid.UUID      `gorm:"type:text;primary_key" json:"id"`
	Username     string         `gorm:"uniqueIndex;not null" json:"username"`
	PasswordHash string         `gorm:"not null" json:"-"`
	Email        string         `gorm:"uniqueIndex;not null" json:"email"`
	AvatarURL    string         `json:"avatar_url"`
	CreatedAt    time.Time      `json:"created_at"`
	UpdatedAt    time.Time      `json:"updated_at"`
	DeletedAt    gorm.DeletedAt `gorm:"index" json:"-"`
}

LocalUser mirrors models.User for CLI/local use. It shares the "users" table with the server-side model so the GUI and CLI can reference the same user (workspace_versions.created_by and workspaces.owner_id both foreign-key into this table).

func (*LocalUser) BeforeCreate added in v0.10.3

func (u *LocalUser) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates the UUID.

func (LocalUser) TableName added in v0.10.3

func (LocalUser) TableName() string

TableName ensures GORM uses the "users" table.

type LocalWorkspace

type LocalWorkspace struct {
	ID             uuid.UUID      `gorm:"type:text;primary_key" json:"id"`
	Name           string         `gorm:"not null" json:"name"`
	Status         string         `gorm:"not null;default:'ready'" json:"status"`
	PackageManager string         `gorm:"not null" json:"package_manager"`
	Path           string         `gorm:"" json:"path,omitempty"`
	Source         string         `gorm:"default:'managed'" json:"source"`
	OriginID       string         `json:"origin_id,omitempty"`
	OriginName     string         `json:"origin_name,omitempty"`
	OriginTag      string         `json:"origin_tag,omitempty"`
	OriginAction   string         `json:"origin_action,omitempty"`
	OriginTomlHash string         `json:"origin_toml_hash,omitempty"`
	OriginLockHash string         `json:"origin_lock_hash,omitempty"`
	CreatedAt      time.Time      `json:"created_at"`
	UpdatedAt      time.Time      `json:"updated_at"`
	DeletedAt      gorm.DeletedAt `gorm:"index" json:"-"`
}

LocalWorkspace represents a workspace tracked by the CLI in its local SQLite database. This is separate from models.Workspace which is used by the server.

func (*LocalWorkspace) BeforeCreate

func (w *LocalWorkspace) BeforeCreate(tx *gorm.DB) error

BeforeCreate hook to generate UUID.

func (LocalWorkspace) TableName

func (LocalWorkspace) TableName() string

TableName ensures GORM uses the "workspaces" table.

type LocalWorkspaceVersion added in v0.10.3

type LocalWorkspaceVersion struct {
	ID            uuid.UUID `gorm:"type:text;primary_key" json:"id"`
	WorkspaceID   uuid.UUID `gorm:"type:text;not null;index:idx_ws_version" json:"workspace_id"`
	VersionNumber int       `gorm:"not null;index:idx_ws_version" json:"version_number"`

	LockFileContent string `gorm:"type:text;not null" json:"lock_file_content"`
	ManifestContent string `gorm:"type:text;not null" json:"manifest_content"`
	PackageMetadata string `gorm:"type:text;not null" json:"package_metadata"`

	ContentHash string `gorm:"type:text;index" json:"content_hash"`

	JobID       *uuid.UUID `gorm:"type:text;index" json:"job_id,omitempty"`
	CreatedBy   uuid.UUID  `gorm:"type:text;not null" json:"created_by"`
	Description string     `gorm:"type:text" json:"description,omitempty"`

	CreatedAt time.Time      `json:"created_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

LocalWorkspaceVersion mirrors models.WorkspaceVersion for CLI/local use. It shares the "workspace_versions" table with the server-side model so the GUI (which uses models.WorkspaceVersion) and the CLI can both read/write versions in local mode.

func (*LocalWorkspaceVersion) BeforeCreate added in v0.10.3

func (wv *LocalWorkspaceVersion) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates the UUID and auto-increments the version number on a per-workspace basis. Matches models.WorkspaceVersion.BeforeCreate.

func (LocalWorkspaceVersion) TableName added in v0.10.3

func (LocalWorkspaceVersion) TableName() string

TableName ensures GORM uses the "workspace_versions" table.

type Store

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

Store manages the local nebi SQLite database via GORM.

func New

func New() (*Store, error)

New creates a Store using the default platform data directory.

func Open

func Open(dataDir string) (*Store, error)

Open creates a Store with a specific data directory.

func (*Store) ClearCredentials added in v0.10.2

func (s *Store) ClearCredentials() error

ClearCredentials removes stored credentials and server URL.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database connection.

func (*Store) CreatePublication added in v0.10.2

func (s *Store) CreatePublication(pub *LocalPublication) error

CreatePublication creates a new local publication record.

func (*Store) CreateRegistry added in v0.10.2

func (s *Store) CreateRegistry(reg *LocalRegistry) error

CreateRegistry creates a new local registry record. If no default registry exists yet, the new one is auto-marked default so a lone registry doesn't force the user to re-run 'nebi registry add --default'.

func (*Store) CreateVersion added in v0.10.3

func (s *Store) CreateVersion(
	wsID uuid.UUID,
	manifestContent string,
	lockContent string,
	description string,
) (*LocalWorkspaceVersion, bool, error)

CreateVersion creates a new workspace version snapshot. If the most recent version for the workspace has the same content hash, it is returned and a new record is NOT created (deduplication). The returned bool indicates whether the version was newly created (true) or deduplicated (false).

func (*Store) CreateWorkspace

func (s *Store) CreateWorkspace(ws *LocalWorkspace) error

CreateWorkspace creates a new workspace record.

func (*Store) DB

func (s *Store) DB() *gorm.DB

DB returns the underlying GORM DB for advanced queries.

func (*Store) DataDir

func (s *Store) DataDir() string

DataDir returns the store's data directory.

func (*Store) DeleteRegistry added in v0.10.2

func (s *Store) DeleteRegistry(id uuid.UUID) error

DeleteRegistry removes a registry by ID (hard delete).

func (*Store) DeleteWorkspace

func (s *Store) DeleteWorkspace(id uuid.UUID) error

DeleteWorkspace removes a workspace by ID (hard delete).

func (*Store) FindWorkspaceByName

func (s *Store) FindWorkspaceByName(name string) (*LocalWorkspace, error)

FindWorkspaceByName returns the first workspace with the given name, or nil if not found.

func (*Store) FindWorkspaceByPath

func (s *Store) FindWorkspaceByPath(path string) (*LocalWorkspace, error)

FindWorkspaceByPath returns the workspace at the given path, or nil if not found.

func (*Store) FindWorkspacesByName

func (s *Store) FindWorkspacesByName(name string) ([]LocalWorkspace, error)

FindWorkspacesByName returns all workspaces with the given name. Multiple workspaces can share the same name since path is the unique identifier.

func (*Store) GetDefaultRegistry added in v0.10.2

func (s *Store) GetDefaultRegistry() (*LocalRegistry, error)

GetDefaultRegistry returns the default registry (is_default=true).

func (*Store) GetRegistryByName added in v0.10.2

func (s *Store) GetRegistryByName(name string) (*LocalRegistry, error)

GetRegistryByName returns a registry by name.

func (*Store) GetVersion added in v0.10.3

func (s *Store) GetVersion(wsID uuid.UUID, versionNumber int) (*LocalWorkspaceVersion, error)

GetVersion returns a single workspace version with full manifest and lock content. Returns nil if the version is not found.

func (*Store) GetWorkspace

func (s *Store) GetWorkspace(id uuid.UUID) (*LocalWorkspace, error)

GetWorkspace returns a workspace by ID.

func (*Store) ListPublications added in v0.10.2

func (s *Store) ListPublications() ([]LocalPublication, error)

ListPublications returns all local publications, most recent first.

func (*Store) ListPublicationsByWorkspace added in v0.10.2

func (s *Store) ListPublicationsByWorkspace(workspaceID uuid.UUID) ([]LocalPublication, error)

ListPublicationsByWorkspace returns publications for a specific workspace.

func (*Store) ListRegistries added in v0.10.2

func (s *Store) ListRegistries() ([]LocalRegistry, error)

ListRegistries returns all local registries.

func (*Store) ListVersions added in v0.10.3

func (s *Store) ListVersions(wsID uuid.UUID) ([]LocalWorkspaceVersion, error)

ListVersions returns all versions for a workspace, newest first. The large manifest/lock TEXT columns are omitted to keep the result cheap; callers that need them should use GetVersion.

func (*Store) ListWorkspaces

func (s *Store) ListWorkspaces() ([]LocalWorkspace, error)

ListWorkspaces returns all workspaces.

func (*Store) LoadCredentials

func (s *Store) LoadCredentials() (*Credentials, error)

LoadCredentials reads stored credentials.

func (*Store) LoadServerURL

func (s *Store) LoadServerURL() (string, error)

LoadServerURL returns the configured server URL.

func (*Store) RollbackToVersion added in v0.10.3

func (s *Store) RollbackToVersion(wsID uuid.UUID, versionNumber int) (*LocalWorkspaceVersion, error)

RollbackToVersion writes the target version's pixi.toml and pixi.lock to the workspace's directory and creates a new "Rolled back to version N" snapshot. It does NOT run pixi install — callers should print a hint telling the user to run it themselves. Returns the newly-created rollback snapshot. If disk content already matches the rollback target, the existing latest version is returned (CreateVersion's dedup).

func (*Store) SaveCredentials

func (s *Store) SaveCredentials(creds *Credentials) error

SaveCredentials writes credentials.

func (*Store) SaveServerURL

func (s *Store) SaveServerURL(url string) error

SaveServerURL stores the server URL.

func (*Store) SaveWorkspace

func (s *Store) SaveWorkspace(ws *LocalWorkspace) error

SaveWorkspace updates an existing workspace record.

func (*Store) SetDefaultRegistry added in v0.10.4

func (s *Store) SetDefaultRegistry(name string) (*LocalRegistry, error)

SetDefaultRegistry marks the registry with the given name as the default and clears the flag on every other registry. Atomic — runs in a single transaction so the default slot never goes empty or double-filled.

Jump to

Keyboard shortcuts

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