Path: redb/redb.Tests.Integration/Models/MigrationLiteralProbeModels.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/MigrationLiteralProbeModels.cs ---- using redb.Core.Attributes; using redb.Core.Pro.Migration; namespace redb.Tests.Integration.Models; public enum MigrationLiteralKind { First, Second, } /// /// One field per kind of value a migration writes as a SQL literal: MigrationTestsBase fills each by DefaultValue and /// by a constant in a ComputedFrom lambda, then reads it back and filters on it as a saved value. /// [RedbScheme("Migrations: literal probe", Name = "migration_literal_probe")] public class MigrationLiteralProbeProps { public string? Text { get; set; } public double? Real { get; set; } public decimal? Money { get; set; } public long? Count { get; set; } public Guid? Key { get; set; } public DateTime? At { get; set; } public DateTimeOffset? Seen { get; set; } public DateOnly? Day { get; set; } public TimeOnly? Clock { get; set; } public TimeSpan? Span { get; set; } public MigrationLiteralKind? Kind { get; set; } public byte[]? Blob { get; set; } } /// The values of the literal probe; the negative numbers catch a culture's minus sign. public static class MigrationLiteralValues { public const string Text = "it's C:\\path\\ 'quoted' \\' end Привет"; public const double Real = -1234.5; public const decimal Money = -9876.54m; public const long Count = -42; public static readonly Guid Key = new("8f14e45f-ceea-467a-9a36-dedd4bea2543"); public static readonly DateTime At = new(2026, 5, 17, 10, 30, 15, DateTimeKind.Utc); public static readonly DateTimeOffset Seen = new(2026, 5, 17, 13, 30, 15, TimeSpan.FromHours(3)); public static readonly DateOnly Day = new(2026, 5, 17); public static readonly TimeOnly Clock = new(10, 30, 15); public static readonly TimeSpan Span = new(1, 2, 3, 4); public const MigrationLiteralKind Kind = MigrationLiteralKind.Second; public static readonly byte[] Blob = [0x00, 0xFF, 0x10, 0x27]; /// The kind the two migrations below act on; set by the test before it migrates. public static readonly AsyncLocal Current = new(); } /// DefaultValue of the field named by . public class MigrationLiteralDefaultMigration : IRedbMigration { public void Configure(IMigrationBuilder builder) { switch (MigrationLiteralValues.Current.Value) { case nameof(MigrationLiteralProbeProps.Text): builder.Property(p => p.Text).DefaultValue(MigrationLiteralValues.Text); break; case nameof(MigrationLiteralProbeProps.Real): builder.Property(p => p.Real).DefaultValue(MigrationLiteralValues.Real); break; case nameof(MigrationLiteralProbeProps.Money): builder.Property(p => p.Money).DefaultValue(MigrationLiteralValues.Money); break; case nameof(MigrationLiteralProbeProps.Count): builder.Property(p => p.Count).DefaultValue(MigrationLiteralValues.Count); break; case nameof(MigrationLiteralProbeProps.Key): builder.Property(p => p.Key).DefaultValue(MigrationLiteralValues.Key); break; case nameof(MigrationLiteralProbeProps.At): builder.Property(p => p.At).DefaultValue(MigrationLiteralValues.At); break; case nameof(MigrationLiteralProbeProps.Seen): builder.Property(p => p.Seen).DefaultValue(MigrationLiteralValues.Seen); break; case nameof(MigrationLiteralProbeProps.Day): builder.Property(p => p.Day).DefaultValue(MigrationLiteralValues.Day); break; case nameof(MigrationLiteralProbeProps.Clock): builder.Property(p => p.Clock).DefaultValue(MigrationLiteralValues.Clock); break; case nameof(MigrationLiteralProbeProps.Span): builder.Property(p => p.Span).DefaultValue(MigrationLiteralValues.Span); break; case nameof(MigrationLiteralProbeProps.Kind): builder.Property(p => p.Kind).DefaultValue(MigrationLiteralValues.Kind); break; case nameof(MigrationLiteralProbeProps.Blob): builder.Property(p => p.Blob).DefaultValue(MigrationLiteralValues.Blob); break; case "Null": builder.Property(p => p.Text).DefaultValue(null); break; default: throw new InvalidOperationException($"No literal probe for '{MigrationLiteralValues.Current.Value}'."); } } } /// /// ComputedFrom keeping a stored value and putting a constant where there is none. Numbers, text and the enum are C# /// literals (a constant node); the other kinds can only be a captured or static value. /// public class MigrationLiteralComputedMigration : IRedbMigration { public void Configure(IMigrationBuilder builder) { switch (MigrationLiteralValues.Current.Value) { case nameof(MigrationLiteralProbeProps.Text): builder.Property(p => p.Text).ComputedFrom(p => p.Text ?? "it's C:\\path\\ 'quoted' \\' end Привет"); break; case nameof(MigrationLiteralProbeProps.Real): builder.Property(p => p.Real).ComputedFrom(p => p.Real ?? -1234.5); break; case nameof(MigrationLiteralProbeProps.Money): builder.Property(p => p.Money).ComputedFrom(p => p.Money ?? -9876.54m); break; case nameof(MigrationLiteralProbeProps.Count): builder.Property(p => p.Count).ComputedFrom(p => p.Count ?? -42L); break; case nameof(MigrationLiteralProbeProps.Key): builder.Property(p => p.Key).ComputedFrom(p => p.Key ?? MigrationLiteralValues.Key); break; case nameof(MigrationLiteralProbeProps.At): builder.Property(p => p.At).ComputedFrom(p => p.At ?? MigrationLiteralValues.At); break; case nameof(MigrationLiteralProbeProps.Seen): builder.Property(p => p.Seen).ComputedFrom(p => p.Seen ?? MigrationLiteralValues.Seen); break; case nameof(MigrationLiteralProbeProps.Day): builder.Property(p => p.Day).ComputedFrom(p => p.Day ?? MigrationLiteralValues.Day); break; case nameof(MigrationLiteralProbeProps.Clock): builder.Property(p => p.Clock).ComputedFrom(p => p.Clock ?? MigrationLiteralValues.Clock); break; case nameof(MigrationLiteralProbeProps.Span): builder.Property(p => p.Span).ComputedFrom(p => p.Span ?? MigrationLiteralValues.Span); break; case nameof(MigrationLiteralProbeProps.Kind): builder.Property(p => p.Kind).ComputedFrom(p => p.Kind ?? MigrationLiteralKind.Second); break; case nameof(MigrationLiteralProbeProps.Blob): builder.Property(p => p.Blob).ComputedFrom(p => p.Blob ?? MigrationLiteralValues.Blob); break; default: throw new InvalidOperationException($"No literal probe for '{MigrationLiteralValues.Current.Value}'."); } } }