diff --git a/app/database/migrations/0001_01_01_000000_create_users_table.rs b/app/database/migrations/0001_01_01_000000_create_users_table.rs index 549723ab..3d663832 100644 --- a/app/database/migrations/0001_01_01_000000_create_users_table.rs +++ b/app/database/migrations/0001_01_01_000000_create_users_table.rs @@ -22,7 +22,8 @@ pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> { tx.schema() .create("sessions", |table| { table.string("id").primary(); - table.big_integer("user_id").nullable().index(); + // The signed-in user's pid: their auth id (`User::auth_id`) + table.uuid("user_id").nullable().index(); table.string("ip_address").length(45).nullable(); table.text("user_agent").nullable(); table.long_text("payload"); diff --git a/app/src/testing.rs b/app/src/testing.rs index 9cd99b39..4882bb72 100644 --- a/app/src/testing.rs +++ b/app/src/testing.rs @@ -28,12 +28,14 @@ pub fn configure() -> ApplicationBuilder { ("APP_DEBUG", "true"), ("BCRYPT_ROUNDS", "4"), ("BROADCAST_CONNECTION", "discard"), - ("CACHE_STORE", "memory"), + ("CACHE_STORE", "database"), ("FEATURE_STORE", "memory"), ("MAIL_MAILER", "log"), ("OTEL_SDK_DISABLED", "true"), + // Production queues on the database and runs jobs on its worker; tests run them inline ("QUEUE_CONNECTION", "sync"), - ("SESSION_DRIVER", "memory"), + // Sessions and the cache in Postgres, as production keeps them + ("SESSION_DRIVER", "database"), ("WORKFLOW_STORE", "memory"), ("DB_CONNECTION", "pgsql"), // The test blob store: RustFS in CI, MinIO on a development machine, both on port 59000. diff --git a/app/tests/sign_in.rs b/app/tests/sign_in.rs index 471d2244..65f49b08 100644 --- a/app/tests/sign_in.rs +++ b/app/tests/sign_in.rs @@ -58,6 +58,10 @@ async fn a_new_person_gets_an_account_and_returns_where_they_started(app: Applic .assert_ok() .assert_json_path("signed_in", true) .assert_json_path("name", "Ada Lovelace"); + // The session is a row in Postgres (SESSION_DRIVER=database, as in production), under the user's pid + let pid = user.pid; + let sessions: i64 = db::query!("SELECT count(*) FROM sessions WHERE user_id = {pid}").scalar().await?.unwrap_or(0); + assert_eq!(sessions, 1); // Again: the same account, found by the GitHub ID let again = app.get("/auth/github/callback").await;