45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
use sqlx::{Transaction, query};
|
|
|
|
use super::authority::{MigrationDescriptor, MigrationError};
|
|
|
|
pub(super) const SOURCE: &str = include_str!("execution_outcome_v5.sql");
|
|
pub(super) const SOURCE_SHA256: &str =
|
|
"bd6703249cc407789586327eb7fbbd5776ba27923c5dc7eb85b05d332585bf42";
|
|
|
|
pub(super) async fn apply(
|
|
transaction: &mut Transaction<'_, sqlx::Postgres>,
|
|
descriptor: &MigrationDescriptor,
|
|
) -> Result<(), MigrationError> {
|
|
sqlx::raw_sql(SOURCE)
|
|
.execute(&mut **transaction)
|
|
.await
|
|
.map_err(|_| {
|
|
MigrationError::new(
|
|
"apply_failed",
|
|
"apply.execution_outcome",
|
|
Some(5),
|
|
"restore_known_good_backup",
|
|
)
|
|
})?;
|
|
query(
|
|
"insert into __crank_migrations (version, name, checksum, phase, compatibility)
|
|
values ($1, $2, $3, $4, $5)",
|
|
)
|
|
.bind(descriptor.version)
|
|
.bind(descriptor.name)
|
|
.bind(&descriptor.checksum)
|
|
.bind(descriptor.phase)
|
|
.bind(descriptor.compatibility)
|
|
.execute(&mut **transaction)
|
|
.await
|
|
.map_err(|_| {
|
|
MigrationError::new(
|
|
"apply_failed",
|
|
"apply.canonical_ledger",
|
|
Some(5),
|
|
"restore_known_good_backup",
|
|
)
|
|
})?;
|
|
Ok(())
|
|
}
|