mz_testdrive/action/
version_check.rs

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.
9
10use anyhow::{Context, bail};
11use tokio_postgres::types::Type;
12
13use crate::action::State;
14
15pub async fn run_version_check(
16    min_version: i32,
17    max_version: i32,
18    state: &State,
19) -> Result<bool, anyhow::Error> {
20    let query = "SELECT mz_version_num()";
21    let stmt = state
22        .materialize
23        .pgclient
24        .prepare(query)
25        .await
26        .context("failed to prepare version-check query")?;
27    if stmt.columns().len() != 1 || *stmt.columns()[0].type_() != Type::INT4 {
28        bail!(
29            "version-check query must return exactly one int column, but is {}",
30            *stmt.columns()[0].type_()
31        );
32    }
33    let actual_version: i32 = state
34        .materialize
35        .pgclient
36        .query_one(&stmt, &[])
37        .await
38        .context("executing version-check query failed")?
39        .get(0);
40    Ok(actual_version < min_version || actual_version > max_version)
41}