Skip to main content

MigrationRecord

Represents a migration record stored in the __MigrationHistory Cosmos DB container. Part of the Cosmigrator.Models namespace.

namespace Cosmigrator.Models;

public class MigrationRecord
{
[JsonPropertyName("id")]
public string Id { get; set; } = string.Empty;

[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;

[JsonPropertyName("appliedAt")]
public DateTime AppliedAt { get; set; }

[JsonPropertyName("status")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public MigrationStatus Status { get; set; }
}

public enum MigrationStatus
{
Applied,
RolledBack
}

MigrationRecord properties

PropertyTypeJSON KeyDescription
IdstringidMigration identifier. Also the document ID and partition key
NamestringnameHuman-readable name of the migration
AppliedAtDateTimeappliedAtUTC timestamp of when the migration was applied or rolled back
StatusMigrationStatusstatusCurrent status, serialized as a string ("Applied" or "RolledBack")

MigrationStatus enum

ValueDescription
AppliedMigration has been successfully applied via UpAsync
RolledBackMigration has been rolled back via DownAsync

JSON representation

A MigrationRecord is stored in Cosmos DB as:

{
"id": "20250219_000001",
"name": "AddEmailToUsers",
"appliedAt": "2025-02-19T14:30:00.0000000",
"status": "Applied"
}

The status field uses JsonStringEnumConverter so it's stored as a human-readable string rather than an integer.

Partition key

The id field serves as both the document ID and partition key in the __MigrationHistory container. This means each migration maps to exactly one record, and reads/writes are efficient single-partition operations.