Skip to main content

mz_deploy/client/
dev_overlays.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
10//! Read/write helpers for the `_mz_deploy.tables.dev_overlays` manifest.
11//!
12//! These are called by `cli::commands::dev` to drop-and-rebuild
13//! per-developer overlay databases.
14
15use crate::client::connection::DevOverlaysClient;
16use crate::client::errors::ConnectionError;
17
18impl DevOverlaysClient<'_> {
19    /// List overlay databases recorded for the given profile + project.
20    pub async fn list_overlays(
21        &self,
22        profile: &str,
23        project: &str,
24    ) -> Result<Vec<String>, ConnectionError> {
25        let rows = self
26            .client
27            .query(
28                "SELECT overlay_db FROM _mz_deploy.tables.dev_overlays \
29                 WHERE profile = $1 AND project = $2 \
30                 ORDER BY overlay_db",
31                &[&profile, &project],
32            )
33            .await?;
34        Ok(rows.into_iter().map(|r| r.get::<_, String>(0)).collect())
35    }
36
37    /// Record that an overlay database was created.
38    pub async fn insert_overlay(
39        &self,
40        profile: &str,
41        project: &str,
42        overlay_db: &str,
43    ) -> Result<(), ConnectionError> {
44        self.client
45            .execute(
46                "INSERT INTO _mz_deploy.tables.dev_overlays \
47                 (profile, project, overlay_db, created_at) \
48                 VALUES ($1, $2, $3, now())",
49                &[&profile, &project, &overlay_db],
50            )
51            .await?;
52        Ok(())
53    }
54
55    /// Remove all overlay records for a profile + project pair.
56    pub async fn delete_overlays(
57        &self,
58        profile: &str,
59        project: &str,
60    ) -> Result<(), ConnectionError> {
61        self.client
62            .execute(
63                "DELETE FROM _mz_deploy.tables.dev_overlays \
64                 WHERE profile = $1 AND project = $2",
65                &[&profile, &project],
66            )
67            .await?;
68        Ok(())
69    }
70}