CHR0084: Event type generation is missing a migrator
Rule Description
Section titled “Rule Description”An event type marked [EventType(generation: N)] with N >= 2 needs an EventTypeMigration<TUpgrade, TPrevious> for every consecutive generation step from 1 up to N: 1->2, 2->3, and so on. CHR0084 reports the event type when one or more of those steps has no migrator, and the message lists exactly which steps are missing and what to add.
A step g-1->g is covered when a non-abstract class derives from EventTypeMigration<TUpgrade, TPrevious> (or implements IEventTypeMigrationFor<TUpgrade, TPrevious>) where TUpgrade is generation g and TPrevious is generation g-1 of the same event type id. Generations are recognized for both declaration styles: [EventTypeGenerationFor<T>(g)] and the older explicit-id [EventType("id", g)] on both records. Migrators in referenced assemblies count.
Event types registered explicitly through ExplicitArtifacts carry no attributes and are not checked by this rule.
Severity
Section titled “Severity”Error
Example
Section titled “Example”Violation
Section titled “Violation”using Cratis.Chronicle.Events;
// Error CHR0084: generation 2 has no migrator for step 1->2.[EventType("chr0084-person-registered", generation: 2)]public record Chr0084PersonRegistered(string FirstName, string LastName);using Cratis.Chronicle.Events;using Cratis.Chronicle.Events.Migrations;
[EventType("chr0084-fix-person-registered", generation: 2)]public record Chr0084FixPersonRegistered(string FirstName, string LastName);
[EventTypeGenerationFor<Chr0084FixPersonRegistered>(1)]public record Chr0084FixPersonRegisteredV1(string Name);
public class Chr0084FixPersonRegisteredV1ToChr0084FixPersonRegisteredMigration : EventTypeMigration<Chr0084FixPersonRegistered, Chr0084FixPersonRegisteredV1>{ public override void Upcast(IEventMigrationBuilder<Chr0084FixPersonRegistered, Chr0084FixPersonRegisteredV1> builder) => builder.Properties(pb => pb .Split(m => m.FirstName, e => e.Name, PropertySeparator.Space, SplitPartIndex.First) .Split(m => m.LastName, e => e.Name, PropertySeparator.Space, SplitPartIndex.Second));
public override void Downcast(IEventMigrationBuilder<Chr0084FixPersonRegisteredV1, Chr0084FixPersonRegistered> builder) => builder.Properties(pb => pb .Combine(m => m.Name, PropertySeparator.Space, e => e.FirstName, e => e.LastName));}How To Fix It
Section titled “How To Fix It”For each missing step g-1->g listed in the diagnostic:
- Make sure a record exists for generation
g-1. If it does not, declare it with the properties generationg-1had, marked[EventTypeGenerationFor<TCurrent>(g-1)]. Do the same for generationgwhen it is not the current type. - Add a class deriving from
EventTypeMigration<TUpgrade, TPrevious>(namespaceCratis.Chronicle.Events.Migrations) and implementUpcastandDowncastto map between the two shapes. See Event type migrations for the available builders.
Do not silence the error by lowering the generation number: events already stored at earlier generations must be upcast. Lower it only when the new generation has never been deployed anywhere.
Why This Rule Exists
Section titled “Why This Rule Exists”Chronicle validates the migration chain when event types are registered. A generation that has no migrator for every step makes the kernel reject the event type (MissingEventTypeMigrators or MissingMigrationForEventTypeGeneration), so the application fails at startup — or, in a development image with validation relaxed, stored events of the older shape are never upcast. This rule moves that failure to build time, where the fix is a few lines in the same project. See event generation validation for the full chain rules.