Skip to content

Cluster SQL storages: allow externally managed tables (no DDL at runtime) #8894

Closed

Description

@bweis

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+ public no longer grants CREATE to 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?

  1. migrate?: boolean on SqlMessageStorage.make / makeEncoded /
    layerWith and SqlRunnerStorage.make / layerWith, default true
    (today's behaviour). With migrate: false the storages issue no DDL.
    SqlMessageStorage instead checks the migrations table and fails at startup,
    naming any migration this version depends on that is not applied.
    SqlRunnerStorage checks that its tables are readable.
  2. SqlMessageStorage.migrate(options) and SqlRunnerStorage.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 CREATE on 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, a search_path on the runtime role covers that
    need (a schema-qualified prefix breaks the <prefix>_messages_rowid_idx
    index name in migration 0003).

Activity

  1. bweis commented on Oct 8, 2026

    @bweis
    ContributorAuthor

    Implementation for reference: main...bweis:effect:cluster-externally-managed-tables

    It adds migrate: false to both storages, exports SqlMessageStorage.migrate and SqlRunnerStorage.migrate, and includes a PostgreSQL integration test and a changeset. Happy to open it as a PR or reshape it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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