cedros-data (server crate)
cedros-data is a single Rust crate for storing one site's content and custom data in PostgreSQL.
The crate is library-first and includes optional embedded HTTP and CLI modes in the same package.
Core guarantees
- One required env var only:
POSTGRES_URI - No built-in auth logic in the core data layer
- Preserve incoming field names exactly as provided
- JSONB compatibility mode and typed-table mode
- Idempotent schema operations
- Roll-forward schema evolution only (no destructive auto-drop)
Install and features
[]
= "0.1"
Feature flags:
- default:
cli,http cli: enablescedros-databinary commandshttp: enables embedded Axum servercedros-login-profile: optional compatibility profile for delegating HTTP auth/authz to cedros-login
Required environment variable
No other environment variable is required by default.
Quick start
Embedded HTTP now fails closed by default. Use --allow-unauthenticated only for local development, or enable the Cedros compatibility profile for authenticated environments.
To allow cross-origin browser admin clients, repeat --cors-origin for each trusted origin:
serve startup automatically:
- runs base migrations
- creates the default deployment record on fresh databases
- bootstraps default collections and default entries for the active deployment
Rust API
use ;
async
Primary API methods:
migrate()register_site()register_collection()register_custom_schema()upsert_entry()query_entries()export_site()import_site()verify_contract()bootstrap_defaults()
Base schema and data model
Base migration creates:
sitecollectionsentriescollection_contractscustom_schema_statecustom_schema_migrations
The active deployment has:
- a row in
site - a dedicated PostgreSQL schema for typed tables and custom schema objects
- default JSONB collections:
pagesnavigationsite_settings
Default seeded pages:
homeaboutcontactdocsblogprivacy-policyterms-of-servicenot-found
Additional seeded entries:
navigation/mainsite_settings/global
Singleton guarantee:
cedros-datastores site metadata in the singletonsitetable- runtime code always addresses the installation-scoped row with
id = 1
Storage modes
jsonbmode:- flexible ingestion into shared
entriestable - preserves field names exactly
- flexible ingestion into shared
typedmode:- stores rows in deployment-specific typed tables
- keeps JSON payload for compatibility and export/import workflows
Custom schema registration
register_custom_schema supports deployment-scoped registration of:
- custom enum/composite types
- custom tables and columns
- indexes
- unique constraints
- foreign keys
Behavior:
- validates schema diff before apply
- reports additive vs breaking changes
- applies additive roll-forward changes only
- does not auto-drop existing objects
- stores versioned state and generated migration statements
CLI commands
verify-contract behavior:
- reports additive and breaking changes
- exits non-zero only on breaking changes
Embedded HTTP API
Run HTTP mode:
If you are not enabling the Cedros compatibility profile, add --allow-unauthenticated for local-only usage:
CORS behavior:
- same-origin requests remain unchanged by default
- cross-origin browser clients require one or more explicit
--cors-originvalues - allowed methods are limited to
GET,POST,PUT, and preflightOPTIONS - allowed headers cover the shipped admin client request shape:
Authorization,Content-Type,Accept, andx-cedros-org-id
Core endpoints:
POST /migratePOST /sitePOST /collectionsPOST /custom-schemaPOST /entries/upsertPOST /entries/queryGET /site/exportPOST /importPOST /contract/verify
Admin endpoints:
GET /admin/default-pagesPOST /admin/bootstrapGET /admin/collectionsPOST /admin/collectionsGET /admin/pagesPUT /admin/pages/{page_key}
Optional Cedros compatibility profile
Core cedros-data remains auth-agnostic.
The Cedros compatibility profile is opt-in and only affects HTTP mode.
In profile mode:
- derives the permissions endpoint from the configured verify URL
- authenticates and authorizes each request through the cedros-login permissions endpoint
- uses a shared HTTP client with a 2s connect timeout and 5s total request timeout
- resolves org scope from
x-cedros-org-idheader - enforces route-level
data:*permissions before data operations - fails closed when org scope cannot be resolved
- surfaces cedros-login timeouts/rate limits as gateway-style availability errors
For full route/permission details see docs/profiles.md.
Examples
examples/generic_blog.rsexamples/cedros_compat_profile.rs