aboutsummaryrefslogtreecommitdiffstats
path: root/lib/api-config/src/schema/update_schema.rs
blob: 4aa0862e73a867eb2ebfaf207447df79c58e98b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use tracing::debug;

use crate::{
    ConfigurationError,
    schema::{SchemaService, TransactionSchema},
};

pub(super) async fn update_schema(
    state: &SchemaService,
    kind: &str,
    version: &str,
    schema: &serde_json::Value,
) -> Result<Option<TransactionSchema>, ConfigurationError> {
    debug!("updating transaction schema");
    sqlx::query_as!(
        TransactionSchema,
        "
            update
                transaction_schema
            set 
                schema = $3
            where 
                schema_type = $1 
                and schema_version = $2
            returning *
        ",
        kind,
        version,
        sqlx::types::Json(&schema) as _
    )
    .fetch_optional(&state.database)
    .await
    .map_err(|e| e.into())
}