1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
910use anyhow::{Context, bail};
11use tokio_postgres::types::Type;
1213use crate::action::State;
1415pub async fn run_version_check(
16 min_version: i32,
17 max_version: i32,
18 state: &State,
19) -> Result<bool, anyhow::Error> {
20let query = "SELECT mz_version_num()";
21let stmt = state
22 .materialize
23 .pgclient
24 .prepare(query)
25 .await
26.context("failed to prepare version-check query")?;
27if stmt.columns().len() != 1 || *stmt.columns()[0].type_() != Type::INT4 {
28bail!(
29"version-check query must return exactly one int column, but is {}",
30*stmt.columns()[0].type_()
31 );
32 }
33let actual_version: i32 = state
34 .materialize
35 .pgclient
36 .query_one(&stmt, &[])
37 .await
38.context("executing version-check query failed")?
39.get(0);
40Ok(actual_version < min_version || actual_version > max_version)
41}