oxify_storage/
lib.rs

1//! OxiFY Storage - SQLite persistence layer
2//!
3//! This crate provides database storage for workflows and executions using SQLite.
4//!
5//! # Architecture Overview
6//!
7//! ## Connection Pooling Strategy
8//!
9//! The storage layer uses `sqlx::SqlitePool` for connection management with the following strategy:
10//!
11//! ### Configuration
12//! - **Max Connections**: Configurable (default: 10) - Upper limit of connections in pool
13//! - **Min Connections**: Configurable (default: 2) - Minimum idle connections to maintain
14//! - **Acquire Timeout**: 30 seconds - Maximum time to wait for an available connection
15//!
16//! ### Best Practices
17//! 1. Use WAL mode for better concurrency
18//! 2. Keep transactions short
19//! 3. Use pool methods, never create direct connections
20//!
21//! Example:
22//! ```ignore
23//! let config = DatabaseConfig {
24//!     database_url: "sqlite:oxify.db?mode=rwc".to_string(),
25//!     max_connections: 20,
26//!     min_connections: 5,
27//! };
28//! let pool = DatabasePool::new(config).await?;
29//! ```
30
31// Core modules (SQLite compatible) - minimal set
32// mod api_key_store;     // Disabled - needs Vec<String> conversion
33// pub mod archival;      // Disabled - needs Vec<Uuid> conversion
34// mod audit_log_store;   // Disabled - complex
35// pub mod backup;        // Disabled - complex
36// pub mod batch_ops;     // Disabled - complex
37pub mod cache;
38// pub mod cache_warmer;  // Disabled - uses WorkflowRow
39// mod checkpoint_store;  // Disabled - complex
40// mod cleanup;           // Disabled - complex
41pub mod connection_leak_detector;
42pub mod db_utils;
43mod encryption;
44mod error;
45mod execution_store;
46pub mod health;
47// pub mod jwks_cache;    // Disabled - complex
48pub mod maintenance;
49// pub mod maintenance_scheduler; // Disabled - complex
50pub mod metrics_exporter;
51// mod metrics_store;     // Disabled - needs major conversion
52pub mod migration_runner;
53pub mod migrations;
54mod models;
55pub mod pagination;
56mod pool;
57// pub mod pool_tuner;    // Disabled - complex
58pub mod query_builder;
59// pub mod query_profiler; // Disabled - complex
60// mod quota_store;       // Disabled - complex
61// #[cfg(feature = "redis-cache")]
62// pub mod redis_cache;   // Disabled - depends on quota_store
63pub mod retry;
64// mod schedule_store;    // Disabled - complex
65// pub mod schema_validator; // Disabled - complex
66// mod secret_store;      // Disabled - needs Vec<String> conversion
67// pub mod seeding;       // Disabled - uses PgPool
68pub mod soft_delete;
69// pub mod transaction;   // Disabled - uses Postgres Transaction
70mod user_store;
71pub mod validation;
72// pub mod vector_cache;  // Disabled - complex
73// pub mod webhook_delivery; // Disabled - complex
74// pub mod webhook_retry; // Disabled - complex
75// mod webhook_store;     // Disabled - needs major conversion
76mod workflow_store;
77mod workflow_version_store;
78
79// PostgreSQL-specific modules (disabled for SQLite)
80// pub mod advisory_lock;
81// pub mod bulk_copy;
82// pub mod comment_manager;
83// pub mod constraint_manager;
84// pub mod enum_manager;
85// pub mod explain_analyzer;
86// pub mod extension_manager;
87// pub mod fts;
88// pub mod index_analyzer;
89// pub mod jsonb_helpers;
90// pub mod materialized_view;
91// pub mod notify;
92// pub mod optimistic_lock;
93// pub mod partitioning;
94// pub mod read_replica;
95// pub mod rls_helper;
96// pub mod sequence_manager;
97// pub mod trigger_manager;
98// pub mod view_manager;
99
100// Minimal exports for SQLite migration
101pub use cache::{Cache, CacheConfig, CacheMetrics, CacheStats};
102pub use connection_leak_detector::{
103    ConnectionToken, LeakDetector, LeakDetectorConfig, LeakReport, LeakStats, SuspectedLeak,
104};
105pub use encryption::EncryptionService;
106pub use error::{ResourceId, ResourceType, Result, StorageError};
107pub use execution_store::ExecutionStore;
108pub use health::{ComponentHealth, HealthCheck, HealthCheckConfig, HealthReport, HealthStatus};
109pub use maintenance::{
110    IndexBloatInfo, MaintenanceConfig, MaintenanceResults, MaintenanceService, TableStats,
111};
112pub use metrics_exporter::{Metric, MetricType, MetricsExporter, MetricsFormat};
113pub use migration_runner::{Migration, MigrationRunner, MigrationStatus};
114pub use models::{ExecutionRow, UserPermissionRow, UserRoleRow, UserRow, WorkflowRow};
115pub use pagination::{
116    CursorDirection, PageInfo, PaginationBuilder, PaginationRequest, PaginationResponse,
117    PaginationStrategy,
118};
119pub use pool::{DatabasePool, PoolHealth, PoolMetrics, PoolStats};
120// #[cfg(feature = "redis-cache")]
121// pub use redis_cache::{RedisCache, RedisCacheConfig, TwoLevelCache};
122pub use soft_delete::{
123    SoftDeleteBuilder, SoftDeleteFilter, SoftDeleteMetadata, SoftDeleteRestorer,
124};
125pub use user_store::UserStore;
126pub use workflow_store::{
127    BulkOperationResult, ConflictStrategy, ImportError, ImportOptions, ImportResult,
128    WorkflowExport, WorkflowStore,
129};
130pub use workflow_version_store::{VersionComparison, WorkflowVersion, WorkflowVersionStore};
131
132/// Database configuration
133#[derive(Debug, Clone)]
134pub struct DatabaseConfig {
135    /// SQLite connection URL
136    pub database_url: String,
137    /// Maximum number of connections in pool
138    pub max_connections: u32,
139    /// Minimum number of idle connections
140    pub min_connections: u32,
141}
142
143impl Default for DatabaseConfig {
144    fn default() -> Self {
145        Self {
146            database_url: std::env::var("DATABASE_URL")
147                .unwrap_or_else(|_| "sqlite:oxify.db?mode=rwc".to_string()),
148            max_connections: 10,
149            min_connections: 2,
150        }
151    }
152}