From 036c317fd6d610621ef9d04a0a279d7935efd583 Mon Sep 17 00:00:00 2001 From: Lewis Date: Sun, 24 May 2026 12:47:33 +0300 Subject: [PATCH] fix(migrate): oauth refreshing, embedded db first invite code Lewis: May this revision serve well! --- crates/tranquil-pds/src/state.rs | 38 +++--- .../components/dashboard/AdminContent.svelte | 5 +- frontend/src/lib/migration/atproto-client.ts | 90 ++++++++++++- frontend/src/lib/migration/flow.svelte.ts | 125 ++++++++++-------- frontend/src/lib/migration/storage.ts | 1 + frontend/src/lib/migration/types.ts | 2 + frontend/src/tests/migration/storage.test.ts | 1 + 7 files changed, 183 insertions(+), 79 deletions(-) diff --git a/crates/tranquil-pds/src/state.rs b/crates/tranquil-pds/src/state.rs index 186ffec..61a9641 100644 --- a/crates/tranquil-pds/src/state.rs +++ b/crates/tranquil-pds/src/state.rs @@ -214,10 +214,10 @@ impl AppState { pub async fn new(shutdown: CancellationToken) -> Result> { let cfg = tranquil_config::get(); - match cfg.storage.repo_backend() { + let mut state = match cfg.storage.repo_backend() { tranquil_config::RepoBackend::TranquilStore => { tracing::info!("tranquil-store repo backend active. EXPERIMENTAL!"); - Ok(Self::from_store(shutdown).await) + Self::from_store(shutdown).await } tranquil_config::RepoBackend::Postgres => { let database_url = &cfg.database.url; @@ -247,28 +247,22 @@ impl AppState { .await .map_err(|e| format!("Failed to run migrations: {}", e))?; - let bootstrap_invite_code = match ( - cfg.server.invite_code_required, - sqlx::query_scalar!("SELECT COUNT(*) FROM users") - .fetch_one(&db) - .await, - ) { - (true, Ok(Some(0))) => { - let code = crate::util::gen_invite_code(); - tracing::info!( - "No users exist and invite codes are required. Bootstrap invite code: {}", - code - ); - Some(code) - } - _ => None, - }; - - let mut state = Self::from_db(db, shutdown).await; - state.bootstrap_invite_code = bootstrap_invite_code; - Ok(state) + Self::from_db(db, shutdown).await } + }; + + if cfg.server.invite_code_required + && state.repos.user.count_users().await.unwrap_or(1) == 0 + { + let code = crate::util::gen_invite_code(); + tracing::info!( + "No users exist and invite codes are required. Bootstrap invite code: {}", + code + ); + state.bootstrap_invite_code = Some(code); } + + Ok(state) } pub async fn from_db(db: PgPool, shutdown: CancellationToken) -> Self { diff --git a/frontend/src/components/dashboard/AdminContent.svelte b/frontend/src/components/dashboard/AdminContent.svelte index eb6f139..a964b9c 100644 --- a/frontend/src/components/dashboard/AdminContent.svelte +++ b/frontend/src/components/dashboard/AdminContent.svelte @@ -1,5 +1,5 @@