mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-07 18:07:47 +08:00
refactor(data): remove MySQL and SQLite support
Use PostgreSQL as the only database backend across runtime, schema tooling, installation, Compose, and CI. Update regression tests and reject removed drivers explicitly.
This commit is contained in:
@@ -113,10 +113,7 @@ impl GatewayDataConfig {
|
||||
return (self.clone(), None);
|
||||
};
|
||||
let total_max = database.pool.max_connections;
|
||||
if total_max < 2
|
||||
|| configured_background_max == Some(0)
|
||||
|| is_private_sqlite_memory_database(database)
|
||||
{
|
||||
if total_max < 2 || configured_background_max == Some(0) {
|
||||
return (self.clone(), None);
|
||||
}
|
||||
|
||||
@@ -152,14 +149,9 @@ impl GatewayDataConfig {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_private_sqlite_memory_database(database: &aether_data::SqlDatabaseConfig) -> bool {
|
||||
database.driver == aether_data::DatabaseDriver::Sqlite
|
||||
&& matches!(database.url.trim(), "sqlite::memory:" | "sqlite://:memory:")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::GatewayDataConfig;
|
||||
use super::{GatewayDataConfig, PostgresPoolConfig};
|
||||
use aether_data::{DatabaseDriver, SqlDatabaseConfig, SqlPoolConfig};
|
||||
|
||||
#[test]
|
||||
@@ -226,7 +218,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn runtime_pool_split_can_be_disabled_or_degrade_for_single_connection() {
|
||||
let mut database = SqlDatabaseConfig::sqlite_default();
|
||||
let mut database = SqlDatabaseConfig::from_postgres_config(PostgresPoolConfig {
|
||||
database_url: "postgres://localhost/aether".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
database.pool.max_connections = 1;
|
||||
let config = GatewayDataConfig::from_database_config(database);
|
||||
assert!(config
|
||||
@@ -234,7 +229,10 @@ mod tests {
|
||||
.1
|
||||
.is_none());
|
||||
|
||||
let mut database = SqlDatabaseConfig::sqlite_default();
|
||||
let mut database = SqlDatabaseConfig::from_postgres_config(PostgresPoolConfig {
|
||||
database_url: "postgres://localhost/aether".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
database.pool.max_connections = 8;
|
||||
let config = GatewayDataConfig::from_database_config(database);
|
||||
assert!(config
|
||||
@@ -242,34 +240,4 @@ mod tests {
|
||||
.1
|
||||
.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_pool_split_keeps_private_sqlite_memory_database_in_one_pool() {
|
||||
for url in ["sqlite::memory:", "sqlite://:memory:"] {
|
||||
let config = GatewayDataConfig::from_database_config(
|
||||
SqlDatabaseConfig::new(
|
||||
DatabaseDriver::Sqlite,
|
||||
url,
|
||||
SqlPoolConfig {
|
||||
min_connections: 1,
|
||||
max_connections: 8,
|
||||
..SqlPoolConfig::default()
|
||||
},
|
||||
)
|
||||
.expect("sqlite memory database config should be valid"),
|
||||
);
|
||||
|
||||
let (foreground, background) = config.split_runtime_pools_with_background_max(Some(2));
|
||||
|
||||
assert!(background.is_none(), "private SQLite URL {url} was split");
|
||||
assert_eq!(
|
||||
foreground
|
||||
.database()
|
||||
.expect("foreground database")
|
||||
.pool
|
||||
.max_connections,
|
||||
8
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1116,10 +1116,7 @@ impl GatewayDataState {
|
||||
}
|
||||
|
||||
fn database_driver_supports_usage_counter_flush(driver: Option<DatabaseDriver>) -> bool {
|
||||
matches!(
|
||||
driver,
|
||||
Some(DatabaseDriver::Postgres | DatabaseDriver::Mysql | DatabaseDriver::Sqlite)
|
||||
)
|
||||
matches!(driver, Some(DatabaseDriver::Postgres))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -1132,12 +1129,6 @@ mod usage_counter_flush_backend_tests {
|
||||
assert!(database_driver_supports_usage_counter_flush(Some(
|
||||
DatabaseDriver::Postgres
|
||||
)));
|
||||
assert!(database_driver_supports_usage_counter_flush(Some(
|
||||
DatabaseDriver::Mysql
|
||||
)));
|
||||
assert!(database_driver_supports_usage_counter_flush(Some(
|
||||
DatabaseDriver::Sqlite
|
||||
)));
|
||||
assert!(!database_driver_supports_usage_counter_flush(None));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,40 +254,6 @@ async fn app_state_wires_gateway_data_state_from_config() {
|
||||
assert!(state.data.has_video_task_reader());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn app_state_prepares_sqlite_database_startup() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut pool = SqlPoolConfig::default();
|
||||
pool.min_connections = 0;
|
||||
pool.max_connections = 1;
|
||||
let database = SqlDatabaseConfig::new(DatabaseDriver::Sqlite, "sqlite::memory:", pool)?;
|
||||
let state =
|
||||
AppState::new()?.with_data_config(GatewayDataConfig::from_database_config(database))?;
|
||||
|
||||
let pending = state
|
||||
.prepare_database_for_startup()
|
||||
.await?
|
||||
.expect("sqlite database should expose migration state");
|
||||
assert!(
|
||||
!pending.is_empty(),
|
||||
"fresh sqlite gateway databases should report pending migrations"
|
||||
);
|
||||
|
||||
assert!(
|
||||
state.run_database_migrations().await?,
|
||||
"sqlite gateway database should run migrations"
|
||||
);
|
||||
let pending = state
|
||||
.prepare_database_for_startup()
|
||||
.await?
|
||||
.expect("sqlite database should expose migration state");
|
||||
assert!(
|
||||
pending.is_empty(),
|
||||
"sqlite gateway databases should be current after migrations"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn data_state_checks_user_uniqueness_through_user_reader() {
|
||||
let user = StoredUserAuthRecord::new(
|
||||
|
||||
Reference in New Issue
Block a user