Documentation ¶
Index ¶
- Variables
- func IsUsed(md *meta.Data) bool
- func OneshotProxy(appSlug, envSlug string) (port int, passwd string, err error)
- func WaitForConn(ctx context.Context, uri string) error
- type Cluster
- func (c *Cluster) GetDB(name string) (*DB, bool)
- func (c *Cluster) Info(ctx context.Context) (*ClusterInfo, error)
- func (c *Cluster) Ready() <-chan struct{}
- func (c *Cluster) Recreate(ctx context.Context, appRoot string, services []string, md *meta.Data) error
- func (c *Cluster) Setup(ctx context.Context, appRoot string, md *meta.Data) error
- func (c *Cluster) SetupAndMigrate(ctx context.Context, appRoot string, md *meta.Data) error
- func (c *Cluster) Start(ctx context.Context) (*ClusterStatus, error)
- func (c *Cluster) Status(ctx context.Context) (*ClusterStatus, error)
- func (c *Cluster) Stop()
- type ClusterID
- type ClusterInfo
- type ClusterManager
- func (cm *ClusterManager) Create(ctx context.Context, params *CreateParams) *Cluster
- func (cm *ClusterManager) Get(id ClusterID) (*Cluster, bool)
- func (cm *ClusterManager) LookupPassword(password string) (*Cluster, bool)
- func (cm *ClusterManager) PreauthProxyConn(client net.Conn, id ClusterID) error
- func (cm *ClusterManager) ProxyConn(client net.Conn, waitForSetup bool) error
- func (cm *ClusterManager) ServeProxy(ln net.Listener) error
- type ClusterStatus
- type ClusterType
- type ConnConfig
- type CreateParams
- type DB
- func (db *DB) CloseConns()
- func (db *DB) Create(ctx context.Context) error
- func (db *DB) Drop(ctx context.Context) error
- func (db *DB) EnsureRoles(ctx context.Context, roles ...Role) error
- func (db *DB) Migrate(ctx context.Context, appRoot string, svc *meta.Service) (err error)
- func (db *DB) Ready() <-chan struct{}
- func (db *DB) Setup(ctx context.Context, appRoot string, svc *meta.Service, migrate, recreate bool) (err error)
- type Driver
- type EncoreRoles
- type Role
- type RoleType
- type Status
- type WebsocketLogicalConn
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupported = errors.New("unsupported operation")
Functions ¶
func OneshotProxy ¶
OneshotProxy listens on a random port for a single connection, and proxies that connection to a remote db. It reports the one-time password and port to use. Once a connection has been established, it stops listening.
Types ¶
type Cluster ¶
type Cluster struct { ID ClusterID // cluster ID Memfs bool // use an in-memory filesystem? Password string // randomly generated password for this cluster Roles EncoreRoles // set by Start // Ctx is canceled when the cluster is being torn down. Ctx context.Context // contains filtered or unexported fields }
Cluster represents a running database Cluster.
func (*Cluster) Info ¶ added in v1.1.0
func (c *Cluster) Info(ctx context.Context) (*ClusterInfo, error)
Info reports information about a cluster.
func (*Cluster) Ready ¶
func (c *Cluster) Ready() <-chan struct{}
Ready returns a channel that is closed when the cluster is up and running.
func (*Cluster) Recreate ¶
func (c *Cluster) Recreate(ctx context.Context, appRoot string, services []string, md *meta.Data) error
Recreate recreates the databases for the given services. If services is the nil slice it recreates all databases.
func (*Cluster) SetupAndMigrate ¶ added in v1.1.0
SetupAndMigrate creates and migrates the given databases.
func (*Cluster) Start ¶
func (c *Cluster) Start(ctx context.Context) (*ClusterStatus, error)
Start creates the cluster if necessary and starts it. If the cluster is already running it does nothing.
type ClusterID ¶ added in v1.3.0
type ClusterID struct { App *apps.Instance Type ClusterType }
ClusterID uniquely identifies a cluster.
func GetClusterID ¶ added in v1.3.0
func GetClusterID(app *apps.Instance, typ ClusterType) ClusterID
type ClusterInfo ¶ added in v1.1.0
type ClusterInfo struct { *ClusterStatus // Encore contains the roles to use to connect for an Encore app. // It is set if and only if the cluster is running. Encore EncoreRoles }
ClusterInfo returns information about a cluster.
type ClusterManager ¶
type ClusterManager struct {
// contains filtered or unexported fields
}
A ClusterManager manages running local sqldb clusters.
func NewClusterManager ¶
func NewClusterManager(driver Driver) *ClusterManager
NewClusterManager creates a new ClusterManager.
func (*ClusterManager) Create ¶ added in v1.1.0
func (cm *ClusterManager) Create(ctx context.Context, params *CreateParams) *Cluster
Create creates a database cluster but does not start it. If the cluster already exists it is returned. It does not perform any database migrations.
func (*ClusterManager) Get ¶
func (cm *ClusterManager) Get(id ClusterID) (*Cluster, bool)
Get retrieves the cluster keyed by id.
func (*ClusterManager) LookupPassword ¶ added in v1.3.0
func (cm *ClusterManager) LookupPassword(password string) (*Cluster, bool)
LookupPassword looks up a cluster based on its password.
func (*ClusterManager) PreauthProxyConn ¶
func (cm *ClusterManager) PreauthProxyConn(client net.Conn, id ClusterID) error
PreauthProxyConn is a pre-authenticated proxy conn directly specifically to the given cluster.
func (*ClusterManager) ProxyConn ¶
func (cm *ClusterManager) ProxyConn(client net.Conn, waitForSetup bool) error
ProxyConn authenticates and proxies a conn to the appropriate database cluster and database. If waitForSetup is true, it will wait for initial setup to complete before proxying the connection.
func (*ClusterManager) ServeProxy ¶
func (cm *ClusterManager) ServeProxy(ln net.Listener) error
ServeProxy serves the database proxy using the given listener.
type ClusterStatus ¶
type ClusterStatus struct { // Status is the status of the underlying container. Status Status // Config is how to connect to the cluster. // It is non-nil if Status == Running. Config *ConnConfig }
ClusterStatus represents the status of a database cluster.
type ClusterType ¶ added in v1.3.0
type ClusterType string
const ( Run ClusterType = "run" Test ClusterType = "test" )
type ConnConfig ¶ added in v1.1.0
type ConnConfig struct { // Host is the host address to connect to the database. // It is only set when Status == Running. Host string // Superuser is the role to use to connect as the superuser, // for creating and managing Encore databases. Superuser Role RootDatabase string // root database to connect to }
type CreateParams ¶ added in v1.1.0
type CreateParams struct { ClusterID ClusterID // Memfs, if true, configures the database container to use an // in-memory filesystem as opposed to persisting the database to disk. Memfs bool }
CreateParams are the params to (*ClusterManager).Create.
type DB ¶
type DB struct { Name string // database name Cluster *Cluster // Ctx is canceled when the database is being torn down. Ctx context.Context // contains filtered or unexported fields }
DB represents a single database instance within a cluster.
func (*DB) CloseConns ¶
func (db *DB) CloseConns()
CloseConns closes all connections to this database through the dbproxy, and prevents future ones from being established.
func (*DB) Create ¶
Create creates the database in the cluster if it does not already exist. It reports whether the database was initialized for the first time in this process.
func (*DB) EnsureRoles ¶ added in v1.1.0
EnsureRoles ensures the roles have been granted access to this database.
type Driver ¶ added in v1.1.0
type Driver interface { // CreateCluster creates (if necessary) and starts (if necessary) a new cluster using the driver, // and returns its status. // err is nil if and only if the cluster could not be started. CreateCluster(ctx context.Context, p *CreateParams, log zerolog.Logger) (*ClusterStatus, error) // DestroyCluster destroys a cluster with the given id. // If a Driver doesn't support destroying the cluster it reports ErrUnsupported. DestroyCluster(ctx context.Context, id ClusterID) error // ClusterStatus reports the current status of a cluster. ClusterStatus(ctx context.Context, id ClusterID) (*ClusterStatus, error) }
A Driver abstracts away how a cluster is actually operated.
type EncoreRoles ¶ added in v1.1.0
type EncoreRoles []Role
EncoreRoles describes the credentials to use when connecting to the cluster as an Encore user.
func (EncoreRoles) Admin ¶ added in v1.1.0
func (roles EncoreRoles) Admin() (Role, bool)
func (EncoreRoles) First ¶ added in v1.1.0
func (roles EncoreRoles) First(typs ...RoleType) (Role, bool)
func (EncoreRoles) Read ¶ added in v1.1.0
func (roles EncoreRoles) Read() (Role, bool)
func (EncoreRoles) Superuser ¶ added in v1.1.0
func (roles EncoreRoles) Superuser() (Role, bool)
func (EncoreRoles) Write ¶ added in v1.1.0
func (roles EncoreRoles) Write() (Role, bool)
type WebsocketLogicalConn ¶ added in v0.18.0
func (*WebsocketLogicalConn) Cancel ¶ added in v0.18.0
func (c *WebsocketLogicalConn) Cancel(req *pgproxy.CancelData) error
func (*WebsocketLogicalConn) Read ¶ added in v0.18.0
func (c *WebsocketLogicalConn) Read(p []byte) (int, error)
func (*WebsocketLogicalConn) SetDeadline ¶ added in v0.18.0
func (c *WebsocketLogicalConn) SetDeadline(t time.Time) error