Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPB-10058 delete phone column in brig's user table #4130

Merged
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ packages:
, tools/db/migrate-sso-feature-flag/
, tools/db/move-team/
, tools/db/phone-users/
, tools/db/remove-phone-keys
, tools/db/repair-handles/
, tools/db/repair-brig-clients-table/
, tools/db/service-backfill/
Expand Down
1 change: 0 additions & 1 deletion cassandra-schema.cql
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,6 @@ CREATE TABLE brig_test.user (
managed_by int,
name text,
password blob,
phone text,
picture list<blob>,
provider uuid,
searchable boolean,
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/5-internal/WPB-10058
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- DB migration for dropping `phone` column from `user` table
- Tool for deleting phone keys from `user_keys`
mdimjasevic marked this conversation as resolved.
Show resolved Hide resolved
1 change: 0 additions & 1 deletion libs/wire-subsystems/src/Wire/StoredUser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ data StoredUser = StoredUser
name :: Name,
pict :: Maybe Pict,
email :: Maybe Email,
phone :: Maybe Phone,
ssoId :: Maybe UserSSOId,
accentId :: ColourId,
assets :: Maybe [Asset],
Expand Down
4 changes: 2 additions & 2 deletions libs/wire-subsystems/src/Wire/UserStore/Cassandra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ lookupLocaleImpl u = do

selectUser :: PrepQuery R (Identity UserId) (TupleType StoredUser)
selectUser =
"SELECT id, name, picture, email, phone, sso_id, accent_id, assets, \
"SELECT id, name, picture, email, sso_id, accent_id, assets, \
\activated, status, expires, language, country, provider, service, \
\handle, team, managed_by, supported_protocols \
\FROM user where id = ?"
Expand Down Expand Up @@ -166,7 +166,7 @@ updateUserToTombstone :: PrepQuery W (AccountStatus, Name, ColourId, Pict, [Asse
updateUserToTombstone =
"UPDATE user SET status = ?, name = ?,\
\ accent_id = ?, picture = ?, assets = ?, handle = null, country = null,\
\ language = null, email = null, phone = null, sso_id = null WHERE id = ?"
\ language = null, email = null, sso_id = null WHERE id = ?"

statusSelect :: PrepQuery R (Identity UserId) (Identity (Maybe AccountStatus))
statusSelect = "SELECT status FROM user WHERE id = ?"
Expand Down
1 change: 1 addition & 0 deletions nix/local-haskell-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
migrate-sso-feature-flag = hself.callPackage ../tools/db/migrate-sso-feature-flag/default.nix { inherit gitignoreSource; };
move-team = hself.callPackage ../tools/db/move-team/default.nix { inherit gitignoreSource; };
phone-users = hself.callPackage ../tools/db/phone-users/default.nix { inherit gitignoreSource; };
remove-phone-keys = hself.callPackage ../tools/db/remove-phone-keys/default.nix { inherit gitignoreSource; };
repair-brig-clients-table = hself.callPackage ../tools/db/repair-brig-clients-table/default.nix { inherit gitignoreSource; };
repair-handles = hself.callPackage ../tools/db/repair-handles/default.nix { inherit gitignoreSource; };
service-backfill = hself.callPackage ../tools/db/service-backfill/default.nix { inherit gitignoreSource; };
Expand Down
2 changes: 1 addition & 1 deletion nix/wire-server.nix
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ let
out = import ./all-toplevel-derivations.nix {
inherit (pkgs) lib;
fn = mk;
# more than two takes more than 32GB of RAM, so this is what
# more than two takes more than 32GB of RAM, so this is what
# we're limiting ourselves to
recursionDepth = 2;
keyFilter = k: k != "passthru";
Expand Down
1 change: 1 addition & 0 deletions services/brig/brig.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ library
Brig.Schema.V79_ConnectionRemoteIndex
Brig.Schema.V80_KeyPackageCiphersuite
Brig.Schema.V81_AddFederationRemoteTeams
Brig.Schema.V82_DropPhoneColumn
Brig.Schema.V_FUTUREWORK
Brig.Team.API
Brig.Team.DB
Expand Down
4 changes: 3 additions & 1 deletion services/brig/src/Brig/Schema/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import Brig.Schema.V78_ClientLastActive qualified as V78_ClientLastActive
import Brig.Schema.V79_ConnectionRemoteIndex qualified as V79_ConnectionRemoteIndex
import Brig.Schema.V80_KeyPackageCiphersuite qualified as V80_KeyPackageCiphersuite
import Brig.Schema.V81_AddFederationRemoteTeams qualified as V81_AddFederationRemoteTeams
import Brig.Schema.V82_DropPhoneColumn qualified as V82_DropPhoneColumn
import Cassandra.MigrateSchema (migrateSchema)
import Cassandra.Schema
import Control.Exception (finally)
Expand Down Expand Up @@ -118,7 +119,8 @@ migrations =
V78_ClientLastActive.migration,
V79_ConnectionRemoteIndex.migration,
V80_KeyPackageCiphersuite.migration,
V81_AddFederationRemoteTeams.migration
V81_AddFederationRemoteTeams.migration,
V82_DropPhoneColumn.migration
-- FUTUREWORK: undo V41 (searchable flag); we stopped using it in
-- https://github.com/wireapp/wire-server/pull/964
--
Expand Down
35 changes: 35 additions & 0 deletions services/brig/src/Brig/Schema/V82_DropPhoneColumn.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{-# LANGUAGE QuasiQuotes #-}

-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2023 Wire Swiss GmbH <[email protected]>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Brig.Schema.V82_DropPhoneColumn
( migration,
)
where

import Cassandra.Schema
import Imports
import Text.RawString.QQ

migration :: Migration
migration =
Migration 82 "Drop phone column from user table" $ do
schema'
[r|
ALTER TABLE user DROP phone
|]
9 changes: 3 additions & 6 deletions tools/db/inconsistencies/src/DanglingUserKeys.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ data Inconsistency = Inconsistency
time :: Writetime UserId,
status :: Maybe (WithWritetime AccountStatus),
userEmail :: Maybe (WithWritetime Email),
userPhone :: Maybe (WithWritetime Phone),
inconsistencyCase :: Text
}
deriving (Generic)
Expand Down Expand Up @@ -130,13 +129,13 @@ instance Cql EmailKey where
instance Aeson.ToJSON EmailKey where
toJSON = Aeson.toJSON . emailKeyUniq

type UserDetailsRow = (Maybe AccountStatus, Maybe (Writetime AccountStatus), Maybe Email, Maybe (Writetime Email), Maybe Phone, Maybe (Writetime Phone))
type UserDetailsRow = (Maybe AccountStatus, Maybe (Writetime AccountStatus), Maybe Email, Maybe (Writetime Email))

getUserDetails :: UserId -> Client (Maybe UserDetailsRow)
getUserDetails uid = retry x5 $ query1 cql (params LocalQuorum (Identity uid))
where
cql :: PrepQuery R (Identity UserId) UserDetailsRow
cql = "SELECT status, writetime(status), email, writetime(email), phone, writetime(phone) from user where id = ?"
cql = "SELECT status, writetime(status), email, writetime(email) from user where id = ?"

checkKey :: Logger -> ClientState -> EmailKey -> Bool -> IO (Maybe Inconsistency)
checkKey l brig key repairData = do
Expand Down Expand Up @@ -179,16 +178,14 @@ checkUser l brig key uid time repairData = do
Nothing -> do
let status = Nothing
userEmail = Nothing
userPhone = Nothing
inconsistencyCase = "2."
when repairData $ -- case 2.
runClient brig $
freeEmailKey l key
pure . Just $ Inconsistency {userId = uid, ..}
Just (mStatus, mStatusWriteTime, mEmail, mEmailWriteTime, mPhone, mPhoneWriteTime) -> do
Just (mStatus, mStatusWriteTime, mEmail, mEmailWriteTime) -> do
let status = WithWritetime <$> mStatus <*> mStatusWriteTime
userEmail = WithWritetime <$> mEmail <*> mEmailWriteTime
userPhone = WithWritetime <$> mPhone <*> mPhoneWriteTime
statusError = case mStatus of
Nothing -> True
Just Deleted -> True
Expand Down
8 changes: 4 additions & 4 deletions tools/db/move-team/src/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -360,18 +360,18 @@ importBrigRichInfo Env {..} path = do

-- brig.user

type RowBrigUser = (Maybe UUID, Maybe [Float], Maybe Int32, Maybe Bool, Maybe [AssetIgnoreData], Maybe Ascii, Maybe Text, Maybe UTCTime, Maybe Text, Maybe Ascii, Maybe Int32, Maybe Text, Maybe Blob, Maybe Text, Maybe [Blob], Maybe UUID, Maybe Bool, Maybe UUID, Maybe Text, Maybe Int32, Maybe UUID)
type RowBrigUser = (Maybe UUID, Maybe [Float], Maybe Int32, Maybe Bool, Maybe [AssetIgnoreData], Maybe Ascii, Maybe Text, Maybe UTCTime, Maybe Text, Maybe Ascii, Maybe Int32, Maybe Text, Maybe Blob, Maybe [Blob], Maybe UUID, Maybe Bool, Maybe UUID, Maybe Text, Maybe Int32, Maybe UUID)

selectBrigUser :: PrepQuery R (Identity [UserId]) RowBrigUser
selectBrigUser = "SELECT id, accent, accent_id, activated, assets, country, email, expires, handle, language, managed_by, name, password, phone, picture, provider, searchable, service, sso_id, status, team FROM user WHERE id in ?"
selectBrigUser = "SELECT id, accent, accent_id, activated, assets, country, email, expires, handle, language, managed_by, name, password, picture, provider, searchable, service, sso_id, status, team FROM user WHERE id in ?"

readBrigUser :: Env -> [UserId] -> ConduitM () [RowBrigUser] IO ()
readBrigUser Env {..} uids =
transPipe (runClient envBrig) $
paginateC selectBrigUser (paramsP LocalQuorum (pure uids) envPageSize) x5

selectBrigUserAll :: PrepQuery R () RowBrigUser
selectBrigUserAll = "SELECT id, accent, accent_id, activated, assets, country, email, expires, handle, language, managed_by, name, password, phone, picture, provider, searchable, service, sso_id, status, team FROM user"
selectBrigUserAll = "SELECT id, accent, accent_id, activated, assets, country, email, expires, handle, language, managed_by, name, password, picture, provider, searchable, service, sso_id, status, team FROM user"

readBrigUserAll :: Env -> ConduitM () [RowBrigUser] IO ()
readBrigUserAll Env {..} =
Expand All @@ -388,7 +388,7 @@ exportBrigUserFull env path = do

insertBrigUser :: PrepQuery W RowBrigUser ()
insertBrigUser =
"INSERT INTO user (id, accent, accent_id, activated, assets, country, email, expires, handle, language, managed_by, name, password, phone, picture, provider, searchable, service, sso_id, status, team) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
"INSERT INTO user (id, accent, accent_id, activated, assets, country, email, expires, handle, language, managed_by, name, password, picture, provider, searchable, service, sso_id, status, team) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

importBrigUser :: Env -> FilePath -> IO ()
importBrigUser Env {..} path = do
Expand Down
14 changes: 6 additions & 8 deletions tools/db/move-team/src/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ deriving instance ToJSON TimeUuid

deriving instance FromJSON TimeUuid

instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n, ToJSON o, ToJSON p, ToJSON q, ToJSON r, ToJSON s, ToJSON t, ToJSON u) => ToJSON ((,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u) where
toJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) =
instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n, ToJSON o, ToJSON p, ToJSON q, ToJSON r, ToJSON s, ToJSON t) => ToJSON ((,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t) where
toJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) =
Array $
V.fromList
[ toJSON a,
Expand All @@ -127,14 +127,13 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g,
toJSON q,
toJSON r,
toJSON s,
toJSON t,
toJSON u
toJSON t
]

instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l, FromJSON m, FromJSON n, FromJSON o, FromJSON p, FromJSON q, FromJSON r, FromJSON s, FromJSON t, FromJSON u) => FromJSON ((,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u) where
instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l, FromJSON m, FromJSON n, FromJSON o, FromJSON p, FromJSON q, FromJSON r, FromJSON s, FromJSON t) => FromJSON ((,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t) where
parseJSON = withArray "Tuple" $ \case
(toList -> [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u]) ->
(,,,,,,,,,,,,,,,,,,,,)
(toList -> [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t]) ->
(,,,,,,,,,,,,,,,,,,,)
<$> parseJSON a
<*> parseJSON b
<*> parseJSON c
Expand All @@ -155,5 +154,4 @@ instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f
<*> parseJSON r
<*> parseJSON s
<*> parseJSON t
<*> parseJSON u
_ -> fail "Expected array of length 21"
1 change: 1 addition & 0 deletions tools/db/remove-phone-keys/.ormolu
20 changes: 20 additions & 0 deletions tools/db/remove-phone-keys/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Remove phone keys

```text
remove-phone-keys

Usage: remove-phone-keys [--brig-cassandra-host HOST]
[--brig-cassandra-port PORT]
[--brig-cassandra-keyspace STRING]

Remove phone data from wire-server

Available options:
-h,--help Show this help text
--brig-cassandra-host HOST
Cassandra Host for brig (default: "localhost")
--brig-cassandra-port PORT
Cassandra Port for brig (default: 9042)
--brig-cassandra-keyspace STRING
Cassandra Keyspace for brig (default: "brig_test")
```
23 changes: 23 additions & 0 deletions tools/db/remove-phone-keys/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2024 Wire Swiss GmbH <[email protected]>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Main where

import qualified RemovePhoneKeys.Lib as Lib

main :: IO ()
main = Lib.main
40 changes: 40 additions & 0 deletions tools/db/remove-phone-keys/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# WARNING: GENERATED FILE, DO NOT EDIT.
# This file is generated by running hack/bin/generate-local-nix-packages.sh and
# must be regenerated whenever local packages are added or removed, or
# dependencies are added or removed.
{ mkDerivation
, attoparsec
, base
, cassandra-util
, conduit
, exceptions
, gitignoreSource
, imports
, lens
, lib
, optparse-applicative
, text
, tinylog
}:
mkDerivation {
pname = "remove-phone-keys";
version = "1.0.0";
src = gitignoreSource ./.;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [
attoparsec
cassandra-util
conduit
exceptions
imports
lens
optparse-applicative
text
tinylog
];
executableHaskellDepends = [ base ];
description = "remove phone data from wire-server";
license = lib.licenses.agpl3Only;
mainProgram = "remove-phone-keys";
}
Loading
Loading