Class EventTypeMigration<TUpgrade, TPrevious>

Namespace
Cratis.Chronicle.Events.Migrations
Assembly
Cratis.Chronicle.dll

Abstract base class for type-safe event type migrations between two generations. Extracts From and To from TUpgrade and TPrevious - each resolved via EventTypeAttribute or EventTypeGenerationForAttribute<TEventType> - validates that both resolve to the same event type id, and that the upgrade generation is exactly one more than the previous generation.

public abstract class EventTypeMigration<TUpgrade, TPrevious> : IEventTypeMigrationFor<TUpgrade, TPrevious>, IEventTypeMigrationFor<TUpgrade>, IEventTypeMigration

Type Parameters

TUpgrade

The upgraded (newer generation) event type.

TPrevious

The previous (older generation) event type.

Inheritance
EventTypeMigration<TUpgrade, TPrevious>
Implements
IEventTypeMigrationFor<TUpgrade, TPrevious>
Inherited Members
Extension Methods

Constructors

EventTypeMigration()

Initializes a new instance of the EventTypeMigration<TUpgrade, TPrevious> class.

protected EventTypeMigration()

Exceptions

MigrationGenerationsMustShareEventTypeId

Thrown when TUpgrade and TPrevious resolve to different event type ids.

InvalidMigrationGenerationGap

Thrown when TUpgrade's generation is not exactly one more than TPrevious's generation.

EventTypeMigration(IEventTypes)

Resolves and validates adjacent migration endpoints in the owning store's registry.

protected EventTypeMigration(IEventTypes eventTypes)

Parameters

eventTypes IEventTypes

The owning store's finalized event registry.

Exceptions

TypeIsNotAnEventType

Either endpoint is not registered in the owning store.

MigrationGenerationsMustShareEventTypeId

The registered endpoints have different identifiers.

InvalidMigrationGenerationGap

The registered endpoints are not adjacent generations.

Properties

From

Gets the generation to migrate from.

public EventTypeGeneration From { get; }

Property Value

EventTypeGeneration

To

Gets the generation to migrate to.

public EventTypeGeneration To { get; }

Property Value

EventTypeGeneration

Methods

Downcast(IEventMigrationBuilder<TPrevious, TUpgrade>)

Define the type-safe downcast migration from TUpgrade to TPrevious.

public abstract void Downcast(IEventMigrationBuilder<TPrevious, TUpgrade> builder)

Parameters

builder IEventMigrationBuilder<TPrevious, TUpgrade>

The IEventMigrationBuilder<TTarget, TSource> to use.

MapValues(IEventValueMapBuilder<TUpgrade, TPrevious>)

Declare the values that keep their property but change what they mean between the two generations.

public virtual void MapValues(IEventValueMapBuilder<TUpgrade, TPrevious> builder)

Parameters

builder IEventValueMapBuilder<TUpgrade, TPrevious>

The IEventValueMapBuilder<TUpgrade, TPrevious> to use.

Remarks

A map declared here is applied in both directions - forward when upcasting, inverted when downcasting - so an enum member that was renumbered, or a code that took on a new spelling, is stated once instead of twice. It is applied before Upcast(IEventMigrationBuilder<TUpgrade, TPrevious>) and Downcast(IEventMigrationBuilder<TPrevious, TUpgrade>) run, so a migration that needs a different answer for one direction states that direction's transformation itself and it wins.

Upcast(IEventMigrationBuilder<TUpgrade, TPrevious>)

Define the type-safe upcast migration from TPrevious to TUpgrade.

public abstract void Upcast(IEventMigrationBuilder<TUpgrade, TPrevious> builder)

Parameters

builder IEventMigrationBuilder<TUpgrade, TPrevious>

The IEventMigrationBuilder<TTarget, TSource> to use.