1 parent
95c0587c1e
commit
5b22add1f3
21 files changed
+293
-89
No files matched your search
@@ -6,7 +6,6 @@ use sqlx::{FromRow, MySqlPool, PgPool};
|
||||
|
||||
use super::{PersistedSession, SessionPersistence};
|
||||
use crate::config::AppConfig;
|
||||
use crate::db::pool::{DatabaseBackend, global_schema_for_backend};
|
||||
use crate::queries;
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -149,20 +148,15 @@ pub struct DatabaseSessionStore {
|
||||
|
||||
impl DatabaseSessionStore {
|
||||
pub async fn connect(config: &AppConfig) -> Result<Self, String> {
|
||||
// Schema ownership is centralized in db::pool::configure(). Calling it here
|
||||
// keeps direct/test construction safe, while the normal application startup
|
||||
// hits the OnceLock fast path. Do not run schema.sql again from this store:
|
||||
// that used to duplicate DDL for SQLite/MySQL/PostgreSQL and produced repeated
|
||||
// PostgreSQL "relation already exists, skipping" NOTICE messages.
|
||||
crate::db::pool::configure(config).await?;
|
||||
|
||||
let pool = match config.database_backend.as_str() {
|
||||
"sqlite" => {
|
||||
let path = sqlite_path(config)?;
|
||||
let migration_path = path.clone();
|
||||
let schema = global_schema_for_backend(DatabaseBackend::Sqlite)?;
|
||||
sqlite_task(migration_path, move |conn| {
|
||||
conn.execute_batch(&schema).map_err(|e| {
|
||||
format!("SQLite database schema initialization failed: {e}")
|
||||
})?;
|
||||
Ok(())
|
||||
})
|
||||
.await?;
|
||||
Pool::Sqlite(path)
|
||||
}
|
||||
"sqlite" => Pool::Sqlite(sqlite_path(config)?),
|
||||
"mysql" => {
|
||||
let url = config
|
||||
.database_url
|
||||
@@ -171,11 +165,6 @@ impl DatabaseSessionStore {
|
||||
let pool = MySqlPool::connect(url)
|
||||
.await
|
||||
.map_err(|e| format!("failed to connect MySQL database: {e}"))?;
|
||||
let schema = global_schema_for_backend(DatabaseBackend::Mysql)?;
|
||||
sqlx::raw_sql(&schema)
|
||||
.execute(&pool)
|
||||
.await
|
||||
.map_err(|e| format!("MySQL database schema initialization failed: {e}"))?;
|
||||
Pool::Mysql(pool)
|
||||
}
|
||||
"pgsql" => {
|
||||
@@ -186,10 +175,6 @@ impl DatabaseSessionStore {
|
||||
let pool = PgPool::connect(url)
|
||||
.await
|
||||
.map_err(|e| format!("failed to connect PostgreSQL database: {e}"))?;
|
||||
let schema = global_schema_for_backend(DatabaseBackend::Pgsql)?;
|
||||
sqlx::raw_sql(&schema).execute(&pool).await.map_err(|e| {
|
||||
format!("PostgreSQL database schema initialization failed: {e}")
|
||||
})?;
|
||||
Pool::Pgsql(pool)
|
||||
}
|
||||
other => return Err(format!("unsupported database backend: {other}")),
|
||||
|
||||
Reference in new issue
Block a user