pgdevserver

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: MIT Imports: 27 Imported by: 0

README

pgdevserver

Pgdevserver is a command line tool for managing ephemeral postgres servers in a development environment.

When you start a server, pgdevserver will:

  • If an existing server meets your requirements it outputs a that server's connection url and exits.
  • Checks for the necessary postgres binaries and downloads them if required.
  • Creates and starts a new server.
  • Outputs a connection url for the new server.

Install

With bindown
bindown template-source add pgdevserver https://github.com/WillAbides/pgdevserver/releases/latest/download/bindown.yaml
bindown dependency add pgdevserver --source pgdevserver -y
With Go
go install github.com/willabides/pgdevserver@latest
From Releases

Download the latest release for your platform, extract and do whatever you normally do with a binary.

Usage

Usage: pgdevserver <command> [flags]

Flags:
  -h, --help    Show context-sensitive help.

Commands:
  start [flags]
    Start a server.

  create [flags]
    Create a server without starting it.

  list [flags]
    List servers.

  stop [flags]
    Stop a server.

  rm [flags]
    Remove a server.

  pg list [flags]
    List installed postgres versions.

  pg available [flags]
    List postgres versions available to download.

  pg install <version> [flags]
    Install a postgres version.

  pg rm <version> [flags]
    Remove a postgres version.

Run "pgdevserver <command> --help" for more information on a command.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// PostgresVersion is the version of the postgres binaries to use. Default is "17.2.0"
	PostgresVersion string `json:"postgres_version,omitempty"`

	// CacheDir is the directory containing the cache. Default is pgdevserver under the xdg cache directory
	CacheDir string `json:"-"`

	// Name is a way to distinguish between multiple servers that otherwise have the same configuration.
	// Default is "default".
	Name string `json:"name,omitempty"`

	// PostgresOptions are additional options to pass to postgres on startup.
	PostgresOptions []string `json:"postgres_options,omitempty"`

	// InitDBArgs are additional arguments to pass to initdb when creating the cluster.
	InitDBArgs []string `json:"init_db_args,omitempty"`

	// Port is the port to use for the cluster. If empty, a random port will be selected.
	Port string `json:"port,omitempty"`

	// PGManager is the PGManager to use for installing postgres. If nil, a default PGManager will be used.
	PGManager *PGManager
}

type PGMConfig

type PGMConfig struct {
	// MavenURL is the base URL for maven repositories. Default is https://repo1.maven.org/maven2.
	MavenURL string

	// CacheDir is the directory containing the cache. Default is pgm under the xdg cache directory
	CacheDir string

	// HTTPClient is the http client to use for downloading files.
	HTTPClient *http.Client
}

type PGManager

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

func NewPGManager

func NewPGManager(cfg PGMConfig) *PGManager

func (*PGManager) AvailableVersions

func (m *PGManager) AvailableVersions(ctx context.Context) ([]string, error)

AvailableVersions returns a list of available versions of postgres

func (*PGManager) Bin

func (m *PGManager) Bin(ctx context.Context, version string) (binDir string, unlock func() error, _ error)

Bin obtains a read lock for the given version and returns a path to the bin directory. The caller must call the returned unlock function when done with the bin directory. Use this to run pg_ctl, initdb, etc.

func (*PGManager) Install

func (m *PGManager) Install(ctx context.Context, version string) error

Install assures that the given version of postgres is installed

func (*PGManager) InstalledVersions

func (m *PGManager) InstalledVersions() ([]string, error)

InstalledVersions returns a list of installed postgres versions

func (*PGManager) Remove added in v0.1.0

func (m *PGManager) Remove(version string) error

type Server

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

func New

func New(cfg Config) *Server

func ServerFromCache

func ServerFromCache(rootCache, id string) (_ *Server, errOut error)

ServerFromCache returns a server from the cache by ID.

func ServersFromCache

func ServersFromCache(cacheDir string) ([]*Server, error)

ServersFromCache returns all the servers in the cache.

func (*Server) Config

func (s *Server) Config() Config

Config returns the configuration of the server after it has been initialized with defaults.

func (*Server) ConnectionURL

func (s *Server) ConnectionURL(ctx context.Context) (string, error)

ConnectionURL returns the current connection URL of this server. When using dynamic ports, the ConnectionURL could change each time the server is started from a stopped state.

func (*Server) Create added in v0.2.0

func (s *Server) Create(ctx context.Context) error

func (*Server) ID

func (s *Server) ID() string

ID returns a unique identifier for the server within the cache.

func (*Server) Logfile

func (s *Server) Logfile(ctx context.Context) (string, error)

Logfile returns the path to the log file for the server. The log file is created the first time the server is started.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

func (*Server) Status

func (s *Server) Status(ctx context.Context) (Status, error)

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

type Status

type Status int
const (
	StatusUnknown Status = iota
	StatusStopped
	StatusRunning
	StatusInvalid
)

func (Status) String

func (s Status) String() string

Directories

Path Synopsis
cmd
pgdevserver command

Jump to

Keyboard shortcuts

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