pgw

package
v0.0.0-...-837eb61 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSrcDbMissing = errors.New("source database does not exist")

Functions

This section is empty.

Types

type AlterRoleQuery

type AlterRoleQuery struct {
	Role            string                 `json:"role"`
	Superuser       bool                   `json:"superuser"`
	NoSuperuser     bool                   `json:"nosuperuser"`
	CreateDB        bool                   `json:"createdb"`
	NoCreateDB      bool                   `json:"nocreatedb"`
	CreateRole      bool                   `json:"createrole"`
	NoCreateRole    bool                   `json:"nocreaterole"`
	CreateUser      bool                   `json:"createuser"`
	NoCreateUser    bool                   `json:"nocreateuser"`
	Inherit         bool                   `json:"inherit"`
	NoInherit       bool                   `json:"noinherit"`
	Login           bool                   `json:"login"`
	NoLogin         bool                   `json:"nologin"`
	Replication     bool                   `json:"replication"`
	NoReplication   bool                   `json:"noreplication"`
	ConnectionLimit int                    `json:"connection_limit"`
	Password        AlterRoleQueryPassword `json:"password"`
}

AlterRoleQuery represents the available options for an ALTER ROLE query

func NewAlterRoleQuery

func NewAlterRoleQuery() *AlterRoleQuery

NewAlterRoleQuery returns a pointer to a new AlterRoleQuery

func (*AlterRoleQuery) String

func (o *AlterRoleQuery) String() string

String returns the options as query

type AlterRoleQueryPassword

type AlterRoleQueryPassword struct {
	Value       string `json:"value"`
	Unencrypted bool   `json:"unencrypted"`
}

AlterRoleQueryPassword represents an ALTER ROLE PASSWORD option

type Client

type Client struct {
	pg.DB
	// contains filtered or unexported fields
}

Client represents the Postgres Sidecar Services database connection

func NewClient

func NewClient(opts ...ClientOpt) (*Client, error)

NewClient takes optional functional arguments and attempts to make a new client.

func (*Client) AlterRole

func (client *Client) AlterRole(query *AlterRoleQuery) error

AlterRole takes a rolename and role options and

func (*Client) Close

func (client *Client) Close() error

Close closes the connection to the database

func (*Client) CreateDB

func (client *Client) CreateDB(db, role string) error

CreateDB takes a database name and role and creates a database

func (*Client) CreateExtension

func (client *Client) CreateExtension(ext string) error

CreateExtension takes a database name and role and creates a database

func (*Client) DeploySqitch

func (client *Client) DeploySqitch(db, dir, user string) error

DeploySqitch takes a connection database name and sqitch directory and runs sqitch

func (*Client) DropTables

func (con *Client) DropTables(query *DropTablesQuery) error

DropTables takes a DropTablesQuery and executes it

func (*Client) MigrateTables

func (client *Client) MigrateTables(from, to string, tables []string, user string, failIfSrcMissing, skipCreate bool) error

MigrateTables migrates tables from a given database to another

func (*Client) RenameDB

func (client *Client) RenameDB(to, from string) error

RenameDB takes an existing database name and a desired name and renames the database if it exists

func (*Client) SetPublicSchemaRole

func (client *Client) SetPublicSchemaRole(role string) error

SetPublicSchemaRole change the owner of all tables in the public and sqitch schemas to the given role name

type ClientOpt

type ClientOpt func(*Client)

ClientOpt are functional arguments used when creating a new connection

func WithDb

func WithDb(db string) ClientOpt

WithDb sets the database connection database

func WithPlatformConfig

func WithPlatformConfig(platformConfig *platform_config.Config) ClientOpt

WithPlatformConfig sets the platform config to use

type DropTablesQuery

type DropTablesQuery struct {
	Tables  []string
	Cascade bool
}

DropTablesQuery represents the available options for an ALTER ROLE query

func NewDropTablesQuery

func NewDropTablesQuery() *DropTablesQuery

NewDropTablesQuery returns a pointer to a new AlterRoleQuery

func (*DropTablesQuery) String

func (q *DropTablesQuery) String() string

String returns the query as SQL

type ErrChan

type ErrChan struct {
	C chan error
	// contains filtered or unexported fields
}

ErrChan is a close() safe error chan

func NewErrChan

func NewErrChan(buffer int) *ErrChan

NewErrChan takes a buffer length and returns a buffered ErrChan

func (*ErrChan) Close

func (c *ErrChan) Close()

Close safely closes the embedded channel once to prevent a panic if it is called multiple times.

type Procedure

type Procedure interface {
	// Ctx returns the context for deadlines and cancellation
	Ctx() context.Context
	// FinishedC returns a channel that will be closed if the procedure
	// completes successfully
	FinishedC() *StructChan
	// ErrC returns a channel which will return an error if the procedure
	// fails
	ErrC() *ErrChan
	// Run runs the procedure's work function
	Run() error
	// Wait takes a timeout waits for the procedure to complete. It will return
	// any error that it encounters on the ErrC or if the timeout is rea
	// an error if the Ctx deadline is reached.
	Wait() error
	// Close performs any cleanup actions that need to be performed
	Close()
}

Procedure in an interface that describes a unit of work that the SerialProcedureRunner can run.

func NewProcedure

func NewProcedure(ctx context.Context, proc func() error) Procedure

NewProcedure takes a request context and procedure work function and returns a runnable procedure

type ProcedureChan

type ProcedureChan struct {
	C chan Procedure
	// contains filtered or unexported fields
}

ProcedureChan is a close() safe SerialProcedure chan

func NewProcedureChan

func NewProcedureChan(buffer int) *ProcedureChan

NewProcedureChan takes a buffer length and returns a buffered ProcedureChan

func (*ProcedureChan) Close

func (c *ProcedureChan) Close()

Close safely closes the embedded channel once to prevent a panic if it is called multiple times.

type SerialProcedureRunner

type SerialProcedureRunner struct {
	C *ProcedureChan
	// contains filtered or unexported fields
}

SerialProcedureRunner runs SerialProcedure's in sequentially and serially. This allows us to queue database operations and wait for them to complete using channels instead of mutexes.

func NewSerialProcedureRunner

func NewSerialProcedureRunner() *SerialProcedureRunner

NewSerialProcedureRunner returns a default SerialProcedureRunner

func (*SerialProcedureRunner) Start

func (r *SerialProcedureRunner) Start()

Start starts the SerialProcedureRunner. It listens on it's channel and processes SerialProcedure's serially without requiring a mutex.

func (*SerialProcedureRunner) Stop

func (r *SerialProcedureRunner) Stop()

Stop terminates the SerialProcedureRunner's processing goroutine

type StructChan

type StructChan struct {
	C chan struct{}
	// contains filtered or unexported fields
}

StructChan is a close() safe struct chan

func NewStructChan

func NewStructChan(buffer int) *StructChan

NewStructChan takes a buffer length and returns a buffered StructChan

func (*StructChan) Close

func (c *StructChan) Close()

Close safely closes the embedded channel once to prevent a panic if it is called multiple times.

Jump to

Keyboard shortcuts

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