Skip to main content

DatabaseConfig

Struct DatabaseConfig 

Source
pub struct DatabaseConfig {
Show 17 fields pub url: Option<String>, pub primary_url: Option<String>, pub replica_url: Option<String>, pub pool_size: usize, pub primary_pool_size: Option<usize>, pub replica_pool_size: Option<usize>, pub replica_fallback: ReplicaFallback, pub read_your_writes: ReadYourWrites, pub pin_after_write_secs: u64, pub connect_timeout_secs: u64, pub startup_wait_secs: u64, pub auto_migrate_in_production: bool, pub statement_timeout: Option<Duration>, pub slow_query_threshold: Duration, pub shards: Vec<ShardConfig>, pub directory_shard_router: bool, pub max_connections_warn_threshold: usize,
}
Expand description

Database connection configuration.

When url is None (the default), the application runs without a database – useful for static-site or API-gateway use cases. Set a Postgres URL to enable the connection pool and the Db extractor.

§Defaults

FieldDefault
urlNone
primary_urlNone
replica_urlNone
pool_size10
primary_pool_sizeNone
replica_pool_sizeNone
replica_fallbackfail_readiness
connect_timeout_secs5
auto_migrate_in_productionfalse
shards[]

§Examples

use autumn_web::config::DatabaseConfig;

let db = DatabaseConfig::default();
assert!(db.url.is_none());
assert_eq!(db.pool_size, 10);

Fields§

§url: Option<String>

Postgres connection URL. None means no database is configured.

Compatibility alias for the primary/write role. New multi-role deployments should prefer primary_url.

When present, must start with postgres:// or postgresql://, or be a libpq-style keyword/value connection string (host=db user=app dbname=app sslmode=require).

§primary_url: Option<String>

Postgres URL for the primary/write role.

All writes, transactions, advisory locks, and migrations use this role. When unset, url remains the single-primary fallback.

§replica_url: Option<String>

Optional Postgres URL for the read/replica role.

Read-only paths may use this pool when configured. If omitted, read paths use the primary role.

§pool_size: usize

Maximum number of connections in the pool. Default: 10.

Compatibility/default pool size used for both roles unless a role-specific size is set.

§primary_pool_size: Option<usize>

Optional primary/write role pool size.

§replica_pool_size: Option<usize>

Optional read/replica role pool size.

§replica_fallback: ReplicaFallback

Deterministic behavior for configured replicas that cannot safely serve reads. Default: fail readiness.

§read_your_writes: ReadYourWrites

Post-write read pinning strategy. Default: off (no pinning).

Set to request to pin reads to the primary for the remainder of the request after the first write. Set to session to additionally pin reads across requests via a signed cookie.

Override via AUTUMN_DATABASE__READ_YOUR_WRITES.

§pin_after_write_secs: u64

Duration (seconds) for cross-request session pins.

Only used when read_your_writes = "session". A signed autumn.ryw cookie pins the client’s reads to the primary for this many seconds after a write. Default: 5.

Override via AUTUMN_DATABASE__PIN_AFTER_WRITE_SECS.

§connect_timeout_secs: u64

Seconds to wait while acquiring a pooled connection, including creating a new connection when the pool grows. Default: 5.

§startup_wait_secs: u64

Bounded startup wait (seconds) for the database to become reachable before the migrator fails. 0 (the default) disables the wait and preserves the current fail-fast behaviour — a single connection attempt, no retry. Set a non-zero value (e.g. 60) to have autumn migrate retry with capped exponential backoff until either the database accepts connections or the window elapses.

Override via AUTUMN_DATABASE__STARTUP_WAIT_SECS.

§auto_migrate_in_production: bool

When true, permits automatic migration application while running with prod/production profile. Default: false.

Keep this disabled for multi-replica production fleets and use an explicit migration job (autumn migrate) instead.

§statement_timeout: Option<Duration>

Optional database statement timeout.

§slow_query_threshold: Duration

Slow query threshold. Default: 500ms.

§shards: Vec<ShardConfig>

Horizontal shards, declared as [[database.shards]] entries.

Empty (the default) means the application is unsharded and only the url/primary_url/replica_url roles above apply. When non-empty, those top-level roles become the control topology — framework state (jobs, scheduler locks, sessions, feature flags) lives there while tenant data is routed across the shards. See ShardConfig.

§directory_shard_router: bool

Route tenants through the control-plane _autumn_shard_directory table (a DirectoryShardRouter) instead of pure slot-hash routing. Default: false.

Tenants with a directory row are pinned to the named shard; everyone else falls back to the hash router. Usually set via AppBuilder::with_directory_shard_router. Ignored when no shards are configured or an explicit with_shard_router is set.

§max_connections_warn_threshold: usize

Emit a startup warning when the aggregate maximum connection count across the control topology and every shard pool reaches this value. Default: 100.

Pool sizes multiply across shards: an N-shard fleet with a pool size of 20 opens up to 20 * N connections, which can exhaust Postgres’s max_connections (default 100) long before the app looks busy. This threshold surfaces that footgun at boot. Set to 0 to disable.

Implementations§

Source§

impl DatabaseConfig

Source

pub fn effective_primary_url(&self) -> Option<&str>

Resolved primary/write database URL.

Source

pub fn effective_primary_pool_size(&self) -> usize

Resolved primary/write role pool size.

Source

pub fn effective_replica_pool_size(&self) -> usize

Resolved read/replica role pool size.

Source

pub const fn has_shards(&self) -> bool

Whether any [[database.shards]] entries are configured.

Source

pub fn resolved_slot_map(&self) -> Result<Vec<usize>, ConfigError>

Resolve the slot→shard map: element s is the index (into shards) of the shard that owns slot s.

This is the single source of truth for slot assignment, used by both configuration validation and runtime ShardSet construction:

  • When no shard declares slots, the slot space is auto-split into contiguous even ranges by declaration order.
  • When every shard declares slots, the explicit assignments are used and must cover 0..SLOT_COUNT exactly once.
  • Mixing declared and undeclared slots is an error.
§Errors

Returns ConfigError::Validation for mixed declarations, malformed/out-of-range/duplicate slots, or incomplete coverage.

Source

pub fn shards_auto_split(&self) -> bool

Whether all shards are using auto-split (no shard declares slots).

Returns false when no shards are configured or any shard has an explicit slots declaration. Mixed declarations already error in resolved_slot_map, so this is a simple all-or-none check.

Source

pub fn resolved_shard_assignments( &self, ) -> Result<Vec<ShardSlotAssignment>, ConfigError>

Resolve the per-shard slot assignment as compact range strings.

Inverts resolved_slot_map (slot→shard-index) into per-shard slot lists rendered via the same compact range notation used in slot-map error messages. Agrees with runtime routing by construction: the output derives from the same slot map that builds the live ShardSet.

§Errors

Propagates any ConfigError from resolved_slot_map.

Source

pub fn validate(&self) -> Result<(), ConfigError>

Validate database configuration.

§Errors

Returns a validation error if a connection string is malformed or a shard declaration is malformed.

Trait Implementations§

Source§

impl Clone for DatabaseConfig

Source§

fn clone(&self) -> DatabaseConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DatabaseConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DatabaseConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for DatabaseConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AutumnDependents for T
where T: ?Sized,

Source§

fn dependents() -> &'static [RuntimeDependentSpec]

The model’s dependent-cascade specs, in declaration order. Defaults to none; #[model] overrides via an inherent shadow when dependents exist.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> RepositoryHooksClone for T
where T: Clone,

Source§

fn autumn_clone(&self) -> T

Clone hook state for generated repository values.
Source§

impl<T> RepositoryHooksDefault for T
where T: Default,

Source§

fn autumn_default() -> T

Construct a hook instance for generated repository state.
Source§

impl<T, Conn> RunQueryDsl<Conn> for T

Source§

fn execute<'conn, 'query>( self, conn: &'conn mut Conn, ) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
where Conn: AsyncConnectionCore + Send, Self: ExecuteDsl<Conn> + 'query,

Executes the given command, returning the number of rows affected. Read more
Source§

fn load<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
where U: Send, Conn: AsyncConnectionCore, Self: LoadQuery<'query, Conn, U> + 'query,

Executes the given query, returning a Vec with the returned rows. Read more
Source§

fn load_stream<'conn, 'query, U>( self, conn: &'conn mut Conn, ) -> Self::LoadFuture<'conn>
where Conn: AsyncConnectionCore, U: 'conn, Self: LoadQuery<'query, Conn, U> + 'query,

Executes the given query, returning a [Stream] with the returned rows. Read more
Source§

fn get_result<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
where U: Send + 'conn, Conn: AsyncConnectionCore, Self: LoadQuery<'query, Conn, U> + 'query,

Runs the command, and returns the affected row. Read more
Source§

fn get_results<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
where U: Send, Conn: AsyncConnectionCore, Self: LoadQuery<'query, Conn, U> + 'query,

Runs the command, returning an Vec with the affected rows. Read more
Source§

fn first<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<<Self::Output as LoadQuery<'query, Conn, U>>::LoadFuture<'conn>, LoadNext<Pin<Box<<Self::Output as LoadQuery<'query, Conn, U>>::Stream<'conn>>>>>
where U: Send + 'conn, Conn: AsyncConnectionCore, Self: LimitDsl, Self::Output: LoadQuery<'query, Conn, U> + Send + 'query,

Attempts to load a single record. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scoped for T
where T: Send + Sync + 'static,

Source§

fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>

Open a deferred ScopeQuery for this type. Resolves the registered scope at .load() time, not here.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more