Path: redb/redb.Tests.Integration/Models/TypeMigrationModels.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.Tests.Integration/Models/TypeMigrationModels.cs
----
using redb.Core.Attributes;
namespace redb.Tests.Integration.Models;
// Props for the scheme-sync type-migration suite.
//
// Note what these deliberately do NOT do: two classes sharing one [RedbScheme(Name = "...")] would be
// the obvious way to stage "the property changed type", but the library refuses it — a duplicate
// explicit name is a hard error (ClrSchemeTypeIndex.ThrowIfNameConflict and RedbSchemeNameConflictException), and rightly so.
// The suite therefore stages the change the way it actually happens in the field: it writes values
// through the current class, then rewrites _structures._id_type and the storage column with raw SQL to
// the shape an EARLIER version of the class would have produced, and re-syncs the same class. What the
// sync path then sees is indistinguishable from a real deployment where the property's type changed.
///
/// Target of the supported case: values are staged as Boolean and the property asks for int,
/// which every provider can convert.
///
[RedbScheme("Миграция типа: поддержанная", Name = "type_migration_supported", Version = 1)]
public class TypeMigrationIntProps
{
/// The property whose type changes. Staged as Boolean, declared here as int.
public int Flag { get; set; }
/// Untouched neighbour: proves the migration does not disturb the rest of the structure.
public string Tag { get; set; } = "";
}
///
/// Target of the unsupported case: Boolean to Guid is in no provider's conversion matrix, so the
/// migration must refuse and synchronisation must stop.
///
[RedbScheme("Миграция типа: неподдержанная", Name = "type_migration_unsupported", Version = 1)]
public class TypeMigrationGuidProps
{
public Guid Flag { get; set; }
public string Tag { get; set; } = "";
}
///
/// Same storage column on both sides (Int and Long both live in _Long): the type changes, the
/// values do not move, and nothing may be lost.
///
[RedbScheme("Миграция типа: та же колонка", Name = "type_migration_samecolumn", Version = 1)]
public class TypeMigrationLongProps
{
public long Flag { get; set; }
public string Tag { get; set; } = "";
}
///
/// Text to Boolean, the conversion that used to destroy what it could not read: the CASE fell through
/// to NULL for an unrecognised token while the same statement cleared the source column, and the row
/// was counted as a success.
///
[RedbScheme("Миграция типа: булева из текста", Name = "type_migration_bool_from_text", Version = 1)]
public class TypeMigrationBoolProps
{
public bool Flag { get; set; }
public string Tag { get; set; } = "";
}
///
/// Text source with rows that cannot be read as a number: the convertible ones move, the rest stay,
/// and the partial result is a failure — synchronisation stops rather than stranding either group.
///
[RedbScheme("Миграция типа: частичная", Name = "type_migration_partial", Version = 1)]
public class TypeMigrationPartialProps
{
public long Flag { get; set; }
public string Tag { get; set; } = "";
}