Documentation ¶
Index ¶
- Constants
- Variables
- func AssertIndex(t *testing.T, tableName string, wantIndexName string, wantDefinition string, ...)
- func AssertTableColumnsEqual(t *testing.T, want *TableColumn, actual *TableColumn)
- func CheckDatabaseExistsWithNewConnection(dbname string) bool
- func CheckTableExists(db *sql.DB, tableName string) bool
- func ConnectInitializedDatabase(postgresDbConfig *postgresdb.Config, upgradeScripts []*UpgradeScript, ...) (*sql.DB, error)
- func GetNumTablesInDb(db *sql.DB) int
- func PostTestWithDbClose(db *sql.DB, dbname string)
- func PreTest(t *testing.T) (*sql.DB, string)
- func QueryAllRows(db *sql.DB, tableName string) [][]interface{}
- func QueryDbVersion(db *sql.DB) (uint32, error)
- func RunUpgradeScripts(db *sql.DB, scripts []*UpgradeScript, codeVersionString string) error
- func ValidateDBVersionRow(t *testing.T, actualRow []interface{}, wantVersion int, ...)
- type IndexSearchResult
- type TableColumn
- type UpgradeScript
Constants ¶
const SqlDbVersionTableAlter1 = "ALTER TABLE db_version ADD COLUMN code_version_string TEXT"
const SqlDbVersionTableCreate = "" /* 211-byte string literal not displayed */
tables
Variables ¶
var UpgradeScripts = []*UpgradeScript{ MakeUpgradeScript(1, SqlDbVersionTableCreate), MakeUpgradeScript(2, SqlDbVersionTableAlter1), }
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 ¶
CheckDatabaseExistsWithNewConnection is well-named
func CheckTableExists ¶
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 PostTestWithDbClose ¶
PostTestWithDbClose logic for tests related to db upgrades
func QueryAllRows ¶
QueryAllRows queries all the rows of a given table in a 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
Types ¶
type IndexSearchResult ¶
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