dbinitiator

package module
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 26 Imported by: 1

README

testdb

Documentation

Overview

Implements tooling to setup a Spanner database configured for running integration tests against.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSpannerInstance

func NewSpannerInstance(ctx context.Context, projectID, instanceID string, opts ...option.ClientOption) error

NewSpannerInstance creates a spanner instance. This is intended for use with a spanner emulator.

func PostgresConnStr added in v0.1.2

func PostgresConnStr(username, password, host, port, database string) string

Types

type PostgresContainer added in v0.1.2

type PostgresContainer struct {
	testcontainers.Container
	// contains filtered or unexported fields
}

PostgresContainer represents a docker container running a postgres instance.

func NewPostgresContainer added in v0.1.2

func NewPostgresContainer(ctx context.Context, imageVersion string) (*PostgresContainer, error)

NewPostgresContainer returns a new PostgresContainer ready to use with postgres.

func (*PostgresContainer) Close added in v0.1.2

func (pc *PostgresContainer) Close()

Close closes all connections to the postgres instance

func (*PostgresContainer) CreateDatabase added in v0.1.2

func (pc *PostgresContainer) CreateDatabase(ctx context.Context, dbName string) (*PostgresDatabase, error)

CreateDatabase creates a new database with the given name and returns a connection to it.

type PostgresDatabase added in v0.1.2

type PostgresDatabase struct {
	*pgxpool.Pool
	// contains filtered or unexported fields
}

PostgresDatabase represents a postgres database created and ready for migrations

func NewPostgresDatabase added in v0.1.2

func NewPostgresDatabase(ctx context.Context, username, password, host, port, databaseToCreate, schemaToCreate string) (*PostgresDatabase, error)

NewPostgresDatabase creates a new database and schema, then connects to it.

func (*PostgresDatabase) Close added in v0.1.2

func (db *PostgresDatabase) Close()

Close closes the database connection

func (*PostgresDatabase) MigrateDown added in v0.1.2

func (db *PostgresDatabase) MigrateDown(sourceURL string) error

MigrateDown will migrate all the way down

func (*PostgresDatabase) MigrateUp added in v0.1.2

func (db *PostgresDatabase) MigrateUp(sourceURL ...string) error

MigrateUp will migrate all the way up, applying all up migrations from all sourceURL's

func (*PostgresDatabase) Schema added in v0.1.2

func (db *PostgresDatabase) Schema() string

Schema returns the default schema

type PostgresMigrationService added in v0.2.9

type PostgresMigrationService struct {
	// contains filtered or unexported fields
}

PostgresMigrationService implements the MigrationService interface for PostgreSQL.

func ConnectToPostgres added in v0.2.9

func ConnectToPostgres(username, password, host, port, database string) (*PostgresMigrationService, error)

ConnectToPostgres connects to an existing postgres database using structured parameters. It does not attempt to create the database or schema. It returns a PostgresMigrationService which can be used to run migrations.

func (*PostgresMigrationService) MigrateUp added in v0.2.9

func (p *PostgresMigrationService) MigrateUp(sourceURL string) error

MigrateUp will migrate all the way up, applying all up migrations from the sourceURL

type SpannerContainer

type SpannerContainer struct {
	testcontainers.Container
	// contains filtered or unexported fields
}

SpannerContainer represents a docker container running a spanner instance.

func NewSpannerContainer

func NewSpannerContainer(ctx context.Context, imageVersion string) (*SpannerContainer, error)

NewSpannerContainer returns a initialized SpannerContainer ready to run to create databases for unit tests

func (*SpannerContainer) Close

func (sc *SpannerContainer) Close() error

Close cleans up open resouces

func (*SpannerContainer) CreateDatabase added in v0.2.0

func (sc *SpannerContainer) CreateDatabase(ctx context.Context, dbName string) (*SpannerDB, error)

CreateDatabase creates a database with dbName. Each test should create their own database for testing

type SpannerDB

type SpannerDB struct {
	*spanner.Client
	// contains filtered or unexported fields
}

SpannerDB represents a database created and ready for migrations

func NewSpannerDatabase

func NewSpannerDatabase(ctx context.Context, projectID, instanceID, dbName string, opts ...option.ClientOption) (*SpannerDB, error)

NewSpannerDatabase will create a spanner database

func (*SpannerDB) Close

func (db *SpannerDB) Close() error

func (*SpannerDB) DropDatabase

func (db *SpannerDB) DropDatabase(ctx context.Context) error

func (*SpannerDB) MigrateDown

func (db *SpannerDB) MigrateDown(sourceURL string) error

MigrateDown will migrate all the way down

func (*SpannerDB) MigrateUp

func (db *SpannerDB) MigrateUp(sourceURL ...string) error

MigrateUp will migrate all the way up, applying all up migrations from all sourceURL's

type SpannerMigrationService added in v0.2.9

type SpannerMigrationService struct {
	// contains filtered or unexported fields
}

SpannerMigrationService implements the MigrationService interface for Spanner.

func ConnectToSpanner added in v0.2.9

func ConnectToSpanner(ctx context.Context, projectID, instanceID, dbName string, opts ...option.ClientOption) (*SpannerMigrationService, error)

ConnectToSpanner connects to an existing spanner database and returns a SpannerMigrationService.

func (*SpannerMigrationService) Close added in v0.2.9

func (s *SpannerMigrationService) Close() error

Close closes the SpannerMigrationService admin client if necessary.

func (*SpannerMigrationService) MigrateUp added in v0.2.9

func (s *SpannerMigrationService) MigrateUp(sourceURL string) error

MigrateUp will migrate all the way up, applying all up migrations from the sourceURL

Jump to

Keyboard shortcuts

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