Centralize durable schema migration ownership

This commit is contained in:
ms2k 2026-07-19 01:20:18 +09:00
commit 069f3813ae

View file

@ -146,8 +146,7 @@ impl WorkerApplication {
)
.await
.map_err(runtime_error)?;
wait_for_core_schema(&pool).await?;
crate::migrate(&pool).await.map_err(runtime_error)?;
wait_for_schema(&pool).await?;
let coordination = CoordinationStore::connect(
&self.config.coordination_url,
&self.config.coordination_namespace,
@ -219,20 +218,15 @@ impl WorkerApplication {
}
}
async fn wait_for_core_schema(pool: &sqlx::PgPool) -> Result<(), RuntimeError> {
async fn wait_for_schema(pool: &sqlx::PgPool) -> Result<(), RuntimeError> {
for _ in 0..120 {
let ready =
sqlx::query_scalar::<_, Option<String>>("SELECT to_regclass('public.jobs')::text")
.fetch_one(pool)
.await
.is_ok_and(|table| table.is_some());
if ready {
if remora_schema::is_ready(pool).await.unwrap_or(false) {
return Ok(());
}
tokio::time::sleep(Duration::from_secs(1)).await;
}
Err(RuntimeError::message(
"core database schema was not initialized",
"database schema did not reach the required generation",
))
}