Documentation
¶
Index ¶
- Constants
- Variables
- func HasDevMigrations() bool
- func IsDeadlockError(err error) bool
- func IsSchemaError(err error) bool
- func IsSerializationError(err error) bool
- func IsSerializationOrDeadlockError(err error) bool
- func MakeTestMigrationSets() []sqldb.MigrationSet
- func MapSQLError(err error) error
- func NewTestPostgresDB(t *testing.T) *sqldb.PostgresStore
- func UseLogger(logger btclog.Logger)
- type ErrDeadlockError
- type ErrSchemaError
- type ErrSerializationError
- type ErrSqlUniqueConstraintViolation
- type PostgresConfig
- type QueriesTxOptions
- type SqliteConfig
- type TestPgFixture
Constants ¶
const ( // LatestMigrationVersion is the latest migration version of the // database. This is used to implement downgrade protection for the // daemon. // // NOTE: This MUST be updated when a new migration is added. // // TODO: On the next update, when the migration version is updated // be beyond version 6, make sure that the default // `SkipMigrationDbBackup` value for Sqlite is set to false. LatestMigrationVersion = 6 // KVDBtoSQLMigVersion is the version of the migration that migrates the // kvdb to the sql database. // // NOTE: This version value should not be updated when a new migration // is added, as this represents a specific migration. KVDBtoSQLMigVersion = 6 // LatestDevMigrationVersion is the latest dev migration version of the // database. This is used to implement downgrade protection for the // daemon. This represents the latest number used in the migrations_dev // directory. // // NOTE: This MUST be updated when a migration is added or removed, from // the migrations_dev directory. LatestDevMigrationVersion = 0 )
const (
PostgresTag = "15"
)
const Subsystem = "SQLD"
Variables ¶
var ( // DefaultPostgresFixtureLifetime is the default maximum time a Postgres // test fixture is being kept alive. After that time the docker // container will be terminated forcefully, even if the tests aren't // fully executed yet. So this time needs to be chosen correctly to be // longer than the longest expected individual test run time. DefaultPostgresFixtureLifetime = 60 * time.Minute )
var ( // ErrRetriesExceeded is returned when a transaction is retried more // than the max allowed valued without a success. ErrRetriesExceeded = errors.New("db tx retries exceeded") )
var SqlSchemas embed.FS
Functions ¶
func HasDevMigrations ¶
func HasDevMigrations() bool
HasDevMigrations reports whether any dev SQL migration files are embedded in the current build. This lets dev builds omit the separate dev migration set cleanly when the directory exists but currently contains no migration files.
func IsDeadlockError ¶
IsDeadlockError returns true if the given error is a deadlock error.
func IsSchemaError ¶
IsSchemaError returns true if the given error is a schema error.
func IsSerializationError ¶
IsSerializationError returns true if the given error is a serialization error.
func IsSerializationOrDeadlockError ¶
IsSerializationOrDeadlockError returns true if the given error is either a deadlock error or a serialization error.
func MakeTestMigrationSets ¶
func MakeTestMigrationSets() []sqldb.MigrationSet
MakeTestMigrationSets creates the migration sets for the unit test environment.
NOTE: This function is not located in the migsets package to avoid cyclic dependencies. This test migration set does not run the kvdb to sql migration, as we already have separate unit tests which tests the migration.
func MapSQLError ¶
MapSQLError attempts to interpret a given error as a database agnostic SQL error.
func NewTestPostgresDB ¶
func NewTestPostgresDB(t *testing.T) *sqldb.PostgresStore
NewTestPostgresDB is a helper function that creates a Postgres database for testing.
Types ¶
type ErrDeadlockError ¶
type ErrDeadlockError struct {
DbError error
}
ErrDeadlockError is an error type which represents a database agnostic error where transactions have led to cyclic dependencies in lock acquisition.
func (ErrDeadlockError) Error ¶
func (e ErrDeadlockError) Error() string
Error returns the error message.
func (ErrDeadlockError) Unwrap ¶
func (e ErrDeadlockError) Unwrap() error
Unwrap returns the wrapped error.
type ErrSchemaError ¶
type ErrSchemaError struct {
DbError error
}
ErrSchemaError is an error type which represents a database agnostic error that the schema of the database is incorrect for the given query.
func (ErrSchemaError) Error ¶
func (e ErrSchemaError) Error() string
Error returns the error message.
func (ErrSchemaError) Unwrap ¶
func (e ErrSchemaError) Unwrap() error
Unwrap returns the wrapped error.
type ErrSerializationError ¶
type ErrSerializationError struct {
DbError error
}
ErrSerializationError is an error type which represents a database agnostic error that a transaction couldn't be serialized with other concurrent db transactions.
func (ErrSerializationError) Error ¶
func (e ErrSerializationError) Error() string
Error returns the error message.
func (ErrSerializationError) Unwrap ¶
func (e ErrSerializationError) Unwrap() error
Unwrap returns the wrapped error.
type ErrSqlUniqueConstraintViolation ¶
type ErrSqlUniqueConstraintViolation struct {
DbError error
}
ErrSqlUniqueConstraintViolation is an error type which represents a database agnostic SQL unique constraint violation.
func (ErrSqlUniqueConstraintViolation) Error ¶
func (e ErrSqlUniqueConstraintViolation) Error() string
type PostgresConfig ¶
type PostgresConfig struct {
SkipMigrations bool `long:"skipmigrations" description:"Skip applying migrations on startup."`
Host string `long:"host" description:"Database server hostname."`
Port int `long:"port" description:"Database server port."`
User string `long:"user" description:"Database user."`
Password string `long:"password" description:"Database user's password."`
DBName string `long:"dbname" description:"Database name to use."`
MaxOpenConnections int `long:"maxconnections" description:"Max open connections to keep alive to the database server."`
MaxIdleConnections int `long:"maxidleconnections" description:"Max number of idle connections to keep in the connection pool."`
ConnMaxLifetime time.Duration `` /* 139-byte string literal not displayed */
ConnMaxIdleTime time.Duration `` /* 137-byte string literal not displayed */
RequireSSL bool `long:"requiressl" description:"Whether to require using SSL (mode: require) when connecting to the server."`
}
PostgresConfig holds the postgres database configuration.
nolint:ll
func (*PostgresConfig) DSN ¶
func (s *PostgresConfig) DSN(hidePassword bool) string
DSN returns the dns to connect to the database.
type QueriesTxOptions ¶
type QueriesTxOptions struct {
// contains filtered or unexported fields
}
QueriesTxOptions defines the set of db txn options the SQLQueries understands.
func NewQueryReadTx ¶
func NewQueryReadTx() QueriesTxOptions
NewQueryReadTx creates a new read transaction option set.
func (*QueriesTxOptions) ReadOnly ¶
func (a *QueriesTxOptions) ReadOnly() bool
ReadOnly returns true if the transaction should be read only.
NOTE: This implements the TxOptions.
type SqliteConfig ¶
type SqliteConfig struct {
// SkipMigrations if true, then all the tables will be created on start
// up if they don't already exist.
SkipMigrations bool `long:"skipmigrations" description:"Skip applying migrations on startup."`
// SkipMigrationDbBackup if true, then a backup of the database will not
// be created before applying migrations.
SkipMigrationDbBackup bool `long:"skipmigrationdbbackup" description:"Skip creating a backup of the database before applying migrations."`
// DatabaseFileName is the full file path where the database file can be
// found.
DatabaseFileName string `long:"dbfile" description:"The full path to the database."`
}
SqliteConfig holds all the config arguments needed to interact with our sqlite DB.
nolint:ll
type TestPgFixture ¶
type TestPgFixture struct {
// contains filtered or unexported fields
}
TestPgFixture is a test fixture that starts a Postgres 11 instance in a docker container.
func NewTestPgFixture ¶
NewTestPgFixture constructs a new TestPgFixture starting up a docker container running Postgres 11. The started container will expire in after the passed duration.
func (*TestPgFixture) ClearDB ¶
func (f *TestPgFixture) ClearDB(t *testing.T)
ClearDB clears the database.
func (*TestPgFixture) GetConfig ¶
func (f *TestPgFixture) GetConfig() *PostgresConfig
GetConfig returns the full config of the Postgres node.
func (*TestPgFixture) GetDSN ¶
func (f *TestPgFixture) GetDSN() string
GetDSN returns the DSN (Data Source Name) for the started Postgres node.
func (*TestPgFixture) TearDown ¶
func (f *TestPgFixture) TearDown(t *testing.T)
TearDown stops the underlying docker container.