aboutsummaryrefslogtreecommitdiffstats
path: root/lib/api-config/src/schema/update_schema.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api-config/src/schema/update_schema.rs')
-rw-r--r--lib/api-config/src/schema/update_schema.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/api-config/src/schema/update_schema.rs b/lib/api-config/src/schema/update_schema.rs
new file mode 100644
index 0000000..4aa0862
--- /dev/null
+++ b/lib/api-config/src/schema/update_schema.rs
@@ -0,0 +1,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())
+}