duroxide_pg/lib.rs
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! # Duroxide PostgreSQL Provider
5//!
6//! A PostgreSQL-based provider implementation for [Duroxide](https://crates.io/crates/duroxide),
7//! a durable task orchestration framework for Rust.
8//!
9//! ## Usage
10//!
11//! ```rust,no_run
12//! use duroxide_pg::PostgresProvider;
13//! use duroxide::runtime::Runtime;
14//! use std::sync::Arc;
15//!
16//! # async fn example() -> anyhow::Result<()> {
17//! // Create a provider with the database URL
18//! let provider = PostgresProvider::new("postgres://user:password@localhost:5432/mydb").await?;
19//!
20//! // Use with the Duroxide runtime
21//! // let runtime = Runtime::start_with_store(Arc::new(provider), activity_registry, orchestration_registry).await;
22//! # Ok(())
23//! # }
24//! ```
25//!
26//! ## Custom Schema
27//!
28//! To isolate data in a specific PostgreSQL schema (useful for multi-tenant deployments):
29//!
30//! ```rust,no_run
31//! use duroxide_pg::PostgresProvider;
32//!
33//! # async fn example() -> anyhow::Result<()> {
34//! let provider = PostgresProvider::new_with_schema(
35//! "postgres://user:password@localhost:5432/mydb",
36//! Some("my_schema"),
37//! ).await?;
38//! # Ok(())
39//! # }
40//! ```
41//!
42//! ## Microsoft Entra ID Authentication
43//!
44//! Connect to Azure Database for PostgreSQL Flexible Server using an Entra
45//! access token. A background task refreshes the token before expiry. See
46//! [`EntraAuthOptions`] for tunables.
47//!
48//! ```rust,no_run
49//! use duroxide_pg::{EntraAuthOptions, PostgresProvider, ProviderConfig};
50//!
51//! # async fn example() -> anyhow::Result<()> {
52//! let config = ProviderConfig::entra(
53//! "myserver.postgres.database.azure.com",
54//! 5432,
55//! "mydb",
56//! "my-entra-principal@contoso.onmicrosoft.com",
57//! EntraAuthOptions::new(),
58//! );
59//! let provider = PostgresProvider::new_with_config(config).await?;
60//! # Ok(())
61//! # }
62//! ```
63//!
64//! All Entra connections use `PgSslMode::VerifyFull`. The default credential
65//! chain is `[WorkloadIdentityCredential (added only when AKS federated env
66//! vars are present), ManagedIdentityCredential, DeveloperToolsCredential]`,
67//! which works for AKS Workload Identity, other Azure-hosted managed
68//! identities, and developer workstations logged in via `az login`.
69//!
70//! ## Configuration
71//!
72//! | Environment Variable | Description | Default |
73//! |---------------------|-------------|---------|
74//! | `DUROXIDE_PG_POOL_MAX` | Maximum connection pool size | `10` |
75//!
76//! ## Features
77//!
78//! - Automatic schema migration on startup
79//! - Connection pooling via sqlx
80//! - Custom schema support for multi-tenant isolation
81//! - Full implementation of the Duroxide `Provider` and `ProviderAdmin` traits
82
83pub mod entra;
84pub mod migrations;
85pub mod provider;
86
87pub use entra::EntraAuthOptions;
88pub use provider::{ConnectionConfig, MigrationPolicy, PostgresProvider, ProviderConfig};