Operations
Configuration Sync
Manage active database configuration alongside Git-tracked canonical JSON in config/sync/ with dry-run previews, atomic imports, and immutable rollback snapshots.
Configuration Sync
PhrameCMS separates active runtime configuration from Git-tracked canonical configuration so content models, entity types, bundles, field definitions, and site settings can be code-reviewed, diffed cleanly, and deployed safely across environments.
Active Storage vs. Sync Storage
PhrameCms\Config\ConfigManager coordinates three pluggable stores (wired in phramecms/skeleton by App\AppBootstrap):
- Active storage (
DatabaseConfigStorage): Persists live configuration objects in thephrame_configdatabase table (name,data, SHA-256hash,updated_at). All runtime reads resolve from here. - Sync storage (
FileConfigStorage): Reads and writes<name>.jsonfiles insideconfig/sync/(configurable viaPHRAME_CONFIG_SYNC_DIR). - Snapshot store (
DatabaseSnapshotStore): Appends immutable, timestamped full-configuration snapshots (snap_<hex>) to thephrame_config_snapshotstable before every live mutation (config.set,config.delete,config.import, andconfig.rollback).
Canonical JSON & Naming Rules
- Every configuration name must match
^[a-z0-9_]+(\.[a-z0-9_]+)+$(at least two dot-separated lowercase alphanumeric/underscore segments, such asadmin.settingsorentity.bundle.content.article). PhrameCms\Config\Canonicalizerrecursively sorts associative keys (SORT_STRING) while preserving list order, formats JSON withJSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODEand a trailing LF newline, and computes deterministic SHA-256 hashes. This eliminates noisy diffs in Git and enables reliable optimistic concurrency checks.- Before any write or import,
ConfigManager::validate()checks each configuration object against the most specific matchingConfigSchemaProviderInterfaceregistered in the container. Onconfig.import, all incoming objects are validated before any snapshot is taken or any storage row is modified.
Core Configuration Operations
All configuration operations execute through OperationBus and are available via CLI (./bin/phrame op:run), MCP tools (config_*), and the Admin UI (/admin/config). The HTTP API (/api/v1/config*) exposes config.list, config.diff, config.get, config.set, and config.delete, while bulk sync and snapshot operations (config.export, config.import, config.snapshots, config.rollback) are executed through CLI, MCP, or /admin/config.
| Operation | Required Permission | Dry-Run | Key Input Parameters |
|---|---|---|---|
config.list |
config.read |
No | prefix (optional string) |
config.get |
config.read or config.<name>.read |
No | name (required) |
config.diff |
config.read |
No | prefix, plus at most one of directory, configs, or snapshot_id (defaults to configured sync storage) |
config.set |
config.write or config.<name>.write |
Yes | name (required), data (required object), reason (optional) |
config.delete |
config.write or config.<name>.write |
Yes | name (required), reason (optional) |
config.export |
config.export |
Yes | prefix, directory (optional override), delete_extra (boolean, default true) |
config.import |
config.import |
Yes | prefix, delete_missing (boolean; defaults to true for sync/directory imports and false for inline configs), reason, plus at most one of configs or directory (defaults to configured sync storage) |
config.snapshots |
config.read |
No | limit (integer 1–500, default 50) |
config.rollback |
config.import |
Yes | snapshot_id (required), reason (optional) |
Granular per-object permissions:
config.get,config.set, andconfig.deleteenforceConfigPermissionGuard, accepting either the coarse permission (config.read/config.write) or the object-specific permission (config.<name>.read/config.<name>.write, e.g.,config.admin.settings.write).
Day-to-Day Git Sync Workflow
1. Export Active Configuration to config/sync/
After making schema or settings changes locally (in /admin/schema, /admin/appearance, or via operations), export them to canonical JSON files in config/sync/:
# Preview what would change in config/sync/ without writing files
./bin/phrame op:run config.export --dry-run --scopes=config.export --json
# Write canonical JSON files into config/sync/
./bin/phrame op:run config.export --scopes=config.exportInspect git diff config/sync/ and commit the canonical JSON files to your repository.
2. Inspect Differences (config.diff)
Compare active database configuration against config/sync/ (or pass snapshot_id to diff against a snapshot):
./bin/phrame op:run config.diff --scopes=config.read --json
# Limit diff to a prefix (for example, admin.* settings only)
./bin/phrame op:run config.diff --scopes=config.read --input='{"prefix":"admin."}' --jsonThe response includes empty (bool) and a structured diff object with created, updated, and deleted arrays (each entry holding name, before, and after).
3. Preview and Apply Imports (config.import)
In staging or production deployments, always preview with --dry-run first, then run the atomic import:
# Dry-run: validate all files in config/sync/ and return the diff with zero writes
./bin/phrame op:run config.import --dry-run --scopes=config.import --json
# Live import: creates an automatic pre-import snapshot, then applies all changes atomically
./bin/phrame op:run config.import --scopes=config.import --input='{"reason":"Release 2026.11"}' --jsonIf any write fails mid-import, ConfigManager::applyDiffAtomically() rolls back previously applied creates, updates, and deletes in-memory/storage and rethrows the exception. On success, data.snapshot_id contains the ID of the snapshot taken right before the import, and a ConfigChangedEvent is dispatched over PSR-14.
4. Edit or Delete a Single Config Object (config.set / config.delete)
# Preview updating admin.settings
./bin/phrame op:run config.set --dry-run --scopes=config.admin.settings.write \
--input='{"name":"admin.settings","data":{"brand_name":"Acme CMS","theme":"default"},"reason":"Update brand"}' \
--json
# Apply live
./bin/phrame op:run config.set --scopes=config.admin.settings.write \
--input='{"name":"admin.settings","data":{"brand_name":"Acme CMS","theme":"default"},"reason":"Update brand"}'
# Delete a configuration object (also captures a snapshot first)
./bin/phrame op:run config.delete --scopes=config.write \
--input='{"name":"site.feature_flags","reason":"Remove deprecated flags"}'Snapshots and Reversible Rollback
Every live config.set, config.delete, and config.import records an immutable snapshot of the entire active configuration map in phrame_config_snapshots via DatabaseSnapshotStore.
List recent snapshots (newest first):
./bin/phrame op:run config.snapshots --scopes=config.read --input='{"limit":10}' --jsonPreview and execute a rollback to any prior snapshot:
# Dry-run rollback to inspect exact changes
./bin/phrame op:run config.rollback --dry-run --scopes=config.import \
--input='{"snapshot_id":"snap_<id>"}' --json
# Execute rollback (automatically creates a pre-rollback snapshot so the rollback itself is reversible)
./bin/phrame op:run config.rollback --scopes=config.import \
--input='{"snapshot_id":"snap_<id>","reason":"Revert unintended import"}' --jsonBecause config.rollback saves a pre_rollback_snapshot_id before restoring the target snapshot, even a rollback can be undone cleanly.
Related Guides
- Architecture Overview — How
ConfigModuleinteracts withEntityModule,AdminModule, andOperationBus. - AI Change Proposals & Human Approval Queue — Stage AI-generated
config.setorconfig.importchanges for human approval instead of granting live write access. - Security & Production Deployment — Keep secrets in
.env, never inconfig/sync/.