Path: redb/redb.Export/Providers/ForeignKeyRefusal.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.Export/Providers/ForeignKeyRefusal.cs
----
namespace redb.Export.Providers;
///
/// The wording an import uses to refuse a file whose rows point at rows it does not hold, shared by the providers
/// that check the foreign keys themselves at the end of an import, so the same file is described the same way.
///
internal static class ForeignKeyRefusal
{
/// One line for one broken key.
/// The key: its name, or the referencing column where the database keeps no name.
/// The table whose rows point nowhere.
/// How many of its rows do.
/// The table the key points at.
/// The columns of that table the key points at.
/// One of the rows, as column = value pairs.
public static string Describe(string key, string table, long rows, string referencedTable,
IEnumerable referencedColumns, string example) =>
$"{key}: {rows} row(s) of {table} point at a missing row of {referencedTable} " +
$"({string.Join(", ", referencedColumns)}), for example {example}";
/// The exception that refuses the import.
/// The lines from .
/// What the refusal leaves in the database.
public static InvalidOperationException Exception(IReadOnlyCollection broken, string outcome) =>
new("The file holds references to rows it does not contain, and the database refuses them " +
"(a file exported with --schemes whose rows point into schemes left out is one way to get one):" +
Environment.NewLine + string.Join(Environment.NewLine, broken.Select(b => " " + b)) +
Environment.NewLine + outcome);
}