{"record":{"id":"3d7b710a41ee62cc","repo":"theonedev/onedev","slug":"unable-to-upgrade-specified-installation-due-to-ab","errorCode":null,"errorMessage":"Unable to upgrade specified installation due to above error","messagePattern":"Unable to upgrade specified installation due to above error","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/commandhandler/Upgrade.java","lineNumber":305,"sourceCode":"\t\t\t\t\t\thibernateProps = Strings.CS.replace(hibernateProps, \"sampledb\", \"internaldb\");\n\t\t\t\t\t\twriteStringToFile(hibernatePropsFile, hibernateProps, UTF_8);\n\t\t\t\t\t}\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tvar callable = new Callable<Void>() {\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic Void call() {\n\t\t\t\t\t\t\tvar newAppDataVersion = parseInt(MigrationHelper.getVersion(DataMigrator.class));\n\t\t\t\t\t\t\tvar dataVersion = getDataVersion(upgradeDir);\n\t\t\t\t\t\t\tvar oldAppDataVersion = dataVersion.app;\n\t\t\t\t\t\t\tvar dbDataVersion = dataVersion.db;\n\t\t\t\t\t\t\tif (dbDataVersion == 0) \n\t\t\t\t\t\t\t\tthrow new ExplicitException(\"Unable to upgrade specified installation as database is not populated yet\");\n\t\t\t\t\t\t\tif (dbDataVersion == -1) \n\t\t\t\t\t\t\t\tthrow new ExplicitException(\"Unable to upgrade specified installation due to above error\");\n\t\t\t\t\t\t\tif (dbDataVersion != oldAppDataVersion && dbDataVersion != newAppDataVersion) \n\t\t\t\t\t\t\t\tthrow new ExplicitException(\"Unable to upgrade specified installation as data version of application and database is not the same\");\n\t\t\t\t\t\t\tif (newAppDataVersion < oldAppDataVersion) \n\t\t\t\t\t\t\t\tthrow new ExplicitException(\"OneDev program is too old, please use a newer version\");\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tString timestamp = DateTimeFormat.forPattern(BACKUP_DATETIME_FORMAT).print(new DateTime());\n\t\t\t\t\t\t\tFile programBackup = new File(upgradeDir, \"site/program-backup/\" + timestamp);\n\t\t\t\t\t\t\tFileUtils.createDir(programBackup);\n\n\t\t\t\t\t\t\tlogger.info(\"Backing up old program files as {}...\", programBackup.getAbsolutePath());\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tfor (File each : upgradeDir.listFiles()) {\n\t\t\t\t\t\t\t\t\tif (each.isFile()) {\n\t\t\t\t\t\t\t\t\t\tFileUtils.copyFileToDirectory(each, programBackup);\n\t\t\t\t\t\t\t\t\t} else if (!each.getName().equals(\"temp\")\n\t\t\t\t\t\t\t\t\t\t\t&& !each.getName().equals(\"site\")\n\t\t\t\t\t\t\t\t\t\t\t&& !each.getName().equals(\"internaldb\")) {\n\t\t\t\t\t\t\t\t\t\tFileUtils.copyDirectoryToDirectory(each, programBackup);","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/commandhandler/Upgrade.java#L287-L323","documentation":"During upgrade, if reading the database data version itself failed, getDataVersion returns dbDataVersion == -1 (the error is logged just above in the console). The upgrade.call() method detects this sentinel and aborts with 'Unable to upgrade specified installation due to above error' rather than proceeding with unknown version state.","triggerScenarios":"Running the 'upgrade' command when getDataVersion could not determine the database version — e.g. the version query against the DB threw an exception, the DB is unreachable, or schema inspection failed — leaving dbDataVersion == -1.","commonSituations":"Database connection problems during upgrade; corrupted or partially migrated schema where version detection fails; running upgrade with wrong DB credentials or against a down database.","solutions":["Read the error logged immediately above this message in the upgrade console output — it names the root cause of version detection failure.","Fix database connectivity/credentials so the upgrade can read the schema version.","Repair or restore the database schema if version tables are corrupted, then retry the upgrade.","Re-run the upgrade command once the underlying version-detection issue is resolved."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// verify DB connectivity before upgrading\ntry (var conn = DriverManager.getConnection(dbUrl, user, pass)) {\n    if (!conn.isValid(5)) throw new IllegalStateException(\"DB unreachable\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    upgrade.call();\n} catch (ExplicitException e) {\n    if (e.getMessage().contains(\"due to above error\"))\n    logger.error(\"See preceding console error for the version-detection failure\");\n}","preventionTips":["Always read the error printed immediately before this message — it contains the real cause.","Check database availability and credentials before starting an upgrade.","Fix any corrupted schema/version tables before retrying."],"tags":["upgrade","database","migration","versioning"],"backgroundTag":"database-schema-version-mismatch","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}