Path: redb/redb.Core/Exceptions/RedbSchemaOutdatedException.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Exceptions/RedbSchemaOutdatedException.cs
----
namespace redb.Core.Exceptions;
///
/// The database schema is behind the version this build requires, and the application could not
/// bring it up to date itself.
///
///
/// Start-up applies the versioned SQL module automatically when the connected role is allowed to.
/// It often is not: the DBA grants owner rights for the initial installation and revokes them
/// afterwards, so ALTER TABLE and CREATE OR REPLACE FUNCTION from the application
/// fail with a privilege error. Before this type that surfaced as a raw driver exception with no
/// indication of what to do. Now it says what is deployed, what is required, what could not be
/// applied, and how to get the script for the DBA — the same text the application would have run.
///
///
///
/// A distinct type, not InvalidOperationException: a hosting layer has to be able to tell
/// "someone must run the upgrade script" from every other start-up failure without parsing text.
///
///
public class RedbSchemaOutdatedException : Exception
{
/// Module version the database reports, or null when the module is absent.
public string? DeployedVersion { get; }
/// Module version this build ships and requires.
public string RequiredVersion { get; }
/// Provider name as the dialect reports it, for the operator's convenience.
public string Provider { get; }
///
/// Why the application did not apply the upgrade itself: a privilege error from the driver, or
/// null when automatic application is disabled by configuration.
///
public Exception? Cause { get; }
public RedbSchemaOutdatedException(
string provider,
string? deployedVersion,
string requiredVersion,
Exception? cause)
: base(BuildMessage(provider, deployedVersion, requiredVersion, cause), cause)
{
Provider = provider;
DeployedVersion = deployedVersion;
RequiredVersion = requiredVersion;
Cause = cause;
}
///
/// For a caller outside the service start, such as a tool, that reads the version and judges it itself and does
/// not upgrade the database. is null.
///
/// Provider name as the dialect reports it.
/// Module version the database reports (SQLite: file schema version), null when absent.
/// Module version (SQLite: file schema version) this build requires.
/// Why the caller did not upgrade the database, completing "and ..." in the first sentence.
/// What the operator does about it: the closing sentence of the message.
public RedbSchemaOutdatedException(
string provider,
string? deployedVersion,
string requiredVersion,
string reason,
string remedy)
: base($"{Outdated(provider, deployedVersion, requiredVersion, reason)} Nothing was changed. {remedy}")
{
Provider = provider;
DeployedVersion = deployedVersion;
RequiredVersion = requiredVersion;
}
private static string BuildMessage(string provider, string? deployed, string required, Exception? cause)
{
var reason = cause is null
? "automatic upgrades are disabled (AutoApplyDatabaseUpgrades = false)"
: $"the connected role is not allowed to apply it ({cause.GetType().Name}: {cause.Message})";
return
$"{Outdated(provider, deployed, required, reason)} " +
"Nothing was changed. Have the schema owner apply the upgrade script: export it with " +
"IRedbService.GetUpgradeScript() or `redb schema --upgrade --provider `, then " +
"run it with psql / sqlcmd. The script is idempotent and safe to re-run.";
}
/// The first sentence of every message: what is deployed, what is required, and why it stays so.
private static string Outdated(string provider, string? deployed, string required, string reason) =>
$"The {provider} database schema is outdated: deployed module version is " +
$"'{deployed ?? ""}', this build requires '{required}', and {reason}.";
}