packages feed

shomei-migrations 0.2.0.1 → 0.2.0.2

raw patch · 5 files changed

+68/−4 lines, 5 filesdep ~shomei-migrationsPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: shomei-migrations

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -4,6 +4,10 @@ [PVP](https://pvp.haskell.org/) and is versioned independently of the other Shōmei packages. +## 0.2.0.2 — 2026-11-25++- Add migration 0044 for authentication generations and initiating enrollment sessions. Preserve factors/sessions and require legacy pending flows to restart; drain old writers before enabling administrative recovery.+ ## 0.2.0.1 — 2026-11-05  - Keep the exported Haskell API unchanged; require the released [`pg-migrate`](mori://shinzui/pg-migrate/packages/pg-migrate) 1.2 family and [`ephemeral-pg`](mori://shinzui/ephemeral-pg/packages/ephemeral-pg) 0.3.1, with stable per-user test database cleanup roots.
+ migrations/shomei/0044-add-authentication-generation.sql view
@@ -0,0 +1,15 @@+-- add-authentication-generation++SET LOCAL search_path = pg_catalog, pg_temp;++-- Preserve enrolled factors and sessions; legacy pending flows restart after rollout.+ALTER TABLE shomei.shomei_users+  ADD COLUMN authentication_generation bigint NOT NULL DEFAULT 0+  CHECK (authentication_generation >= 0);+ALTER TABLE shomei.shomei_webauthn_pending_ceremonies+  ADD COLUMN authentication_generation bigint CHECK (authentication_generation >= 0),+  ADD COLUMN initiating_session_id uuid;+ALTER TABLE shomei.shomei_oauth_authorization_codes+  ADD COLUMN authentication_generation bigint CHECK (authentication_generation >= 0);+ALTER TABLE shomei.shomei_totp_credentials+  ADD COLUMN authentication_generation bigint CHECK (authentication_generation >= 0);
migrations/shomei/manifest view
@@ -41,3 +41,4 @@ 0041-add-active-session-principal-indexes.sql 0042-add-admin-keyset-indexes.sql 0043-enforce-session-provenance-upgrades.sql+0044-add-authentication-generation.sql
shomei-migrations.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: shomei-migrations-version: 0.2.0.1+version: 0.2.0.2 synopsis:   Schema migrations for Shōmei (pg-migrate component, embedded SQL) @@ -84,7 +84,7 @@     optparse-applicative >=0.19 && <0.20,     pg-migrate >=1.2 && <1.3,     pg-migrate-cli >=1.2 && <1.3,-    shomei-migrations ^>=0.2.0.1,+    shomei-migrations ^>=0.2.0.2,     text >=2.0 && <2.2,  library test-support@@ -97,7 +97,7 @@     directory >=1.3 && <1.4,     ephemeral-pg >=0.3.1 && <0.4,     pg-migrate >=1.2 && <1.3,-    shomei-migrations ^>=0.2.0.1,+    shomei-migrations ^>=0.2.0.2,     text >=2.0 && <2.2,     time >=1.12 && <1.15,     unix >=2.8 && <2.9,@@ -120,6 +120,6 @@     pg-migrate >=1.2 && <1.3,     pg-migrate-embed >=1.2 && <1.3,     pg-migrate-test-support >=1.2 && <1.3,-    shomei-migrations ^>=0.2.0.1,+    shomei-migrations ^>=0.2.0.2,     tasty >=1.4 && <1.6,     tasty-hunit >=0.10 && <0.11,
test/Main.hs view
@@ -28,6 +28,7 @@         [ testCase             "composition preserves a host component's namespace state"             testCompositionPreservesHostNamespace,+          testCase "generation upgrade preserves credentials/sessions and marks old pending flows as legacy" testGenerationUpgrade,           testCase "provenance upgrade repairs legacy machine and actor rows and defaults unknown writers safely" testProvenanceUpgrade         ]     )@@ -198,3 +199,46 @@  embeddedHistory :: NonEmpty (FilePath, Data.ByteString.ByteString) embeddedHistory = $(embedMigrationManifest "migrations/shomei/manifest")++testGenerationUpgrade :: Assertion+testGenerationUpgrade = do+  let history = NE.toList embeddedHistory+      (before, upgrade) = span ((/= "0044-add-authentication-generation.sql") . fst) history+      fixture = ("0043-generation-fixture.sql", generationFixture)+      component = expectRight (migrationComponentFromEmbeddedSql "generation-upgrade" Set.empty (NE.fromList (before <> [fixture] <> upgrade)))+      plan = expectRight (migrationPlan (component :| []))+  result <- withMigratedDatabase plan \connection -> do+    snapshot <- Connection.use connection (Session.statement () generationSnapshot)+    snapshot @?= Right True+    invalid <- Connection.use connection (Session.script "UPDATE shomei.shomei_users SET authentication_generation = -1")+    case invalid of+      Left _ -> pure ()+      Right () -> assertFailure "negative generation admitted"+  case result of+    Left err -> assertFailure (show err)+    Right () -> pure ()++generationFixture :: Data.ByteString.ByteString+generationFixture =+  """+  INSERT INTO shomei.shomei_users(user_id,login_id,status,created_at,updated_at)+    VALUES ('11111111-1111-1111-1111-111111111111','generation-user','active',now(),now());+  INSERT INTO shomei.shomei_sessions(session_id,user_id,status,created_at,expires_at,kind)+    VALUES ('aaaaaaaa-0000-0000-0000-000000000001','11111111-1111-1111-1111-111111111111','active',now(),now()+interval '1 day','interactive');+  INSERT INTO shomei.shomei_webauthn_pending_ceremonies(ceremony_id,user_id,kind,options_blob,created_at,expires_at)+    VALUES ('bbbbbbbb-0000-0000-0000-000000000001','11111111-1111-1111-1111-111111111111','authentication','public-fixture',now(),now()+interval '5 minutes');+  INSERT INTO shomei.shomei_totp_credentials(totp_credential_id,user_id,secret_enc,created_at,confirmed_at,envelope_version)+    VALUES ('cccccccc-0000-0000-0000-000000000001','11111111-1111-1111-1111-111111111111','public-fixture',now(),now(),1);+  """++generationSnapshot :: Statement () Bool+generationSnapshot =+  Statement.preparable+    """+    SELECT (SELECT count(*) = 1 AND bool_and(authentication_generation = 0) FROM shomei.shomei_users)+      AND (SELECT count(*) = 1 AND bool_and(status = 'active') FROM shomei.shomei_sessions)+      AND (SELECT count(*) = 1 AND bool_and(confirmed_at IS NOT NULL) FROM shomei.shomei_totp_credentials)+      AND (SELECT count(*) = 1 AND bool_and(authentication_generation IS NULL) FROM shomei.shomei_webauthn_pending_ceremonies)+    """+    Encoders.noParams+    (Decoders.singleRow (Decoders.column (Decoders.nonNullable Decoders.bool)))