Skip to main content

a3s_flow/store/
postgres_schema.rs

1use a3s_orm::{MigrationReport, Migrator, PostgresExecutor};
2
3use crate::error::{FlowError, Result};
4
5use super::postgres_migrations;
6
7/// Apply the canonical Flow PostgreSQL schema with a dedicated migration
8/// executor.
9///
10/// Production hosts should terminate this operation before starting serving
11/// workers, then construct stores and queues through their `*_verified`
12/// constructors with a role that does not have DDL authority.
13pub async fn migrate_postgres_flow(executor: &PostgresExecutor) -> Result<MigrationReport> {
14    Migrator::new(executor.clone())
15        .run(postgres_migrations())
16        .await
17        .map_err(|error| FlowError::Store(format!("PostgreSQL Flow migration failed: {error}")))
18}
19
20pub(crate) async fn verify_postgres_flow(executor: &PostgresExecutor) -> Result<()> {
21    Migrator::new(executor.clone())
22        .verify_required(postgres_migrations())
23        .await
24        .map_err(|error| {
25            FlowError::Store(format!(
26                "PostgreSQL Flow schema admission failed: {error}; run migrate_postgres_flow before serving"
27            ))
28        })
29}