Skip to main content

haste_repository/pg/
migrate.rs

1use haste_fhir_model::r4::generated::terminology::IssueType;
2use haste_fhir_operation_error::OperationOutcomeError;
3use sqlx;
4
5use crate::admin::Migrate;
6
7impl Migrate for super::PGConnection {
8    async fn migrate(&self) -> Result<(), OperationOutcomeError> {
9        match self {
10            super::PGConnection::Pool(pool, _) => sqlx::migrate!("./pg-migrations")
11                .run(pool)
12                .await
13                .map_err(|e| {
14                    OperationOutcomeError::fatal(
15                        IssueType::exception(),
16                        format!("Failed to migrate repository schema: {e}"),
17                    )
18                }),
19            super::PGConnection::Transaction(_, _) => Err(OperationOutcomeError::fatal(
20                IssueType::exception(),
21                "Cannot run migrations in a transaction.".to_string(),
22            )),
23        }
24    }
25}