Skip to main content

lenso_organization_postgres_plugin/
operator.rs

1use lenso_postgres_kit::{PostgresKitError, SchemaOperator, SetupOutcome, UpgradeOutcome};
2use thiserror::Error;
3
4use crate::schema::schema_plan;
5
6/// Explicit schema administration for the Organization Plugin.
7#[derive(Clone, Copy, Debug, Default)]
8pub struct OrganizationOperator;
9
10impl OrganizationOperator {
11    pub async fn setup(
12        database_url: &str,
13        schema: &str,
14    ) -> Result<SetupOutcome, OrganizationOperatorError> {
15        Ok(SchemaOperator::connect(database_url, schema_plan(schema)?)
16            .await?
17            .setup()
18            .await?)
19    }
20
21    pub async fn upgrade(
22        database_url: &str,
23        schema: &str,
24    ) -> Result<UpgradeOutcome, OrganizationOperatorError> {
25        Ok(SchemaOperator::connect(database_url, schema_plan(schema)?)
26            .await?
27            .upgrade()
28            .await?)
29    }
30}
31
32#[derive(Debug, Error)]
33pub enum OrganizationOperatorError {
34    #[error(transparent)]
35    Plan(#[from] lenso_postgres_kit::PlanError),
36    #[error(transparent)]
37    Postgres(#[from] PostgresKitError),
38}