//
// Copyright (c) StellaOps. Licensed under AGPL-3.0-or-later.
//
// Sprint: SPRINT_20260105_002_005_TEST_cross_cutting
// Task: CCUT-006, CCUT-007
using System.Collections.Immutable;
namespace StellaOps.Testing.SchemaEvolution;
///
/// Represents a schema version.
///
/// Version identifier (e.g., "v2024.11", "v2024.12").
/// Migration identifier if applicable.
/// When this version was applied.
public sealed record SchemaVersion(
string VersionId,
string? MigrationId,
DateTimeOffset AppliedAt);
///
/// Result of schema compatibility test.
///
/// Whether the test passed.
/// Schema version used as baseline.
/// Target schema version tested against.
/// Type of operation tested.
/// Error message if not compatible.
/// Exception if one occurred.
public sealed record SchemaCompatibilityResult(
bool IsCompatible,
string BaselineVersion,
string TargetVersion,
SchemaOperationType TestedOperation,
string? ErrorMessage = null,
Exception? Exception = null);
///
/// Type of schema operation tested.
///
public enum SchemaOperationType
{
///
/// Read operation (SELECT).
///
Read,
///
/// Write operation (INSERT/UPDATE).
///
Write,
///
/// Delete operation (DELETE).
///
Delete,
///
/// Migration forward (upgrade).
///
MigrationUp,
///
/// Migration rollback (downgrade).
///
MigrationDown
}
///
/// Configuration for schema evolution tests.
///
/// Versions to test compatibility with.
/// Current schema version.
/// Number of previous versions to test backward compatibility.
/// Number of future versions to test forward compatibility.
/// Timeout per individual test.
public sealed record SchemaEvolutionConfig(
ImmutableArray SupportedVersions,
string CurrentVersion,
int BackwardCompatibilityVersionCount = 2,
int ForwardCompatibilityVersionCount = 1,
TimeSpan TimeoutPerTest = default)
{
///
/// Gets the timeout per test.
///
public TimeSpan TimeoutPerTest { get; init; } =
TimeoutPerTest == default ? TimeSpan.FromMinutes(5) : TimeoutPerTest;
}
///
/// Information about a database migration.
///
/// Unique migration identifier.
/// Version this migration belongs to.
/// Human-readable description.
/// Whether up migration script exists.
/// Whether down migration script exists.
/// When the migration was applied.
public sealed record MigrationInfo(
string MigrationId,
string Version,
string Description,
bool HasUpScript,
bool HasDownScript,
DateTimeOffset? AppliedAt);
///
/// Result of testing migration rollback.
///
/// Migration that was tested.
/// Whether rollback succeeded.
/// Duration of rollback in milliseconds.
/// Error message if rollback failed.
public sealed record MigrationRollbackResult(
MigrationInfo Migration,
bool Success,
long DurationMs,
string? ErrorMessage);
///
/// Test data seeding result.
///
/// Schema version data was seeded for.
/// Number of records seeded.
/// Duration of seeding in milliseconds.
public sealed record SeedDataResult(
string SchemaVersion,
int RecordsSeeded,
long DurationMs);
///
/// Report of schema evolution test suite.
///
/// Total number of tests executed.
/// Number of passed tests.
/// Number of failed tests.
/// Number of skipped tests.
/// Individual test results.
/// Total duration in milliseconds.
public sealed record SchemaEvolutionReport(
int TotalTests,
int PassedTests,
int FailedTests,
int SkippedTests,
ImmutableArray Results,
long TotalDurationMs)
{
///
/// Gets a value indicating whether all tests passed.
///
public bool IsSuccess => FailedTests == 0;
}