Skip to content

Commit 5e65b38

Browse files
committed
Merge remote-tracking branch 'origin/main' into duncan/nip-fi-deny-api-port
* origin/main: test(desktop): fix flaky forum empty-draft replacement e2e (#7981) chore(release): release Buzz Desktop version 0.5.26 (#7980) fix(desktop): correct Grok Build setup guide URL (#4846) fix(db): audit partition catalog before creation (#6515) feat(mobile): show contextual names in channel conversations (#7895) Signed-off-by: Will Pfleger <[email protected]>
2 parents b629422 + 12dbb11 commit 5e65b38

47 files changed

Lines changed: 4671 additions & 258 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.env.example‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ REDIS_URL=redis://localhost:6379
3737
# Max connections in each of the relay's Postgres pools — writer and, when
3838
# READ_DATABASE_URL is set, reader (default 50).
3939
# BUZZ_DB_POOL_SIZE=50
40+
# Read-only partition catalog audit interval, clamped to 60s..24h (default 900s).
41+
# BUZZ_PARTITION_AUDIT_INTERVAL_SECS=900
42+
# Emergency kill switch for monthly partition CREATE; audits remain enabled.
43+
# BUZZ_PARTITION_MANAGER_CREATE_ENABLED=true
4044

4145
# Writer-session Postgres timeouts for buzz-db-backed pools and the relay audit
4246
# pool, all in milliseconds; 0 disables. The separately deployed push gateway

‎.release/desktop-candidate.json‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"schema": 2,
3-
"version": "0.5.25",
4-
"base_sha": "797012ff01a6d499959b45ed2e56f7927c6a4d6b",
5-
"previous_tag": "desktop-v0.5.24",
6-
"previous_base_sha": "fe56d311a7156802408afb04023c3f75d4015007",
7-
"previous_merge_sha": "ec7ea38f62ea917f15e85a678bc94f3bbee5bb64",
8-
"tag": "desktop-v0.5.25",
9-
"commit_count": 17
3+
"version": "0.5.26",
4+
"base_sha": "7ebf1beb44139264e9c5c7fee6970429ff66f934",
5+
"previous_tag": "desktop-v0.5.25",
6+
"previous_base_sha": "797012ff01a6d499959b45ed2e56f7927c6a4d6b",
7+
"previous_merge_sha": "02753722a7dd06560402a5b92491b048968c1a63",
8+
"tag": "desktop-v0.5.26",
9+
"commit_count": 39
1010
}

‎CHANGELOG.md‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,54 @@
11
# Changelog
22

3+
## v0.5.26
4+
5+
### Desktop and shared changes
6+
7+
- fix(desktop): correct Grok Build setup guide URL ([#4846](https://github.com/block/buzz/pull/4846)) ([`7ebf1beb44139264e9c5c7fee6970429ff66f934`](https://github.com/block/buzz/commit/7ebf1beb44139264e9c5c7fee6970429ff66f934))
8+
- feat(relay): implement NIP-AR channel artifacts ([#7919](https://github.com/block/buzz/pull/7919)) ([`12670bd0f037c66a682272bb81c46c3f254fad74`](https://github.com/block/buzz/commit/12670bd0f037c66a682272bb81c46c3f254fad74))
9+
- fix(desktop): resolve unlisted project channel requests ([#7619](https://github.com/block/buzz/pull/7619)) ([`c96553eb13a073ca9f4ee1547b50ba3d28dfd4db`](https://github.com/block/buzz/commit/c96553eb13a073ca9f4ee1547b50ba3d28dfd4db))
10+
- Schedule the deletion drain safely ([#7827](https://github.com/block/buzz/pull/7827)) ([`6918dd3a83fd7aacf6d8e4634d3864eb10ead61d`](https://github.com/block/buzz/commit/6918dd3a83fd7aacf6d8e4634d3864eb10ead61d))
11+
- test(desktop): wait for channel head refresh before paging thread summary test ([#7955](https://github.com/block/buzz/pull/7955)) ([`f1e50be4103addabd497563495e0ffe5bda07ef7`](https://github.com/block/buzz/commit/f1e50be4103addabd497563495e0ffe5bda07ef7))
12+
- 🤖 perf: bound long-thread aux reads and make query deadlines terminal ([#7854](https://github.com/block/buzz/pull/7854)) ([`9b1c4f98e2981d6d89fbfa3154b8ef0b3b6ad334`](https://github.com/block/buzz/commit/9b1c4f98e2981d6d89fbfa3154b8ef0b3b6ad334))
13+
- Add native HPKE encryption for nsec backups ([#7849](https://github.com/block/buzz/pull/7849)) ([`cc36d25bec2d34340ab7aace50110f51162edd7a`](https://github.com/block/buzz/commit/cc36d25bec2d34340ab7aace50110f51162edd7a))
14+
- test(desktop): scope video menu e2e probes to emitted messages ([#7953](https://github.com/block/buzz/pull/7953)) ([`548718e042decbc059fd7ebfb9b9ad2459ac258d`](https://github.com/block/buzz/commit/548718e042decbc059fd7ebfb9b9ad2459ac258d))
15+
- fix(sidebar): converge stale-at-open state across devices (sections/sort/stars/mutes) ([#7805](https://github.com/block/buzz/pull/7805)) ([`52c4c08c9ef349f2bb994ca40e98faa0f44209ea`](https://github.com/block/buzz/commit/52c4c08c9ef349f2bb994ca40e98faa0f44209ea))
16+
- feat(nip-fi): harden Blossom kind-24242 verifier to NIP-FI spec ([#7288](https://github.com/block/buzz/pull/7288)) ([`f7ff4294fa95191d1fc7b29a765e6f0b48db6bd8`](https://github.com/block/buzz/commit/f7ff4294fa95191d1fc7b29a765e6f0b48db6bd8))
17+
- fix(ci): select runtime suites from PR changes only ([#7843](https://github.com/block/buzz/pull/7843)) ([`02c6309f534050e54c8d36f5ce90e48e4dd152b1`](https://github.com/block/buzz/commit/02c6309f534050e54c8d36f5ce90e48e4dd152b1))
18+
- test(desktop): synchronize upload edit smoke test ([#7903](https://github.com/block/buzz/pull/7903)) ([`a1fb6645d994e72b5f39fae8bd482d400e4005b6`](https://github.com/block/buzz/commit/a1fb6645d994e72b5f39fae8bd482d400e4005b6))
19+
- feat(desktop): relay admin console for the /api/admin/v1 operator surface ([#4768](https://github.com/block/buzz/pull/4768)) ([`8f8c4dfadecb2298a9140af5d323487aaad844ab`](https://github.com/block/buzz/commit/8f8c4dfadecb2298a9140af5d323487aaad844ab))
20+
21+
### Other repository changes
22+
23+
- fix(db): audit partition catalog before creation ([#6515](https://github.com/block/buzz/pull/6515)) ([`14a752fb2445790bf4620348e485e8576371f906`](https://github.com/block/buzz/commit/14a752fb2445790bf4620348e485e8576371f906))
24+
- feat(mobile): show contextual names in channel conversations ([#7895](https://github.com/block/buzz/pull/7895)) ([`4ef23609b7025bc356a9ea078834d57b69ec33cf`](https://github.com/block/buzz/commit/4ef23609b7025bc356a9ea078834d57b69ec33cf))
25+
- feat(buzz-relay): NIP-FI stateless enforcement (S3) — upgrade gate, NIP-42 pairing, session lifetime, JWKS warm ([#7224](https://github.com/block/buzz/pull/7224)) ([`8519db1532efd6cda8f72bb6454c00fc3f87cfba`](https://github.com/block/buzz/commit/8519db1532efd6cda8f72bb6454c00fc3f87cfba))
26+
- feat(web): add Browse releases link next to invite download ([#2255](https://github.com/block/buzz/pull/2255)) ([`b9d22a273f2225917f13b13a9fde305629126502`](https://github.com/block/buzz/commit/b9d22a273f2225917f13b13a9fde305629126502))
27+
- docs(nips): fix stray angle brackets in created_at clauses ([#4486](https://github.com/block/buzz/pull/4486)) ([`12423f2868b810240a6b949d21c8a09e9e8a1994`](https://github.com/block/buzz/commit/12423f2868b810240a6b949d21c8a09e9e8a1994))
28+
- docs: specify desktop-driven mobile push suppression ([#7809](https://github.com/block/buzz/pull/7809)) ([`45c288c1793bbbbbbb1be88f8a53c6aecfff8d2f`](https://github.com/block/buzz/commit/45c288c1793bbbbbbb1be88f8a53c6aecfff8d2f))
29+
- feat(mobile): add the contextual identity-name resolver ([#7894](https://github.com/block/buzz/pull/7894)) ([`efe04288ea907adfe91a38ae916c0d364c315cca`](https://github.com/block/buzz/commit/efe04288ea907adfe91a38ae916c0d364c315cca))
30+
- Automate owner deletion preparation ([#7830](https://github.com/block/buzz/pull/7830)) ([`bba75a71eb5a719b597479ec848053cde364befd`](https://github.com/block/buzz/commit/bba75a71eb5a719b597479ec848053cde364befd))
31+
- fix(mobile): stale community selection during mobile invite setup ([#7951](https://github.com/block/buzz/pull/7951)) ([`662014d544f835a075f0020e7d161fe7985d7959`](https://github.com/block/buzz/commit/662014d544f835a075f0020e7d161fe7985d7959))
32+
- Add owner deletion admission control plane ([#7818](https://github.com/block/buzz/pull/7818)) ([`15d44dcceee0679979991b3100f21f01fc799693`](https://github.com/block/buzz/commit/15d44dcceee0679979991b3100f21f01fc799693))
33+
- Make relay readiness process-local ([#7341](https://github.com/block/buzz/pull/7341)) ([`b37e477211313a94344a31aea4b180ed4effe0b8`](https://github.com/block/buzz/commit/b37e477211313a94344a31aea4b180ed4effe0b8))
34+
- 🤖 docs(nip-fi): remove implementation references from the spec ([#7912](https://github.com/block/buzz/pull/7912)) ([`447951a19c00edfa6432636f50782445929ab678`](https://github.com/block/buzz/commit/447951a19c00edfa6432636f50782445929ab678))
35+
- fix(relay): fail startup on invalid operator listener config ([#7933](https://github.com/block/buzz/pull/7933)) ([`ebe99a46e8802b9ff20fdf6a1028ce93bdefaa43`](https://github.com/block/buzz/commit/ebe99a46e8802b9ff20fdf6a1028ce93bdefaa43))
36+
- fix(db): limit event transactions to listener mention kinds ([#7932](https://github.com/block/buzz/pull/7932)) ([`1846094b3111a059f856bb4f3466c102fad17ef7`](https://github.com/block/buzz/commit/1846094b3111a059f856bb4f3466c102fad17ef7))
37+
- feat(relay): deliver pubkey mentions to relay companions ([#7793](https://github.com/block/buzz/pull/7793)) ([`c4c86006f2d67b2ea9055780129ee7ce95c54e0a`](https://github.com/block/buzz/commit/c4c86006f2d67b2ea9055780129ee7ce95c54e0a))
38+
- docs(protocol): propose simplified channel artifacts ([#7791](https://github.com/block/buzz/pull/7791)) ([`b0d6fb8ad27f6f255a5044e49ed0a59e11542914`](https://github.com/block/buzz/commit/b0d6fb8ad27f6f255a5044e49ed0a59e11542914))
39+
- feat(push): support configurable HTTP(S) delivery URLs ([#7877](https://github.com/block/buzz/pull/7877)) ([`781d39510cf23cfe224e8f521ae06a23377e06de`](https://github.com/block/buzz/commit/781d39510cf23cfe224e8f521ae06a23377e06de))
40+
- feat(relay): enforce NIP-FI assertion+NIP-98 pairing on HTTP ingress ([#7264](https://github.com/block/buzz/pull/7264)) ([`6410e685a80d42db0645fadc9bbe710559ef911e`](https://github.com/block/buzz/commit/6410e685a80d42db0645fadc9bbe710559ef911e))
41+
- fix(ci): run the admin disabled-mode DB test in the PostgreSQL lane ([#7900](https://github.com/block/buzz/pull/7900)) ([`b65cff31a4c5f4a0af63952b60a21fd73195321a`](https://github.com/block/buzz/commit/b65cff31a4c5f4a0af63952b60a21fd73195321a))
42+
- 🤖 docs: add pre-PR checklist and review guidance to AGENTS.md ([#7897](https://github.com/block/buzz/pull/7897)) ([`9c7687cc914cd8eddee7ba25cb980ad1a6bc0fdc`](https://github.com/block/buzz/commit/9c7687cc914cd8eddee7ba25cb980ad1a6bc0fdc))
43+
- docs: specify durable data backfills ([#7326](https://github.com/block/buzz/pull/7326)) ([`9263cda8455b8fd27f4491e5e4fc0ebc2ce2e8bc`](https://github.com/block/buzz/commit/9263cda8455b8fd27f4491e5e4fc0ebc2ce2e8bc))
44+
- docs(vision): add /buzz/v1 read endpoints to the protocol contract ([#7879](https://github.com/block/buzz/pull/7879)) ([`930b8bb800d8149ce29a881ba4c5d9f424580434`](https://github.com/block/buzz/commit/930b8bb800d8149ce29a881ba4c5d9f424580434))
45+
- 🤖 fix(justfile): point just staging at the current staging relay ([#7881](https://github.com/block/buzz/pull/7881)) ([`20131488528e35e6c50f4ccdb0490a9135c28edf`](https://github.com/block/buzz/commit/20131488528e35e6c50f4ccdb0490a9135c28edf))
46+
- fix(relay-admin): make thread deletions atomic and fence expired action leases under row lock ([#7853](https://github.com/block/buzz/pull/7853)) ([`676e8c43825fa478850a3a320b1367d3288cce1a`](https://github.com/block/buzz/commit/676e8c43825fa478850a3a320b1367d3288cce1a))
47+
- fix(mobile): keep retired sections manager out of successor cache ([#7873](https://github.com/block/buzz/pull/7873)) ([`28a8b90805278a91d723731bf7b824cea473bcfa`](https://github.com/block/buzz/commit/28a8b90805278a91d723731bf7b824cea473bcfa))
48+
- Select one feature flag provider at compile time ([#7677](https://github.com/block/buzz/pull/7677)) ([`8f6b66f9ff6b2e42cd713506805763269375b473`](https://github.com/block/buzz/commit/8f6b66f9ff6b2e42cd713506805763269375b473))
49+
50+
[Compare desktop-v0.5.25...desktop-v0.5.26](https://github.com/block/buzz/compare/desktop-v0.5.25...desktop-v0.5.26)
51+
352
## v0.5.25
453

554
### Desktop and shared changes

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/buzz-admin/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ buzz-media = { workspace = true }
2424
nostr = { workspace = true }
2525
tokio = { workspace = true }
2626
serde_json = { workspace = true }
27+
serde = { workspace = true }
2728
anyhow = { workspace = true }
2829
hex = { workspace = true }
2930
deadpool-redis = { workspace = true }

‎crates/buzz-admin/src/main.rs‎

Lines changed: 114 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ use std::time::Instant;
3131
use anyhow::Result;
3232
use buzz_core::kind::KIND_NIP43_MEMBERSHIP_LIST;
3333
use buzz_core::tenant::{relay_url_authority, TenantContext};
34-
use buzz_db::{Db, DbConfig};
34+
use buzz_db::{partition::PartitionAuditReport, Db, DbConfig};
3535
use buzz_media::{BucketSnapshot, MediaConfig, MediaStorage, S3AddressingStyle, SweepError};
3636
use buzz_pubsub::{EventTopic, PubSubManager};
3737
use clap::{Parser, Subcommand};
3838
use nostr::{EventBuilder, Keys, Kind, Tag};
39+
use serde::Serialize;
40+
use sqlx::Row;
3941
use tracing::warn;
4042

4143
#[derive(Parser)]
@@ -89,6 +91,12 @@ enum Command {
8991
#[arg(long, default_value_t = 10_000_000)]
9092
max_objects: u64,
9193
},
94+
/// Run the partition catalog audit using a read-only database session.
95+
PartitionAudit {
96+
/// Future months to include in the coverage check.
97+
#[arg(long, default_value_t = 3)]
98+
months_ahead: u32,
99+
},
92100
/// Inspect deployment-wide Buzz product feedback.
93101
ProductFeedback {
94102
#[command(subcommand)]
@@ -166,6 +174,7 @@ async fn run(cli: Cli) -> Result<i32> {
166174
Ok(0)
167175
}
168176
Command::StorageSnapshot { max_objects } => cmd_storage_snapshot(max_objects).await,
177+
Command::PartitionAudit { months_ahead } => cmd_partition_audit(months_ahead).await,
169178
Command::AddMember { pubkey, role } => cmd_add_member(pubkey, role).await,
170179
Command::RemoveMember { pubkey, role } => cmd_remove_member(pubkey, role).await,
171180
Command::ListMembers => cmd_list_members().await,
@@ -314,6 +323,94 @@ fn storage_config_from_env() -> Result<MediaConfig> {
314323
})
315324
}
316325

326+
#[derive(Serialize)]
327+
struct PartitionAuditIdentity {
328+
database: String,
329+
user: String,
330+
schema: String,
331+
default_transaction_read_only: bool,
332+
transaction_read_only: bool,
333+
}
334+
335+
#[derive(Serialize)]
336+
struct PartitionAuditOutput {
337+
schema_version: u32,
338+
mode: &'static str,
339+
source_sha: &'static str,
340+
build_id: &'static str,
341+
build_url: &'static str,
342+
outcome: &'static str,
343+
months_ahead: u32,
344+
identity: PartitionAuditIdentity,
345+
report: PartitionAuditReport,
346+
}
347+
348+
async fn cmd_partition_audit(months_ahead: u32) -> Result<i32> {
349+
let db_url = std::env::var("DATABASE_URL")
350+
.map_err(|_| anyhow::anyhow!("DATABASE_URL is required for partition-audit"))?;
351+
let config = DbConfig {
352+
database_url: db_url,
353+
max_connections: 1,
354+
min_connections: 1,
355+
statement_timeout_ms: 30_000,
356+
default_transaction_read_only: true,
357+
..DbConfig::default()
358+
};
359+
let pool = Db::connect_writer_pool(&config).await?;
360+
let row = sqlx::query(
361+
"SELECT current_database() AS database, current_user AS user, \
362+
current_schema() AS schema, \
363+
current_setting('default_transaction_read_only') = 'on' \
364+
AS default_transaction_read_only, \
365+
current_setting('transaction_read_only') = 'on' AS transaction_read_only",
366+
)
367+
.fetch_one(&pool)
368+
.await?;
369+
let identity = PartitionAuditIdentity {
370+
database: row.try_get("database")?,
371+
user: row.try_get("user")?,
372+
schema: row.try_get("schema")?,
373+
default_transaction_read_only: row.try_get("default_transaction_read_only")?,
374+
transaction_read_only: row.try_get("transaction_read_only")?,
375+
};
376+
if !identity.default_transaction_read_only || !identity.transaction_read_only {
377+
anyhow::bail!("partition-audit connection is not read-only");
378+
}
379+
380+
let report = Db::from_pool(pool)
381+
.audit_partitions_report(months_ahead)
382+
.await;
383+
let outcome = if !report.errors.is_empty() {
384+
"error"
385+
} else if !report.serving_safe() {
386+
"unsafe"
387+
} else if report.tables.iter().any(|table| table.degraded()) {
388+
"degraded"
389+
} else {
390+
"ok"
391+
};
392+
let code = match outcome {
393+
"error" => 5,
394+
"unsafe" => 2,
395+
_ => 0,
396+
};
397+
println!(
398+
"{}",
399+
serde_json::to_string_pretty(&PartitionAuditOutput {
400+
schema_version: 1,
401+
mode: "read_only",
402+
source_sha: option_env!("BUZZ_SOURCE_SHA").unwrap_or("unknown"),
403+
build_id: option_env!("BUZZ_BUILD_ID").unwrap_or("local"),
404+
build_url: option_env!("BUZZ_BUILD_URL").unwrap_or("unknown"),
405+
outcome,
406+
months_ahead,
407+
identity,
408+
report,
409+
})?
410+
);
411+
Ok(code)
412+
}
413+
317414
async fn cmd_add_member(pubkey_arg: String, role: String) -> Result<i32> {
318415
if let Err(msg) = validate_role(&role) {
319416
eprintln!("error: {msg}");
@@ -581,8 +678,7 @@ async fn connect_db() -> Result<Db> {
581678
}
582679

583680
fn db_config_from_env() -> DbConfig {
584-
let db_url = std::env::var("DATABASE_URL")
585-
.unwrap_or_else(|_| "postgres://buzz:buzz_dev@localhost:5432/buzz".to_string());
681+
let db_url = std::env::var("DATABASE_URL").unwrap_or_else(|_| DbConfig::default().database_url);
586682
DbConfig {
587683
database_url: db_url,
588684
..DbConfig::default()
@@ -801,3 +897,18 @@ mod storage_snapshot_tests {
801897
assert_eq!(persist_calls.load(Ordering::SeqCst), 0);
802898
}
803899
}
900+
901+
#[cfg(test)]
902+
mod tests {
903+
use super::*;
904+
905+
#[test]
906+
fn parses_partition_audit_month_horizon() {
907+
let cli = Cli::try_parse_from(["buzz-admin", "partition-audit", "--months-ahead", "6"])
908+
.expect("parse partition-audit command");
909+
assert!(matches!(
910+
cli.command,
911+
Command::PartitionAudit { months_ahead: 6 }
912+
));
913+
}
914+
}

‎crates/buzz-db/src/runtime/mod.rs‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@ pub struct DbConfig {
544544
/// (env `BUZZ_DB_STATEMENT_TIMEOUT_MS`). `0` disables it and is the
545545
/// default because migrations and backfills may legitimately run long.
546546
pub statement_timeout_ms: u64,
547+
/// Whether every new writer-pool connection defaults all transactions to
548+
/// read-only. Intended for operator audit commands, never the relay pool.
549+
pub default_transaction_read_only: bool,
547550
}
548551

549552
impl Default for DbConfig {
@@ -564,6 +567,7 @@ impl Default for DbConfig {
564567
lock_timeout_ms: DEFAULT_LOCK_TIMEOUT_MS,
565568
idle_txn_timeout_ms: DEFAULT_IDLE_TXN_TIMEOUT_MS,
566569
statement_timeout_ms: 0,
570+
default_transaction_read_only: false,
567571
}
568572
}
569573
}
@@ -649,6 +653,7 @@ impl Db {
649653
let lock_timeout_ms = config.lock_timeout_ms;
650654
let idle_txn_timeout_ms = config.idle_txn_timeout_ms;
651655
let statement_timeout_ms = config.statement_timeout_ms;
656+
let default_transaction_read_only = config.default_transaction_read_only;
652657
let options = PgPoolOptions::new()
653658
.max_connections(config.max_connections)
654659
.min_connections(config.min_connections)
@@ -693,11 +698,17 @@ impl Db {
693698
if let Err(error) = sqlx::query(
694699
"SELECT set_config('lock_timeout', $1, false), \
695700
set_config('idle_in_transaction_session_timeout', $2, false), \
696-
set_config('statement_timeout', $3, false)",
701+
set_config('statement_timeout', $3, false), \
702+
set_config('default_transaction_read_only', $4, false)",
697703
)
698704
.bind(lock_timeout_ms.to_string())
699705
.bind(idle_txn_timeout_ms.to_string())
700706
.bind(statement_timeout_ms.to_string())
707+
.bind(if default_transaction_read_only {
708+
"on"
709+
} else {
710+
"off"
711+
})
701712
.execute(&mut *conn)
702713
.await
703714
{

‎crates/buzz-db/src/store/artifact_postgres_tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl Fixture {
2424
crate::migration::run_migrations(&pool).await.unwrap();
2525
}
2626
let db = Db::from_pool(pool);
27-
db.ensure_future_partitions(1).await.unwrap();
27+
db.ensure_future_partitions(1, true).await.unwrap();
2828
let community = CommunityId::from_uuid(Uuid::new_v4());
2929
sqlx::query("INSERT INTO communities(id,host) VALUES($1,$2)")
3030
.bind(community.as_uuid())

0 commit comments

Comments
 (0)