event-schema-already-registered
The event type has a schema already, which can be neither replaced nor removed.
- Routes:
register-event-schemaandrestore-backup - Description:
event schema is already registered: a schema can be neither replaced nor removed, so a different one needs a new event type - Details: When registering a schema,
value, the event type as the request gave it. When restoring a backup,part, the part of the backup that brings the second schema, counting from 0, with the full backup as part 0, andvalue, the event type.
Why It Happens#
An event type has at most one schema, which applies to all of its events and can be neither replaced nor removed once it is registered. Registering a schema for a type that has one is refused, even if it is the same schema, for example when a service registers its schemas each time it starts.
When restoring a backup, the backup brings two different schemas for the same event type. Every part of a backup brings every schema again, and the same schema is taken once.
How to Fix It#
To change the schema, introduce a new event type, such as io.eventsourcingdb.library.book-acquired.v2, with a schema of its own. To make sure that a schema is registered, read the event type with read-event-type, which answers with its schema, and register one only if it has none. Sending the same request again fails the same way.
Example#
To register a schema for io.eventsourcingdb.library.book-acquired, which has one already, EventSourcingDB answers with this error, as a line of the stream, and then ends the stream with its end item:
{
"type": "error",
"data": {
"code": "https://docs.eventsourcingdb.io/errors/event-schema-already-registered",
"description": "event schema is already registered: a schema can be neither replaced nor removed, so a different one needs a new event type",
"details": {
"value": "io.eventsourcingdb.library.book-acquired"
}
}
}