{"record":{"id":"c233f9e5e8d8cb95","repo":"juanfont/headscale","slug":"database-of-type-s-is-not-supported-w","errorCode":null,"errorMessage":"database of type %s is not supported: %w","messagePattern":"database of type (.+?) is not supported: %w","errorType":"console","errorClass":"errDatabaseNotSupported","httpStatus":null,"severity":"error","filePath":"hscontrol/db/db.go","lineNumber":1153,"sourceCode":"\n\t\tdb, err := gorm.Open(postgres.Open(dbString), &gorm.Config{\n\t\t\tLogger: dbLogger,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tsqlDB, _ := db.DB()\n\t\tsqlDB.SetMaxIdleConns(cfg.Postgres.MaxIdleConnections)\n\t\tsqlDB.SetMaxOpenConns(cfg.Postgres.MaxOpenConnections)\n\t\tsqlDB.SetConnMaxIdleTime(\n\t\t\ttime.Duration(cfg.Postgres.ConnMaxIdleTimeSecs) * time.Second,\n\t\t)\n\n\t\treturn db, nil\n\t}\n\n\treturn nil, fmt.Errorf(\n\t\t\"database of type %s is not supported: %w\",\n\t\tcfg.Type,\n\t\terrDatabaseNotSupported,\n\t)\n}\n\nfunc runMigrations(cfg types.DatabaseConfig, dbConn *gorm.DB, migrations *gormigrate.Gormigrate) error {\n\tif cfg.Type == types.DatabaseSqlite {\n\t\t// SQLite: Run the early migrations that GORM cannot handle safely with\n\t\t// foreign keys enabled (route and pre-auth-key automigrations) with FK\n\t\t// disabled, then run everything else with FK enabled.\n\t\t//\n\t\t// NO NEW MIGRATIONS SHOULD RUN WITH FK DISABLED. As of 2025-07-02, all\n\t\t// new migrations must run with foreign keys enabled via the\n\t\t// migrations.Migrate() call below.\n\t\tif err := dbConn.Exec(\"PRAGMA foreign_keys = OFF\").Error; err != nil { //nolint:noinlineerr\n\t\t\treturn fmt.Errorf(\"disabling foreign keys: %w\", err)\n\t\t}","sourceCodeStart":1135,"sourceCodeEnd":1171,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/hscontrol/db/db.go#L1135-L1171","documentation":"openDB switches on cfg.Database.Type and only 'sqlite' and 'postgres' are implemented; anything else falls through to this terminal error wrapping errDatabaseNotSupported. It is a configuration validation error, not a runtime fault.","triggerScenarios":"Setting db.type to a value other than sqlite/postgres in config.yaml (e.g. 'mysql', 'postgres16', trailing whitespace, or a typo like 'sqllite').","commonSituations":"Copy-pasted config from another tool expecting MySQL support; case or spelling mistakes in the type string; env var overrides (HS_DB_TYPE) with a wrong value.","solutions":["Set db.type to exactly sqlite or postgres in config.yaml (or the HS_DB_TYPE env var).","Check for stray whitespace/quotes around the type value.","headscale does not support MySQL/MariaDB — choose postgres if sqlite is insufficient."],"exampleFix":"// before (config.yaml)\ndb:\n  type: mysql\n\n// after\ndb:\n  type: sqlite\n  sqlite:\n    path: /var/lib/headscale/db.sqlite","handlingStrategy":"validation","validationCode":"// Validate config before startup\ntype dbCfg struct{ Type string }\nfunc validDbType(t string) bool {\n    switch strings.ToLower(strings.TrimSpace(t)) {\n    case \"sqlite\", \"postgres\":\n        return true\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"// Fail fast on unsupported type; there is no fallback. Correct db.type in\n// config.yaml / HS_DB_TYPE and restart.","preventionTips":["Use only 'sqlite' or 'postgres' for db.type.","Template configs through a validator in CI."],"tags":["database","config","validation"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}