golang-migrate/migrate · error

no database name

Error message

no database name

What it means

ErrNoDatabaseName (message "no database name") is declared in the Snowflake driver (snowflake.go:28) and returned when the database component of the DSN is missing or empty. In Open (snowflake.go:111-113), after the URL path is split on "/" the third segment must be a non-empty database name; it is also returned by WithInstance/WithConnection when Config.DatabaseName is empty. Snowflake requires an explicit database to run migrations against.

Source

Thrown at database/snowflake/snowflake.go:28

	"strconv"
	"strings"
	"sync/atomic"

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

func init() {
	db := Snowflake{}
	database.Register("snowflake", &db)
}

var DefaultMigrationsTable = "schema_migrations"

var (
	ErrNilConfig          = fmt.Errorf("no config")
	ErrNoDatabaseName     = fmt.Errorf("no database name")
	ErrNoPassword         = fmt.Errorf("no password")
	ErrNoSchema           = fmt.Errorf("no schema")
	ErrNoSchemaOrDatabase = fmt.Errorf("no schema/database name")
)

type Config struct {
	MigrationsTable string
	DatabaseName    string
}

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

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

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Provide the full three-level path: snowflake://user:pass@account/schema/database
  2. Set DatabaseName in the Config when using WithInstance/WithConnection
  3. Verify env-substituted DSNs don't collapse to an empty trailing segment
  4. Validate the URL path length and non-empty segments before calling Open

Example fix

// before
url := "snowflake://user:pass@acct/PUBLIC/"
// after
url := "snowflake://user:pass@acct/PUBLIC/MYDB"
Defensive patterns

Strategy: validation

Validate before calling

u, _ := url.Parse(dsn)
parts := strings.Split(u.Path, "/")
if len(parts) < 3 || parts[2] == "" {
    return fmt.Errorf("snowflake DSN must be .../schema/database; got path %q", u.Path)
}

Prevention

When it happens

Trigger: URLs like snowflake://user:pass@account/schema/ (empty third path segment); WithInstance with Config where DatabaseName == "".

Common situations: DSNs templated for Postgres-style URLs (host/db) missing Snowflake's account/schema/database three-level path; env-var substitution producing an empty database segment.

Related errors


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