mirror of
https://github.com/atuinsh/atuin.git
synced 2025-01-24 23:31:00 +01:00
feat(server): check PG version before running migrations (#1868)
This commit is contained in:
parent
3e2e7292c0
commit
c330636766
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -354,6 +354,7 @@ dependencies = [
|
||||
"async-trait",
|
||||
"atuin-common",
|
||||
"atuin-server-database",
|
||||
"eyre",
|
||||
"futures-util",
|
||||
"serde",
|
||||
"sqlx",
|
||||
|
@ -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 }
|
||||
|
@ -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<sqlx::postgres::Postgres>,
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user