diff --git a/Cargo.lock b/Cargo.lock index 86c972f9745..b6dfd90f30f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -354,6 +354,7 @@ dependencies = [ "async-trait", "atuin-common", "atuin-server-database", + "eyre", "futures-util", "serde", "sqlx", diff --git a/atuin-server-postgres/Cargo.toml b/atuin-server-postgres/Cargo.toml index d6579ee3f16..a5dfbaf7ebf 100644 --- a/atuin-server-postgres/Cargo.toml +++ b/atuin-server-postgres/Cargo.toml @@ -13,6 +13,7 @@ repository = { workspace = true } atuin-common = { path = "../atuin-common", version = "18.1.0" } atuin-server-database = { path = "../atuin-server-database", version = "18.1.0" } +eyre = { workspace = true } tracing = "0.1" time = { workspace = true } serde = { workspace = true } diff --git a/atuin-server-postgres/src/lib.rs b/atuin-server-postgres/src/lib.rs index 0ad330761a7..6dc56fe4646 100644 --- a/atuin-server-postgres/src/lib.rs +++ b/atuin-server-postgres/src/lib.rs @@ -16,6 +16,8 @@ use wrappers::{DbHistory, DbRecord, DbSession, DbUser}; mod wrappers; +const MIN_PG_VERSION: u32 = 14; + #[derive(Clone)] pub struct Postgres { pool: sqlx::Pool, @@ -43,6 +45,25 @@ impl Database for Postgres { .await .map_err(fix_error)?; + // Call server_version_num to get the DB server's major version number + // The call returns None for servers older than 8.x. + let pg_major_version: u32 = pool + .acquire() + .await + .map_err(fix_error)? + .server_version_num() + .ok_or(DbError::Other(eyre::Report::msg( + "could not get PostgreSQL version", + )))? + / 10000; + + if pg_major_version < MIN_PG_VERSION { + return Err(DbError::Other(eyre::Report::msg(format!( + "unsupported PostgreSQL version {}, minimum required is {}", + pg_major_version, MIN_PG_VERSION + )))); + } + sqlx::migrate!("./migrations") .run(&pool) .await