Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

SqlMessageStorage unstable

Persists cluster mailbox messages and replies in SQL.

The SQL-backed MessageStorage stores encoded cluster envelopes and reply chunks so runners can recover mailbox state after restarts. It supports redelivering unprocessed messages, deduplicating requests by primary key, and replaying reply chunks until they are acknowledged. This module includes the storage constructor, layers, migrations, optional table prefixes, and the row mapping needed by encoded message storage.

layer, layerWith, make, and makeEncoded run the migrations before building the storage. To run migrations with a different connection, such as a schema owner in a deploy step, use layerMigrations there and layerStorage in the runtime.

Request deduplication keys that exceed the 255-character message_id column are hashed with the Crypto service before they are written, so composed keys of any length are supported; shorter keys are stored as plaintext, byte-compatible with rows written by previous versions.

7 exports Since v4.0.0 Source

Constructors

make

unstable
Since v4.0.0

Creates a SQL-backed MessageStorage implementation, running its migrations and using the optional table prefix.

Signature

declare const make: (options?: {
readonly prefix?: string;
}) => Effect.Effect<MessageStorage.MessageStorage["Service"], never, SqlClient.SqlClient | Snowflake.Generator | Crypto.Crypto>

makeEncoded

unstable
Since v4.0.0

Creates a SQL-backed encoded message storage driver, running its migrations and using the optional table prefix.

When to use

Use when you need the SQL-backed encoded driver directly, such as when composing a custom message storage adapter.

Details

The optional prefix controls the table names for messages, replies, and migrations; when omitted, cluster is used.

Gotchas

Changing prefix after deployment points the runtime at a different set of tables, including the migration history table.

See

  • make for the decoded MessageStorage constructor

Signature

declare const makeEncoded: (options?: {
readonly prefix?: string;
}) => Effect.Effect<MessageStorage.Encoded, never, SqlClient.SqlClient | Crypto.Crypto>

Layers

layer

unstable
Since v4.0.0

Provides SQL-backed MessageStorage with the cluster table prefix, running migrations first and supplying Snowflake.layerGenerator.

Details

The connection needs DDL permissions. PostgreSQL takes an exclusive lock on the migration history table. Use layerWith for a custom prefix or layerMigrations and layerStorage to migrate separately.

Signature

declare const layer: Layer.Layer<MessageStorage.MessageStorage, never, SqlClient.SqlClient | ShardingConfig | Crypto.Crypto>
Since v4.1.0

Runs the SQL message storage migrations without providing storage.

Details

Use an owner connection in a deploy step, then use layerStorage with a DML-only runtime connection. History is recorded in <prefix>_migrations. Migration errors become defects.

On PostgreSQL, use the role's search_path to select a schema. A schema-qualified prefix such as app.cluster produces an invalid index name.

Signature

declare function layerMigrations(options: {
readonly prefix?: string;
}): Layer<never, never, SqlClient>
Since v4.1.0

Provides SQL-backed MessageStorage without DDL or startup schema checks.

Details

Run layerMigrations separately before using this layer. This layer supplies Snowflake.layerGenerator internally.

Signature

declare function layerStorage(options: {
readonly prefix?: string;
}): Layer<MessageStorage, never, Crypto | ShardingConfig | SqlClient>

layerWith

unstable
Since v4.0.0

Provides SQL-backed MessageStorage with a custom table prefix, running migrations first.

Details

Migration errors become defects. Use layerMigrations and layerStorage to migrate separately.

Signature

declare function layerWith(options: {
readonly prefix?: string;
}): Layer<MessageStorage, never, Crypto | ShardingConfig | SqlClient>

Migrations

migrations

unstable
Since v4.1.0

Migration loader for the SQL message storage tables.

Details

History is recorded in <prefix>_migrations; the default prefix is cluster.

Signature

declare function migrations(options?: {
readonly prefix?: string;
}): Loader