chore(migration): add oauth2 migration
This commit is contained in:
parent
3607a9da6d
commit
843e6dbba2
@ -49,6 +49,7 @@ import qualified Data.Time.Zones as TZ
|
||||
data ManualMigration
|
||||
= Migration20230524QualificationUserBlock
|
||||
| Migration20230703LmsUserStatus
|
||||
| Migration20240312OAuth2
|
||||
deriving (Eq, Ord, Read, Show, Enum, Bounded, Generic)
|
||||
deriving anyclass (Universe, Finite)
|
||||
|
||||
@ -177,6 +178,23 @@ customMigrations = mapF $ \case
|
||||
;
|
||||
|]
|
||||
|
||||
Migration20240312OAuth2 -> whenM (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 ()
|
||||
in runConduit $ getPWHashes .| C.mapM_ migratePWHash
|
||||
[executeQQ|
|
||||
ALTER TABLE "user" DROP COLUMN "authentication";
|
||||
|]
|
||||
|
||||
[executeQQ|
|
||||
ALTER TABLE "user" RENAME COLUMN "last_ldap_synchronisation" TO "password_hash";
|
||||
ALTER TABLE "user" DROP COLUMN "ldap_primary_key";
|
||||
|]
|
||||
|
||||
|
||||
tableExists :: MonadIO m => Text -> ReaderT SqlBackend m Bool
|
||||
tableExists table = do
|
||||
|
||||
Reference in New Issue
Block a user