diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/repositories/migration_db_repo.go | 16 | ||||
| -rw-r--r-- | internal/sqlparse/sqlparse.go | 3 | ||||
| -rw-r--r-- | internal/storage/db.go | 11 |
3 files changed, 20 insertions, 10 deletions
diff --git a/internal/repositories/migration_db_repo.go b/internal/repositories/migration_db_repo.go index 93b9c73..b9e2d78 100644 --- a/internal/repositories/migration_db_repo.go +++ b/internal/repositories/migration_db_repo.go @@ -25,7 +25,10 @@ func NewMigrationDBRepo(db *sql.DB) (*MigrationDBRepo, error) { ); `) if err != nil { - return nil, err + return nil, fmt.Errorf( + "unable to create bolt_migrations database table: %w", + err, + ) } return &MigrationDBRepo{db: db}, nil @@ -38,7 +41,11 @@ func NewMigrationDBRepo(db *sql.DB) (*MigrationDBRepo, error) { func (mr *MigrationDBRepo) List() (map[string]*models.Migration, error) { rows, err := mr.db.Query(`SELECT version FROM bolt_migrations;`) if err != nil { - return nil, err + return nil, fmt.Errorf( + "unable to execute query to select versions from "+ + "bolt_migrations database table: %w", + err, + ) } defer rows.Close() @@ -47,7 +54,10 @@ func (mr *MigrationDBRepo) List() (map[string]*models.Migration, error) { var version string err := rows.Scan(&version) if err != nil { - return nil, err + return nil, fmt.Errorf( + "unable to scan version row from applied migrations: %w", + err, + ) } trimmedVersion := strings.TrimSpace(version) migrations[trimmedVersion] = &models.Migration{ diff --git a/internal/sqlparse/sqlparse.go b/internal/sqlparse/sqlparse.go index 9ded618..25960c5 100644 --- a/internal/sqlparse/sqlparse.go +++ b/internal/sqlparse/sqlparse.go @@ -2,6 +2,7 @@ package sqlparse import ( "bufio" + "fmt" "io" "strings" ) @@ -37,7 +38,7 @@ func (sp *SqlParser) Parse() (*ExecutionOptions, error) { } if err := scanner.Err(); err != nil { - return nil, err + return nil, fmt.Errorf("parsing sql file encountered an error: %w", err) } return options, nil diff --git a/internal/storage/db.go b/internal/storage/db.go index 9032dc3..e329e71 100644 --- a/internal/storage/db.go +++ b/internal/storage/db.go @@ -15,16 +15,15 @@ import ( func DBConnect(driver string, connectionParams string) (*sql.DB, error) { db, err := sql.Open(driver, connectionParams) if err != nil { - return nil, err + return nil, fmt.Errorf("invalid database connection parameters: %w", err) } - // Note: `sql.Open` only validates the connection string we provided - // it is sane. It doesn't actually open up a connection to the database. - // For that, we ping the database to ensure the connection string is fully - // valid. + // Note: `sql.Open` only validates the connection string we provided is sane. + // It doesn't actually open up a connection to the database. For that, we ping + // the database to ensure the connection string is fully valid. err = db.Ping() if err != nil { - return nil, err + return nil, fmt.Errorf("unable to ping database: %w", err) } return db, nil |