Skip to main content

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