database

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package database provides functions to migrate the database.

Index

Constants

View Source
const (
	// DBName is the name of the test database
	DBName = "testdb"
	// DBUser is the username for the root user of the test database
	DBUser = "testuser"
	// DBPass is the password for the root user of the test database
	DBPass = "testpass"
)

Variables

This section is empty.

Functions

func GetMigrate

func GetMigrate(connString string) (*migrate.Migrate, error)

GetMigrate creates a new migrate instance using the embedded migrations

func GetPrimeTemplate added in v0.3.0

func GetPrimeTemplate() ([]byte, error)

GetPrimeTemplate returns the contents of the prime.sql.tmpl template file

func GetVersion

func GetVersion(connString string) (uint, bool, error)

GetVersion returns the current migration version

func MigrateDown

func MigrateDown(_ context.Context, db *pgx.Conn, steps int) error

MigrateDown reverts the last migration

func MigrateUp

func MigrateUp(_ context.Context, db *pgx.Conn) error

MigrateUp executes all pending database migrations

func RegisterEnumArrayCodecs added in v1.4.6

func RegisterEnumArrayCodecs(ctx context.Context, conn *pgx.Conn) error

RegisterEnumArrayCodecs registers pgx array codecs for the schema's custom enum types. It is the AfterConnect hook used by both the production connection pool and the test database setup, so both encode enum-array parameters identically.

The codecs are resolved from the live database — the enum OIDs are assigned at migration time — so this must run after migrations, on a connection that can read pg_type.

func SetupTestDB

func SetupTestDB(t *testing.T) (*pgx.Conn, func())

SetupTestDB creates a Postgres container using testcontainers and runs all migrations

func SetupTestDBContainer added in v0.3.0

func SetupTestDBContainer(t *testing.T, ctx context.Context) (*pgx.Conn, func())

SetupTestDBContainer creates a Postgres container using testcontainers and returns a connection to the database

Types

This section is empty.

Jump to

Keyboard shortcuts

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