Documentation
¶
Index ¶
- Variables
- func DisableForeignKeysAndTriggers(t *testing.T, db database.Store)deprecated
- func DumpOnFailure(t testing.TB, connectionURL string)
- func NewDB(t testing.TB, opts ...Option) (database.Store, pubsub.Pubsub)
- func NewDBWithSQLDB(t testing.TB, opts ...Option) (database.Store, pubsub.Pubsub, *sql.DB)
- func NowInDefaultTimezone() time.Time
- func Open(t TBSubset, opts ...OpenOption) (string, error)
- func OpenContainerized(t TBSubset, opts DBContainerOptions) (string, func(), error)
- func PGDump(dbURL string) ([]byte, error)
- func PGDumpSchemaOnly(dbURL string) ([]byte, error)
- func WillUsePostgres() bool
- type ConnectionParams
- type Connector
- type DBContainerOptions
- type DBTx
- type Driver
- type OpenOption
- type OpenOptions
- type Option
- type TBSubset
Constants ¶
This section is empty.
Variables ¶
var DefaultTimezone = "Canada/Newfoundland"
Functions ¶
func DisableForeignKeysAndTriggers
deprecated
added in
v2.19.0
func DumpOnFailure ¶ added in v2.2.0
DumpOnFailure exports the database referenced by connectionURL to a file corresponding to the current test, with a suffix indicating the time the test was run. To import this into a new database (assuming you have already run make test-postgres-docker):
- Create a new test database: go run ./scripts/migrate-ci/main.go and note the database name it outputs
- Import the file into the above database: psql 'postgres://postgres:[email protected]:5432/<dbname>?sslmode=disable' -f <path to file.test.sql>
- Run a dev server against that database: ./scripts/coder-dev.sh server --postgres-url='postgres://postgres:[email protected]:5432/<dbname>?sslmode=disable'
func NewDBWithSQLDB ¶ added in v2.3.1
func NowInDefaultTimezone ¶ added in v2.19.0
NowInDefaultTimezone returns the current time rounded to the nearest microsecond in the default timezone used by postgres in tests. Useful for object equality checks.
func Open ¶ added in v2.10.0
func Open(t TBSubset, opts ...OpenOption) (string, error)
Open creates a new PostgreSQL database instance. If there's a database running at localhost:5432, it will use that. Otherwise, it will start a new postgres container.
func OpenContainerized ¶ added in v2.10.0
func OpenContainerized(t TBSubset, opts DBContainerOptions) (string, func(), error)
OpenContainerized creates a new PostgreSQL server using a Docker container. If port is nonzero, forward host traffic to that port to the database. If port is zero, allocate a free port from the OS. The user is responsible for calling the returned cleanup function.
func PGDump ¶ added in v2.11.0
PGDump runs pg_dump against dbURL and returns the output. It is used by DumpOnFailure().
func PGDumpSchemaOnly ¶ added in v2.11.0
PGDumpSchemaOnly is for use by gen/dump only. It runs pg_dump against dbURL and sets a consistent timezone and encoding.
func WillUsePostgres ¶
func WillUsePostgres() bool
WillUsePostgres returns true if a call to NewDB() will return a real, postgres-backed Store and Pubsub.
Types ¶
type ConnectionParams ¶ added in v2.18.0
type ConnectionParams struct { Username string Password string Host string Port string DBName string }
func (ConnectionParams) DSN ¶ added in v2.18.0
func (p ConnectionParams) DSN() string
type Connector ¶ added in v2.15.0
type Connector struct {
// contains filtered or unexported fields
}
type DBContainerOptions ¶ added in v2.18.0
type DBTx ¶ added in v2.17.0
type OpenOption ¶ added in v2.18.0
type OpenOption func(*OpenOptions)
func WithDBFrom ¶ added in v2.18.0
func WithDBFrom(dbFrom string) OpenOption
WithDBFrom sets the template database to use when creating a new database. Overrides the DB_FROM environment variable.
type OpenOptions ¶ added in v2.18.0
type OpenOptions struct {
DBFrom *string
}
type Option ¶ added in v2.2.0
type Option func(*options)
func WithDumpOnFailure ¶ added in v2.2.0
func WithDumpOnFailure() Option
WithDumpOnFailure will dump the entire database on test failure.
func WithLogger ¶ added in v2.8.0
func WithTimezone ¶ added in v2.2.0
WithTimezone sets the database to the defined timezone.