Skip to content

SqlMessageStorage: export an encoded storage constructor that skips migrations #9321

Closed

Description

@IgnisDa

What is the problem this feature would solve?

Follow-up to #8894. effect 4.0.5 lets the runtime use SQL cluster storage without running DDL: SqlMessageStorage.layerMigrations runs the migrations in a deploy step, and SqlMessageStorage.layerStorage builds a MessageStorage without them.

There is no equivalent for the encoded driver. SqlMessageStorage.makeEncoded always runs the migrations first:

export const makeEncoded = (options) =>
  Effect.andThen(runMessageMigrations(options), makeEncodedStorage(options))

makeEncodedStorage isn't exported. So a custom adapter has to call makeEncoded, and with it the migrator, at runtime. A custom adapter here means one that wraps the SQL driver's MessageStorage.Encoded and then calls MessageStorage.makeEncoded, for example to run extra bookkeeping in the same transaction as saveEnvelope/saveReply. Such an adapter can't use layerStorage, because that returns an already-decoded MessageStorage.

const storage = yield* SqlMessageStorage.makeEncoded() // always migrates
return yield* MessageStorage.makeEncoded({
  ...storage,
  saveEnvelope: (options) => sql.withTransaction(Effect.andThen(bookkeeping(options), storage.saveEnvelope(options)))
})

Even when layerMigrations has already applied everything, the migrator still runs at every startup: it ensures the history table exists and takes LOCK TABLE cluster_migrations IN ACCESS EXCLUSIVE MODE. That means the runtime role needs privileges on the history table, and the "migrate in a deploy step" setup from #8894 doesn't fully work for custom adapters.

What is the feature you are proposing to solve the problem?

Export an encoded constructor that skips migrations, matching layerStorage. For example:

What alternatives have you considered?

  • Deep-importing the unexported constructor: this depends on private module paths.
  • Keeping makeEncoded and letting the migrator no-op: this works, but still takes the exclusive lock on the history table and needs DDL-adjacent privileges at runtime.

Activity

  1. self-assigned this
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions