feat(server): create-user CLI + session-store migration on startup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-02 15:07:58 +02:00
parent 642f709bbe
commit dbff95c2a9
6 changed files with 159 additions and 8 deletions
+40
View File
@@ -0,0 +1,40 @@
use db::Db;
use domain::Role;
use sqlx::PgPool;
// Note: `server::create_user` opens its own DB connection by URL, but `#[sqlx::test]`
// provisions a temporary database whose URL is not directly exposed. The test below
// exercises the same building blocks that `server::create_user` composes —
// `auth::hash_password` + `db::users::create_user` + `db::users::credentials_by_email` —
// against the test pool, which fully validates the end-to-end bootstrap logic.
#[sqlx::test(migrations = "../db/migrations")]
async fn create_user_persists_and_password_verifies(pool: PgPool) {
let db = Db::from_pool(pool.clone());
let hash = auth::hash_password("bootstrap-pw-123").unwrap();
let mut tx = db.pool().begin().await.unwrap();
db::users::create_user(
&mut tx,
domain::AuditActor::System,
&domain::NewUser {
email: domain::Email::parse("boss@example.com").unwrap(),
password_hash: hash,
role: Role::Admin,
},
)
.await
.unwrap();
tx.commit().await.unwrap();
let (user, stored_hash) = db::users::credentials_by_email(db.pool(), "boss@example.com")
.await
.unwrap()
.unwrap();
assert_eq!(user.role, Role::Admin);
assert!(auth::verify_password("bootstrap-pw-123", &stored_hash));
}