Skip to main content

Module feature_flags

Module feature_flags 

Source
Expand description

rustio_feature_flags — a tiny project-side feature-flag surface. Projects flip a named flag from the admin UI; project code reads it via feature_enabled without paying for a Postgres round-trip on every call.

Schema:

CREATE TABLE rustio_feature_flags (
    key         TEXT        PRIMARY KEY,
    enabled     BOOLEAN     NOT NULL DEFAULT FALSE,
    description TEXT        NOT NULL DEFAULT '',
    created_at  TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at  TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

Reads go through a process-local 60-second cache (mirrors the permissions cache pattern). The cache is per-key — a single flag flip refreshes only that key’s entry.

The admin UI at /admin/feature_flags lets administrators create / toggle / describe flags. Project code calls feature_enabled from request handlers, background jobs, migrations — anywhere a Db is in scope.

Structs§

FeatureFlag
One feature flag’s stored state. Surfaced by [list_flags] for the admin UI; project code reads booleans via feature_enabled.

Functions§

ensure_table
Ensure the rustio_feature_flags table exists. Idempotent.
feature_enabled
true when the named flag is set and enabled = TRUE. Missing keys read as false. Reads go through a 60-second per-key cache so hot paths stay cheap.
invalidate_cache
Drop every cached entry. Called by [set_flag] / [create_flag] so a fresh write is observable on the next read without waiting for the TTL.