Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Download `steda.sql` from the matching [Steda release](https://github.com/selemi
psql "$DATABASE_URL" --single-transaction -v ON_ERROR_STOP=1 -f steda.sql
```

Applications that own database bootstrap can instead apply [`steda::SCHEMA_SQL`](https://docs.rs/steda/latest/steda/constant.SCHEMA_SQL.html) from the linked crate release in the same atomic manner.

When upgrading Steda, apply the new release's `steda.sql` the same way before starting binaries built against that release. Database upgrades remain compatible within a major release line. A future major release may introduce breaking storage changes and require an explicit migration procedure, such as draining workers or running a one-time upgrade script. Any such requirements will be documented in the release notes. Mixed-version deployments are not guaranteed unless a release explicitly states otherwise.

## Features
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ pub mod middleware {
};
}

/// Complete re-applicable PostgreSQL schema artifact for this Steda release.
///
/// Applications that own database bootstrap may apply this SQL atomically before starting
/// producers or workers. Reapply the value from the new Steda release when upgrading.
pub const SCHEMA_SQL: &str = include_str!("../sql/steda.sql");

pub use context::{TaskContext, TaskWait};
pub use error::{Error, Result};
pub use queue::Queue;
Expand Down
6 changes: 3 additions & 3 deletions tests/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ mod common;
mod tests {
use serde_json::{Value, json};
use sqlx::{AssertSqlSafe, PgPool};
use steda::{Result, RunId, Steda, Task, TaskSnapshot};
use steda::{Result, RunId, SCHEMA_SQL, Steda, Task, TaskSnapshot};

use super::common::unique_queue;

const SCHEMA_PROBE: Task<Value, Value> = Task::new("schema-probe");

#[sqlx::test]
async fn merged_schema_can_be_reapplied_without_losing_state(pool: PgPool) -> Result<()> {
sqlx::raw_sql(include_str!("../sql/steda.sql")).execute(&pool).await?;
sqlx::raw_sql(SCHEMA_SQL).execute(&pool).await?;

let queue_name = unique_queue("schema_reapply");
let queue = Steda::from_pool(pool.clone()).queue(queue_name.clone())?;
queue.create().await?;
let spawned = queue.spawn(SCHEMA_PROBE, json!({"preserved": true})).await?;
assert_eq!(spawned.snapshot().await?, Some(TaskSnapshot::Pending));

sqlx::raw_sql(include_str!("../sql/steda.sql")).execute(&pool).await?;
sqlx::raw_sql(SCHEMA_SQL).execute(&pool).await?;

assert_eq!(spawned.snapshot().await?, Some(TaskSnapshot::Pending));
assert!(Steda::from_pool(pool).queues().await?.contains(&queue_name));
Expand Down
Loading