Repository navigation
Description
What is the problem this feature would solve?
SqlMessageStorage and SqlRunnerStorage create and migrate their tables
every time they are constructed, using the runtime's SqlClient. That makes
the runtime database role need DDL privileges, which many deployments do not
grant:
- the app role has DML only, and schema changes go through a deploy step run
by the role that owns the tables; - on PostgreSQL 15+
publicno longer grantsCREATEto everyone; - some deployments refuse to start if the app role owns any table (a guard
that keeps row-level security from being bypassed by ownership).
SqlMessageStorage can be worked around by applying the migrations
beforehand: the Migrator sees them recorded and runs nothing. But
SqlRunnerStorage.make always runs CREATE TABLE IF NOT EXISTS, and
PostgreSQL checks CREATE on the schema even when the table exists:
-- as a role with SELECT/INSERT/UPDATE/DELETE on cluster_runners, no CREATE on public (PG 18.3)
CREATE TABLE IF NOT EXISTS cluster_runners (...);
ERROR: permission denied for schema public
So today the runtime role must hold CREATE on the schema the cluster tables
live in.
What is the feature you are proposing to solve the problem?
migrate?: booleanonSqlMessageStorage.make/makeEncoded/
layerWithandSqlRunnerStorage.make/layerWith, defaulttrue
(today's behaviour). Withmigrate: falsethe storages issue no DDL.
SqlMessageStorageinstead checks the migrations table and fails at startup,
naming any migration this version depends on that is not applied.
SqlRunnerStoragechecks that its tables are readable.SqlMessageStorage.migrate(options)andSqlRunnerStorage.migrate(options)
export the DDL the storages run today as effects, so a deploy step can apply
it with an owner connection. The DDL stays single-sourced in effect, and an
upgrade that adds a migration is applied by the same step.
// deploy step, connected as the owner
yield* SqlMessageStorage.migrate({ prefix: "cluster" })
yield* SqlRunnerStorage.migrate({ prefix: "cluster" })
// runtime, DML-only role
SqlMessageStorage.layerWith({ prefix: "cluster", migrate: false })
SqlRunnerStorage.layerWith({ prefix: "cluster", migrate: false })I have a working implementation, with a PostgreSQL integration test covering
three cases: a DML-only role runs on migrated tables, the same
role fails with AuthorizationError without the option, and a missing
migration is reported by name. The existing SQL storage suites pass (pg,
mysql, sqlite). I'm happy to open it as a PR if the shape looks right.
What alternatives have you considered?
- Granting the runtime role
CREATEon a dedicated schema. This works, and is
our interim, but it gives the runtime more than it needs. - Recreating the DDL in our own migration tool. This duplicates effect's
schema, and every upgrade that adds a cluster migration needs a hand-copied
migration. - Related: Add support in SqlRunnerStorage and SqlMessageStorage for setting schema #5922 asked for a schema option for the same tables and was closed
as stale. With this change, asearch_pathon the runtime role covers that
need (a schema-qualifiedprefixbreaks the<prefix>_messages_rowid_idx
index name in migration 0003).
Activity
bweis commentedon Oct 8, 2026
Implementation for reference: main...bweis:effect:cluster-externally-managed-tables
It adds
migrate: falseto both storages, exportsSqlMessageStorage.migrateandSqlRunnerStorage.migrate, and includes a PostgreSQL integration test and a changeset. Happy to open it as a PR or reshape it.