{"record":{"id":"89cc78d260fb3297","repo":"golang-migrate/migrate","slug":"no-database-name-89cc78","errorCode":null,"errorMessage":"no database name","messagePattern":"no database name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/cockroachdb/cockroachdb.go","lineNumber":32,"sourceCode":"\t\"github.com/cockroachdb/cockroach-go/v2/crdb\"\n\t\"github.com/golang-migrate/migrate/v4\"\n\t\"github.com/golang-migrate/migrate/v4/database\"\n\t\"github.com/lib/pq\"\n)\n\nfunc init() {\n\tdb := CockroachDb{}\n\tdatabase.Register(\"cockroach\", &db)\n\tdatabase.Register(\"cockroachdb\", &db)\n\tdatabase.Register(\"crdb-postgres\", &db)\n}\n\nvar DefaultMigrationsTable = \"schema_migrations\"\nvar DefaultLockTable = \"schema_lock\"\n\nvar (\n\tErrNilConfig      = fmt.Errorf(\"no config\")\n\tErrNoDatabaseName = fmt.Errorf(\"no database name\")\n)\n\ntype Config struct {\n\tMigrationsTable string\n\tLockTable       string\n\tForceLock       bool\n\tDatabaseName    string\n}\n\ntype CockroachDb struct {\n\tdb       *sql.DB\n\tisLocked atomic.Bool\n\n\t// Open and WithInstance need to guarantee that config is never nil\n\tconfig *Config\n}\n\nfunc WithInstance(instance *sql.DB, config *Config) (database.Driver, error) {","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/database/cockroachdb/cockroachdb.go#L14-L50","documentation":"CockroachDB driver's ErrNoDatabaseName (\"no database name\") is returned by WithInstance, Open, and WithConnection when the resolved database name is the empty string. Migrations need a target database to place the schema_migrations and schema_lock tables; without a database name the driver cannot proceed.","triggerScenarios":"Passing a Config with DatabaseName == \"\" to WithInstance; opening a DSN with no database path component, e.g. \"cockroachdb://root@localhost:26257/?sslmode=disable\".","commonSituations":"DSN copied from a tool that omitted the database segment; env-var interpolation that produced an empty database name; programmatically built Config with only MigrationsTable set.","solutions":["Include the database in the DSN path: \"cockroachdb://root@host:26257/mydb?sslmode=disable\".","Set cfg.DatabaseName explicitly when using WithInstance/WithConnection.","Verify any env interpolation (e.g. ${DB_NAME}) is actually populated before composing the DSN."],"exampleFix":"// before\ndsn := \"cockroachdb://root@localhost:26257/?sslmode=disable\"\n// after\ndsn := \"cockroachdb://root@localhost:26257/migrations?sslmode=disable\"","handlingStrategy":"validation","validationCode":"u, err := url.Parse(dsn)\nif err != nil { return err }\nif strings.Trim(u.Path, \"/\") == \"\" {\n    return fmt.Errorf(\"cockroachdb DSN must include a database name, e.g. cockroachdb://host:26257/db\")\n}","typeGuard":null,"tryCatchPattern":"d, err := cockroachdb.Open(dsn)\nif err != nil {\n    if errors.Is(err, cockroachdb.ErrNoDatabaseName) {\n        return fmt.Errorf(\"DSN %q is missing the database path component\", dsn)\n    }\n    return err\n}","preventionTips":["Always include the database segment in the DSN path.","Validate composed DSNs with url.Parse at startup; fail fast if the path is empty.","Check env-var interpolation for database name placeholders that expand to empty."],"tags":["cockroachdb","configuration","dsn"],"backgroundTag":"missing-database-name","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}