Documentation
¶
Index ¶
- Variables
- func IsUsed(md *meta.Data) bool
- func OneshotProxy(appSlug, envSlug string, role RoleType) (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, databaseNames []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, tracker *optracker.OpTracker) (*ClusterStatus, error)
- func (c *Cluster) Status(ctx context.Context) (*ClusterStatus, error)
- func (c *Cluster) Stop()
- type ClusterID
- type ClusterInfo
- type ClusterManager
- func (cm *ClusterManager) CanDeleteNamespace(ctx context.Context, app *apps.Instance, ns *namespace.Namespace) error
- func (cm *ClusterManager) Create(ctx context.Context, params *CreateParams) *Cluster
- func (cm *ClusterManager) DeleteNamespace(ctx context.Context, app *apps.Instance, ns *namespace.Namespace) error
- 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) Ready() error
- func (cm *ClusterManager) ServeProxy(ln net.Listener) error
- type ClusterStatus
- type ClusterType
- type ConnConfig
- type CreateParams
- type DB
- type Driver
- type DriverMeta
- type EncoreRoles
- type MetadataSource
- 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, databaseNames []string, md *meta.Data) error
Recreate recreates the databases for the given database names. If databaseNames 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 ¶
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 {
NS *namespace.Namespace
Type ClusterType
}
ClusterID uniquely identifies a cluster.
func GetClusterID ¶ added in v1.3.0
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 ¶
NewClusterManager creates a new ClusterManager.
func (*ClusterManager) CanDeleteNamespace ¶ added in v1.23.0
func (cm *ClusterManager) CanDeleteNamespace(ctx context.Context, app *apps.Instance, ns *namespace.Namespace) error
CanDeleteNamespace implements namespace.DeletionHandler.
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) DeleteNamespace ¶ added in v1.23.0
func (cm *ClusterManager) DeleteNamespace(ctx context.Context, app *apps.Instance, ns *namespace.Namespace) error
DeleteNamespace implements namespace.DeletionHandler.
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) Ready ¶ added in v1.17.0
func (cm *ClusterManager) Ready() error
Ready reports whether the cluster manager is ready and all requirements are met.
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" Shadow ClusterType = "shadow" Test ClusterType = "test" )
func (ClusterType) Memfs ¶ added in v1.29.0
func (ct ClusterType) Memfs() bool
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
// Tracker allows tracking the progress of the operation.
Tracker *optracker.OpTracker
}
CreateParams are the params to (*ClusterManager).Create.
type DB ¶
type DB struct {
EncoreName string
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) ApplicationCloudName ¶ added in v1.37.0
ApplicationCloudName reports the "cloud name" of the application-facing database.
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) Ready ¶
func (db *DB) Ready() <-chan struct{}
Ready returns a channel that is closed when the database is up and running.
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)
// CanDestroyCluster reports whether the cluster could be destroyed, if desired.
// If a Driver doesn't support destroying the cluster it reports ErrUnsupported.
CanDestroyCluster(ctx context.Context, id ClusterID) 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
// DestroyNamespaceData destroys the data associated with a namespace.
// If a Driver doesn't support destroying data it reports ErrUnsupported.
DestroyNamespaceData(ctx context.Context, ns *namespace.Namespace) error
// ClusterStatus reports the current status of a cluster.
ClusterStatus(ctx context.Context, id ClusterID) (*ClusterStatus, error)
// CheckRequirements checks whether all the requirements are met
// to use the driver.
CheckRequirements(ctx context.Context) error
// Meta reports driver metadata.
Meta() DriverMeta
}
A Driver abstracts away how a cluster is actually operated.
type DriverMeta ¶ added in v1.17.0
type DriverMeta struct {
// ClusterIsolation reports whether clusters are isolated by the driver.
// If false, database names will be prefixed with the cluster id.
ClusterIsolation bool
}
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 MetadataSource ¶ added in v1.43.9
type MetadataSource interface {
source.Driver
Migration(version uint, offset int) (*meta.DBMigration, error)
FilePath(filename string) string
}
func NewMetadataSource ¶ added in v1.43.9
func NewMetadataSource(path string, migrations []*meta.DBMigration) MetadataSource
func NonSequentialMigrator ¶ added in v1.43.9
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