database

package
v0.0.0-...-832224e Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const SqlDbVersionTableAlter1 = "ALTER TABLE db_version ADD COLUMN code_version_string TEXT"
View Source
const SqlDbVersionTableCreate = "" /* 211-byte string literal not displayed */

tables

Variables

Functions

func AssertIndex

func AssertIndex(t *testing.T, tableName string, wantIndexName string, wantDefinition string, indexes IndexSearchResult)

AssertIndex validates that the index exists

func AssertTableColumnsEqual

func AssertTableColumnsEqual(t *testing.T, want *TableColumn, actual *TableColumn)

AssertTableColumnsEqual is well-named

func CheckDatabaseExistsWithNewConnection

func CheckDatabaseExistsWithNewConnection(dbname string) bool

CheckDatabaseExistsWithNewConnection is well-named

func CheckTableExists

func CheckTableExists(db *sql.DB, tableName string) bool

CheckTableExists is well-named

func ConnectInitializedDatabase

func ConnectInitializedDatabase(postgresDbConfig *postgresdb.Config, upgradeScripts []*UpgradeScript, codeVersionString string) (*sql.DB, error)

ConnectInitializedDatabase creates a database with the required metadata tables

func GetNumTablesInDb

func GetNumTablesInDb(db *sql.DB) int

GetNumTablesInDb is well-named

func PostTestWithDbClose

func PostTestWithDbClose(db *sql.DB, dbname string)

PostTestWithDbClose logic for tests related to db upgrades

func PreTest

func PreTest(t *testing.T) (*sql.DB, string)

PreTest logic for tests related to db upgrades

func QueryAllRows

func QueryAllRows(db *sql.DB, tableName string) [][]interface{}

QueryAllRows queries all the rows of a given table in a database

func QueryDbVersion

func QueryDbVersion(db *sql.DB) (uint32, error)
query helper functions

QueryDbVersion queries for the version of the database

func RunUpgradeScripts

func RunUpgradeScripts(db *sql.DB, scripts []*UpgradeScript, codeVersionString string) error

RunUpgradeScripts is a utility function that can be run from outside this package so we need to export it

func ValidateDBVersionRow

func ValidateDBVersionRow(
	t *testing.T,
	actualRow []interface{},
	wantVersion int,
	wantDateCompletedUTC time.Time,
	wantNumScripts int,
	wantTimeElapsedMillis int,
	wantCodeVersionString *string,
)

ValidateDBVersionRow is well-named

Types

type IndexSearchResult

type IndexSearchResult map[string]string

IndexSearchResult captures the result from GetTableIndexes() and is used as input to AssertIndex()

func GetTableIndexes

func GetTableIndexes(db *sql.DB, tableName string) IndexSearchResult

GetTableIndexes is well-named

type TableColumn

type TableColumn struct {
	ColumnName             string      // `db:"column_name"`
	OrdinalPosition        int         // `db:"ordinal_position"`
	ColumnDefault          interface{} // `db:"column_default"`
	IsNullable             string      // `db:"is_nullable"`        // uses "YES" / "NO" instead of a boolean
	DataType               string      // `db:"data_type"`
	CharacterMaximumLength interface{} // `db:"character_maximum_length"`
}

TableColumn is a column in a table specefied generically

func GetTableSchema

func GetTableSchema(db *sql.DB, tableName string) []TableColumn

GetTableSchema is well-named

type UpgradeScript

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

UpgradeScript encapsulates a script to be run to upgrade the database from one version to the next

func MakeUpgradeScript

func MakeUpgradeScript(version uint32, command string, moreCommands ...string) *UpgradeScript

MakeUpgradeScript encapsulates a script to be run to upgrade the database from one version to the next

Jump to

Keyboard shortcuts

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