Centralize durable schema migration ownership
This commit is contained in:
parent
cc328237f4
commit
069f3813ae
3 changed files with 354 additions and 350 deletions
|
|
@ -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",
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ use time::OffsetDateTime;
|
|||
|
||||
use crate::WorkerError;
|
||||
|
||||
const MIGRATION_TABLE: &str = "_remora_worker_migrations";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DescriptorStore {
|
||||
pool: PgPool,
|
||||
|
|
@ -154,17 +152,6 @@ impl DescriptorStore {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn migrate(pool: &PgPool) -> Result<(), sqlx::migrate::MigrateError> {
|
||||
migrator().run(pool).await
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn migrator() -> sqlx::migrate::Migrator {
|
||||
let mut migrator = sqlx::migrate!("./migrations");
|
||||
migrator.dangerous_set_table_name(MIGRATION_TABLE);
|
||||
migrator
|
||||
}
|
||||
|
||||
struct StoredDescriptor {
|
||||
id: OpaqueId,
|
||||
schema_version: PositiveIntegerDto,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ mod runtime;
|
|||
|
||||
pub use application::{WorkerApplication, WorkerApplicationConfig};
|
||||
pub use client::WorkerApiClient;
|
||||
pub use descriptor::{DescriptorStore, migrate, migrator};
|
||||
pub use descriptor::DescriptorStore;
|
||||
pub use error::WorkerError;
|
||||
pub use executor::{AdapterExecutor, ObjectSourceEndpoint};
|
||||
pub use runtime::{
|
||||
|
|
|
|||
Loading…
Reference in a new issue