evento-sql-migrator
SQL database migrations for the Evento event sourcing library.
Overview
This crate provides database schema migrations required for storing events and subscriber state in SQL databases. It supports SQLite, MySQL, and PostgreSQL.
Installation
Add to your Cargo.toml:
[]
= "1.8"
By default, all database backends are enabled. To use only specific databases:
[]
= { = "1.8", = false, = ["postgres"] }
Features
sqlite- SQLite database supportmysql- MySQL database supportpostgres- PostgreSQL database support
Usage
use ;
async
When using the main evento crate, the migrator is re-exported:
let migrator = ?;
migrator.run.await?;
Migrations
The crate includes the following migrations:
| Migration | Description |
|---|---|
InitMigration |
Creates the initial schema (event, snapshot, subscriber tables) |
M0002 |
Adds timestamp_subsec column for sub-second precision |
M0003 |
Drops snapshot table, extends event name column to VARCHAR(50) |
Database Schema
After running all migrations, the following tables are created:
Event Table
Stores all domain events:
| Column | Type | Description |
|---|---|---|
id |
VARCHAR(26) | Event ID (ULID format) |
name |
VARCHAR(50) | Event type name |
aggregator_type |
VARCHAR(50) | Aggregate root type |
aggregator_id |
VARCHAR(26) | Aggregate root instance ID |
version |
INTEGER | Event sequence number |
data |
BLOB | Serialized event data |
metadata |
BLOB | Serialized event metadata |
routing_key |
VARCHAR(50) | Optional routing key |
timestamp |
BIGINT | Event timestamp (seconds) |
timestamp_subsec |
BIGINT | Sub-second precision |
Indexes:
idx_event_type- Onaggregator_typeidx_event_type_id- On(aggregator_type, aggregator_id)idx_event_routing_key_type- On(routing_key, aggregator_type)- Unique constraint on
(aggregator_type, aggregator_id, version)
Subscriber Table
Tracks event subscription progress:
| Column | Type | Description |
|---|---|---|
key |
VARCHAR(50) | Subscriber identifier (primary key) |
worker_id |
VARCHAR(26) | Associated worker ID |
cursor |
TEXT | Current event stream position |
lag |
INTEGER | Subscription lag counter |
enabled |
BOOLEAN | Whether subscription is active |
created_at |
TIMESTAMP | Creation timestamp |
updated_at |
TIMESTAMP | Last update timestamp |
License
See the LICENSE file in the repository root.