chore(migration): fix oauth2 migration

This commit is contained in:
Sarah Vaupel 2024-03-13 10:20:10 +01:00
parent 843e6dbba2
commit 770c2f3182

View File

@ -178,13 +178,13 @@ customMigrations = mapF $ \case
;
|]
Migration20240312OAuth2 -> whenM (columnExists "user" "ldap_primary_key") $ do
Migration20240312OAuth2 -> whenM (andM [ columnNotExists "user" "password_hash", columnExists "user" "authentication", columnExists "user" "last_ldap_synchronisation", columnExists "user" "ldap_primary_key" ]) $ do
[executeQQ|
ALTER TABLE "user" ADD COLUMN "password_hash" VARCHAR NULL;
|]
let getPWHashes = [queryQQ| SELECT "id", "authentication"->'pw-hash' FROM "user" WHERE "authentication"->'pw-hash' IS NOT NULL; |]
migratePWHash [ fromPersistValue -> Right (uid :: UserId), fromPersistValue -> Right (pwHash :: Text) ] = [executeQQ| UPDATE "user" SET "password_hash" = #{pwHash} WHERE "id" = #{uid}; |]
migratePWHash _ = error "otherwise case reached!" -- TODO: return ()
migratePWHash _ = return ()
in runConduit $ getPWHashes .| C.mapM_ migratePWHash
[executeQQ|
ALTER TABLE "user" DROP COLUMN "authentication";