golang-migrate/migrate · error

no database name

Error message

no database name

What it means

ErrNoDatabaseName is the redshift driver's sentinel returned when Config.DatabaseName is empty (WithInstance/WithConnection) or the Open URL has no database in its path. The driver must know which database to operate on for the migrations table and version tracking.

Source

Thrown at database/redshift/redshift.go:30

	"strconv"
	"strings"
	"sync/atomic"

	"github.com/golang-migrate/migrate/v4"
	"github.com/golang-migrate/migrate/v4/database"
	"github.com/lib/pq"
)

func init() {
	db := Redshift{}
	database.Register("redshift", &db)
}

var DefaultMigrationsTable = "schema_migrations"

var (
	ErrNilConfig      = fmt.Errorf("no config")
	ErrNoDatabaseName = fmt.Errorf("no database name")
)

type Config struct {
	MigrationsTable string
	DatabaseName    string
}

type Redshift struct {
	isLocked atomic.Bool
	conn     *sql.Conn
	db       *sql.DB

	// Open and WithInstance need to guarantee that config is never nil
	config *Config
}

func WithInstance(instance *sql.DB, config *Config) (database.Driver, error) {
	if config == nil {

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Add the database name to the URL path, e.g. redshift://user:pass@host:5439/dbname
  2. Set Config.DatabaseName before calling WithInstance/WithConnection
  3. Validate the database name at application startup before invoking the migrator

Example fix

// before
dsn := fmt.Sprintf("redshift://%s:%s@%s:5439", user, pass, host)
// after
dsn := fmt.Sprintf("redshift://%s:%s@%s:5439/%s", user, pass, host, dbName)
if dbName == "" {
    return errors.New("redshift database name is required")
}
Defensive patterns

Strategy: validation

Validate before calling

func requireRedshiftDatabaseName(cfg *redshift.Config) error {
    if cfg == nil || cfg.DatabaseName == "" {
        return errors.New("redshift: DatabaseName is required")
    }
    return nil
}

Type guard

func hasDatabaseName(cfg *redshift.Config) bool {
    return cfg != nil && cfg.DatabaseName != ""
}

Prevention

When it happens

Trigger: redshift.Open("redshift://host:5439") without a path; WithInstance/WithConnection with Config{DatabaseName: ""}.

Common situations: Reusing a postgres DSN template with the path stripped for redshift; environment-driven configs where DB_NAME is unset in the deploy target; misconfigured IaC templates.

Related errors


AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02). Data as JSON: /api/errors/bd21e1645a8c7760. Report an issue: GitHub.