pub async fn setup(
client: &Client,
cluster_size: &str,
emulator: bool,
) -> Result<(), CliError>Expand description
Bring the deployment tracking infrastructure up to the current schema.
The only function in this crate that mutates _mz_deploy. Every statement
is idempotent so re-running setup against an existing installation
heals drift (missing tables, missing grants) without losing data.
Phases:
- Create the
_mz_deploy_servercluster if missing. - Create the
_mz_deploydatabase (IF NOT EXISTS). - Run every statement in
SETUP_STATEMENTS— each usesIF NOT EXISTSso existing objects are left alone. Seed the version row with a pre-check (noINSERT IF NOT EXISTSform). - RBAC-enabled clusters only: create the three
materialize_*roles if missing and re-apply grants.
When RBAC is disabled — or the profile sets emulator = true, which forces
the RBAC-disabled path via rbac_active — the role/grant phase is skipped
entirely: no roles are created, no grants are issued, no ownership check is
performed. Without RBAC, GRANT statements would have no effect anyway and
downstream commands fall through to the superuser path in
validate_connection.
When RBAC is enabled, require_superuser gates phase 4 because the
GRANT ... ON SYSTEM statements (CREATEDB, CREATECLUSTER) and CREATE ROLE
require it. The superuser also needs:
- Ownership of
_mz_deploy_server(granted at creation in phase 1) toGRANT USAGEon it. CREATEDBto create the database.CREATEROLEto create the roles.
Ordinary commands do not call this function — they call
verify and surface CliError::SetupRequired if it fails. See the
module docs for the full model.