same migration process test and prod
ci/woodpecker/push/tests Pipeline was canceled

This commit is contained in:
qpismont committed 2026-10-14 16:50:02 +00:00
1 parent b40985528e
commit cedd052a4d
3 files changed
+5 -35

No files matched your search

+1
View File
@@ -39,6 +39,7 @@ steps:
environment:
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/steep
commands:
- bash scripts/migrate-apply.sh
- cargo test --workspace --all-targets -- --include-ignored
- name: container-build
+1 -1
View File
@@ -112,7 +112,7 @@ After changing a model in `crates/steep-server/src/schemas/`, generate a migrati
./scripts/migrate-generate.sh describe_change
```
Apply the pending migrations **before starting the service** — the server does not migrate at boot:
Apply the pending migrations **before starting the service** — the server does not migrate at boot. The tests need the same schema: run this before `cargo test` too (CI does it as well):
```sh
./scripts/migrate-apply.sh
+3 -34
View File
@@ -9,43 +9,12 @@ pub async fn open(url: &str) -> toasty::Result<Db> {
/// A connection for a test, on the database `DATABASE_URL` points to.
///
/// Every `#[tokio::test]` runs on its own runtime, and the connection tasks live on
/// the runtime that opened the pool: sharing one `Db` between tests would leave
/// them with a pool whose runtime is gone. Each test therefore opens its own, and
/// only the migrations are applied once.
/// The schema must already be migrated: `scripts/migrate-apply.sh` does it, the same
/// way it does for the server. Each test opens its own connection, because the
/// connection tasks live on the runtime of the test that opened them.
#[cfg(test)]
pub(crate) async fn test_connect() -> Db {
static MIGRATED: tokio::sync::OnceCell<()> = tokio::sync::OnceCell::const_new();
let url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
// The migrations run on a runtime of their own, which outlives the first test.
MIGRATED
.get_or_init(|| async {
let url = url.clone();
std::thread::spawn(move || {
tokio::runtime::Runtime::new()
.expect("migration runtime")
.block_on(async {
let migrations =
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("toasty");
let config = toasty_cli::Config::new()
.migration(toasty_cli::MigrationConfig::new().path(migrations));
toasty_cli::ToastyCli::with_config(
open(&url).await.expect("open pool"),
config,
)
.parse_from(["toasty", "migration", "apply"])
.await
.expect("apply migrations");
});
})
.join()
.expect("migrations panicked");
})
.await;
open(&url).await.expect("connect to postgres")
}