state

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunMigrations

func RunMigrations(dsn string) error

RunMigrations applies all pending goose migrations from the embedded SQL files. Should be called explicitly via `previewctl migrate` before first use.

Types

type FileStateAdapter

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

FileStateAdapter persists state to a JSON file with atomic writes.

func NewFileStateAdapter

func NewFileStateAdapter(path string) *FileStateAdapter

NewFileStateAdapter creates a new file-based state adapter.

func (*FileStateAdapter) GetEnvironment

func (a *FileStateAdapter) GetEnvironment(ctx context.Context, name string) (*domain.EnvironmentEntry, error)

func (*FileStateAdapter) Load

func (*FileStateAdapter) RemoveEnvironment

func (a *FileStateAdapter) RemoveEnvironment(ctx context.Context, name string) error

func (*FileStateAdapter) Save

func (a *FileStateAdapter) Save(_ context.Context, state *domain.State) error

func (*FileStateAdapter) SetEnvironment

func (a *FileStateAdapter) SetEnvironment(ctx context.Context, name string, entry *domain.EnvironmentEntry) error

type PostgresStateAdapter

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

PostgresStateAdapter persists state to a PostgreSQL database. Each environment is stored as a JSONB row, scoped by project name. Deleted environments are hard-deleted from the database. Run RunMigrations before first use to ensure the schema is up to date.

func NewPostgresStateAdapter

func NewPostgresStateAdapter(dsn, project string) (*PostgresStateAdapter, error)

NewPostgresStateAdapter creates a new Postgres-backed state adapter. The dsn should be a valid PostgreSQL connection string. The project name scopes state so multiple projects can share one database. The caller should run RunMigrations separately (via `previewctl migrate`) before using the adapter for the first time.

func (*PostgresStateAdapter) Close

func (a *PostgresStateAdapter) Close() error

Close closes the underlying database connection.

func (*PostgresStateAdapter) GetEnvironment

func (a *PostgresStateAdapter) GetEnvironment(ctx context.Context, name string) (*domain.EnvironmentEntry, error)

func (*PostgresStateAdapter) Load

func (*PostgresStateAdapter) RemoveEnvironment

func (a *PostgresStateAdapter) RemoveEnvironment(ctx context.Context, name string) error

func (*PostgresStateAdapter) Save

func (a *PostgresStateAdapter) Save(ctx context.Context, state *domain.State) error

func (*PostgresStateAdapter) SetEnvironment

func (a *PostgresStateAdapter) SetEnvironment(ctx context.Context, name string, entry *domain.EnvironmentEntry) error

Jump to

Keyboard shortcuts

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