pipedash_core/infrastructure/database/
mod.rs1use std::path::Path;
2
3mod metrics_repository;
4mod pipeline_view_repository;
5mod push_repository;
6mod repository;
7mod schema;
8mod sqlite_backend;
9
10#[cfg(feature = "postgres")]
11mod postgres_backend;
12
13pub use metrics_repository::{
14 MetricsRepository,
15 RecordMetrics,
16};
17pub use pipeline_view_repository::{
18 PipelineViewRepository,
19 StoredMember,
20 StoredPin,
21 StoredView,
22 ViewExport,
23};
24#[cfg(feature = "postgres")]
25pub use postgres_backend::PostgresConfigBackend;
26pub use push_repository::PushRepository;
27pub use repository::{
28 DatabasePool,
29 ProviderFetchStatus,
30 Repository,
31};
32pub(crate) use repository::{
33 FETCH_STATUS_ERROR,
34 FETCH_STATUS_NEVER,
35 FETCH_STATUS_SUCCESS,
36};
37pub use schema::init_database;
38#[cfg(feature = "postgres")]
39pub use schema::init_postgres_database;
40pub use sqlite_backend::SqliteConfigBackend;
41
42pub async fn has_encrypted_tokens(db_path: &Path) -> bool {
43 if !db_path.exists() {
44 return false;
45 }
46
47 let db_url = format!("sqlite:{}?mode=ro", db_path.display());
48
49 let pool = match sqlx::SqlitePool::connect(&db_url).await {
50 Ok(pool) => pool,
51 Err(e) => {
52 tracing::debug!(
53 "Could not connect to database to check encrypted tokens: {}",
54 e
55 );
56 return false;
57 }
58 };
59
60 let result: Result<i64, _> = sqlx::query_scalar(
61 "SELECT COUNT(*) FROM providers WHERE encrypted_token IS NOT NULL AND token_nonce IS NOT NULL"
62 )
63 .fetch_one(&pool)
64 .await;
65
66 let has_tokens = result.map(|count| count > 0).unwrap_or(false);
67
68 tracing::debug!(
69 "Checked for encrypted tokens in {}: {}",
70 db_path.display(),
71 if has_tokens { "found" } else { "none" }
72 );
73
74 has_tokens
75}