From dc771bc9ed3d51be197e939f66510a28928cfd82 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Tue, 16 Apr 2024 14:25:22 +0200 Subject: [PATCH 1/7] Move around Cql instances. --- libs/brig-types/src/Brig/Types/Search.hs | 11 + libs/types-common/src/Data/Domain.hs | 7 + libs/types-common/src/Data/Handle.hs | 3 + libs/wire-api/src/Wire/API/Asset.hs | 9 + libs/wire-api/src/Wire/API/Connection.hs | 33 ++ libs/wire-api/src/Wire/API/MLS/CipherSuite.hs | 11 + libs/wire-api/src/Wire/API/Properties.hs | 9 + libs/wire-api/src/Wire/API/User.hs | 30 ++ libs/wire-api/src/Wire/API/User/Activation.hs | 5 + libs/wire-api/src/Wire/API/User/Client.hs | 34 +- libs/wire-api/src/Wire/API/User/Identity.hs | 23 ++ libs/wire-api/src/Wire/API/User/Password.hs | 5 + libs/wire-api/src/Wire/API/User/Profile.hs | 93 +++++ libs/wire-api/src/Wire/API/User/RichInfo.hs | 7 + libs/wire-api/src/Wire/API/User/Search.hs | 13 + services/brig/brig.cabal | 1 - services/brig/src/Brig/Data/Instances.hs | 319 ------------------ .../galley/src/Galley/Cassandra/Instances.hs | 8 +- tools/db/auto-whitelist/auto-whitelist.cabal | 1 - tools/db/auto-whitelist/src/Work.hs | 3 - tools/db/find-undead/src/Work.hs | 20 -- .../migrate-sso-feature-flag.cabal | 1 - tools/db/migrate-sso-feature-flag/src/Work.hs | 3 - tools/db/move-team/src/Work.hs | 3 - .../service-backfill/service-backfill.cabal | 1 - tools/db/service-backfill/src/Work.hs | 3 - tools/mlsstats/src/MlsStats/Run.hs | 6 - 27 files changed, 289 insertions(+), 373 deletions(-) delete mode 100644 services/brig/src/Brig/Data/Instances.hs diff --git a/libs/brig-types/src/Brig/Types/Search.hs b/libs/brig-types/src/Brig/Types/Search.hs index cbd6eb0a986..2bf55eb1ea8 100644 --- a/libs/brig-types/src/Brig/Types/Search.hs +++ b/libs/brig-types/src/Brig/Types/Search.hs @@ -26,6 +26,7 @@ module Brig.Types.Search ) where +import Cassandra qualified as C import Data.Aeson import Data.Attoparsec.ByteString import Data.ByteString.Builder @@ -77,6 +78,16 @@ instance FromByteString SearchVisibilityInbound where SearchableByOwnTeam <$ string "searchable-by-own-team" <|> SearchableByAllTeams <$ string "searchable-by-all-teams" +instance C.Cql SearchVisibilityInbound where + ctype = C.Tagged C.IntColumn + + toCql SearchableByOwnTeam = C.CqlInt 0 + toCql SearchableByAllTeams = C.CqlInt 1 + + fromCql (C.CqlInt 0) = pure SearchableByOwnTeam + fromCql (C.CqlInt 1) = pure SearchableByAllTeams + fromCql n = Left $ "Unexpected SearchVisibilityInbound: " ++ show n + defaultSearchVisibilityInbound :: SearchVisibilityInbound defaultSearchVisibilityInbound = SearchableByOwnTeam diff --git a/libs/types-common/src/Data/Domain.hs b/libs/types-common/src/Data/Domain.hs index 6f9d0884405..e45d966c85b 100644 --- a/libs/types-common/src/Data/Domain.hs +++ b/libs/types-common/src/Data/Domain.hs @@ -19,6 +19,7 @@ module Data.Domain where +import Cassandra import Control.Lens ((?~)) import Data.Aeson (FromJSON, FromJSONKey, FromJSONKeyFunction (FromJSONKeyTextParser), ToJSON, ToJSONKey (toJSONKey)) import Data.Aeson qualified as Aeson @@ -177,3 +178,9 @@ instance Arbitrary DomainText where [ (1, pure ""), (5, x) -- to get longer labels ] + +instance Cql Domain where + ctype = Tagged TextColumn + toCql = CqlText . domainText + fromCql (CqlText txt) = mkDomain txt + fromCql _ = Left "Domain: Text expected" diff --git a/libs/types-common/src/Data/Handle.hs b/libs/types-common/src/Data/Handle.hs index 29d1570cc32..56d61f5165a 100644 --- a/libs/types-common/src/Data/Handle.hs +++ b/libs/types-common/src/Data/Handle.hs @@ -25,6 +25,7 @@ module Data.Handle ) where +import Cassandra qualified as C import Data.Aeson (FromJSON (..), ToJSON (..)) import Data.Attoparsec.ByteString.Char8 qualified as Atto import Data.Bifunctor (Bifunctor (first)) @@ -65,6 +66,8 @@ instance ToHttpApiData Handle where instance FromByteString Handle where parser = handleParser +deriving instance C.Cql Handle + parseHandle :: Text -> Maybe Handle parseHandle = either (const Nothing) Just . parseHandleEither diff --git a/libs/wire-api/src/Wire/API/Asset.hs b/libs/wire-api/src/Wire/API/Asset.hs index 200fcbe245c..784f0081070 100644 --- a/libs/wire-api/src/Wire/API/Asset.hs +++ b/libs/wire-api/src/Wire/API/Asset.hs @@ -63,6 +63,7 @@ module Wire.API.Asset ) where +import Cassandra qualified as C import Codec.MIME.Type qualified as MIME import Control.Lens (makeLenses, (?~)) import Data.Aeson (FromJSON (..), ToJSON (..)) @@ -189,6 +190,14 @@ instance FromHttpApiData AssetKey where nilAssetKey :: AssetKey nilAssetKey = AssetKeyV3 (Id UUID.nil) AssetVolatile +instance C.Cql AssetKey where + ctype = C.Tagged C.TextColumn + toCql = C.CqlText . assetKeyToText + + -- if the asset key is invalid we will return the nil asset key (`3-1-00000000-0000-0000-0000-000000000000`) + fromCql (C.CqlText txt) = pure $ fromRight nilAssetKey $ runParser parser $ T.encodeUtf8 txt + fromCql _ = Left "AssetKey: Expected CqlText" + -------------------------------------------------------------------------------- -- AssetToken diff --git a/libs/wire-api/src/Wire/API/Connection.hs b/libs/wire-api/src/Wire/API/Connection.hs index 138b6c3eb4b..7c0fa5bbfdd 100644 --- a/libs/wire-api/src/Wire/API/Connection.hs +++ b/libs/wire-api/src/Wire/API/Connection.hs @@ -40,6 +40,7 @@ module Wire.API.Connection ) where +import Cassandra qualified as C import Control.Applicative (optional) import Control.Lens ((?~)) import Data.Aeson (FromJSON (..), ToJSON (..)) @@ -224,6 +225,38 @@ instance ToHttpApiData Relation where Cancelled -> "cancelled" MissingLegalholdConsent -> "missing-legalhold-consent" +instance C.Cql RelationWithHistory where + ctype = C.Tagged C.IntColumn + + fromCql (C.CqlInt i) = case i of + 0 -> pure AcceptedWithHistory + 1 -> pure BlockedWithHistory + 2 -> pure PendingWithHistory + 3 -> pure IgnoredWithHistory + 4 -> pure SentWithHistory + 5 -> pure CancelledWithHistory + 6 -> pure MissingLegalholdConsentFromAccepted + 7 -> pure MissingLegalholdConsentFromBlocked + 8 -> pure MissingLegalholdConsentFromPending + 9 -> pure MissingLegalholdConsentFromIgnored + 10 -> pure MissingLegalholdConsentFromSent + 11 -> pure MissingLegalholdConsentFromCancelled + n -> Left $ "unexpected RelationWithHistory: " ++ show n + fromCql _ = Left "RelationWithHistory: int expected" + + toCql AcceptedWithHistory = C.CqlInt 0 + toCql BlockedWithHistory = C.CqlInt 1 + toCql PendingWithHistory = C.CqlInt 2 + toCql IgnoredWithHistory = C.CqlInt 3 + toCql SentWithHistory = C.CqlInt 4 + toCql CancelledWithHistory = C.CqlInt 5 + toCql MissingLegalholdConsentFromAccepted = C.CqlInt 6 + toCql MissingLegalholdConsentFromBlocked = C.CqlInt 7 + toCql MissingLegalholdConsentFromPending = C.CqlInt 8 + toCql MissingLegalholdConsentFromIgnored = C.CqlInt 9 + toCql MissingLegalholdConsentFromSent = C.CqlInt 10 + toCql MissingLegalholdConsentFromCancelled = C.CqlInt 11 + ---------------- -- Requests diff --git a/libs/wire-api/src/Wire/API/MLS/CipherSuite.hs b/libs/wire-api/src/Wire/API/MLS/CipherSuite.hs index fc06a3d708f..f4e24df2989 100644 --- a/libs/wire-api/src/Wire/API/MLS/CipherSuite.hs +++ b/libs/wire-api/src/Wire/API/MLS/CipherSuite.hs @@ -41,6 +41,7 @@ module Wire.API.MLS.CipherSuite ) where +import Cassandra qualified as C import Cassandra.CQL import Control.Applicative import Control.Error (note) @@ -134,6 +135,16 @@ instance ToSchema CipherSuiteTag where pure (cipherSuiteTag (CipherSuite index)) +instance C.Cql CipherSuiteTag where + ctype = Tagged IntColumn + toCql = CqlInt . fromIntegral . cipherSuiteNumber . tagCipherSuite + + fromCql (CqlInt index) = + case cipherSuiteTag (CipherSuite (fromIntegral index)) of + Just t -> Right t + Nothing -> Left "CipherSuiteTag: unexpected index" + fromCql _ = Left "CipherSuiteTag: int expected" + -- | See https://messaginglayersecurity.rocks/mls-protocol/draft-ietf-mls-protocol.html#table-5. cipherSuiteTag :: CipherSuite -> Maybe CipherSuiteTag cipherSuiteTag cs = listToMaybe $ do diff --git a/libs/wire-api/src/Wire/API/Properties.hs b/libs/wire-api/src/Wire/API/Properties.hs index debcf9016d7..83c8ee1aa50 100644 --- a/libs/wire-api/src/Wire/API/Properties.hs +++ b/libs/wire-api/src/Wire/API/Properties.hs @@ -25,6 +25,7 @@ module Wire.API.Properties ) where +import Cassandra qualified as C import Control.Lens ((?~)) import Data.Aeson (FromJSON (..), ToJSON (..), Value) import Data.Aeson qualified as A @@ -67,9 +68,17 @@ instance S.ToParamSchema PropertyKey where & S.type_ ?~ S.OpenApiString & S.format ?~ "printable" +deriving instance C.Cql PropertyKey + -- | A raw, unparsed property value. newtype RawPropertyValue = RawPropertyValue {rawPropertyBytes :: LByteString} +instance C.Cql RawPropertyValue where + ctype = C.Tagged C.BlobColumn + toCql = C.toCql . C.Blob . rawPropertyBytes + fromCql (C.CqlBlob v) = pure (RawPropertyValue v) + fromCql _ = Left "PropertyValue: Blob expected" + instance {-# OVERLAPPING #-} MimeUnrender JSON RawPropertyValue where mimeUnrender _ = pure . RawPropertyValue diff --git a/libs/wire-api/src/Wire/API/User.hs b/libs/wire-api/src/Wire/API/User.hs index a55509da237..39e01c892ce 100644 --- a/libs/wire-api/src/Wire/API/User.hs +++ b/libs/wire-api/src/Wire/API/User.hs @@ -159,6 +159,7 @@ module Wire.API.User ) where +import Cassandra qualified as C import Control.Applicative import Control.Arrow ((&&&)) import Control.Error.Safe (rightMay) @@ -345,6 +346,8 @@ instance ToByteString PhonePrefix where instance FromHttpApiData PhonePrefix where parseUrlPiece = Bifunctor.first cs . phonePrefixParser +deriving instance C.Cql PhonePrefix + phonePrefixParser :: Text -> Either String PhonePrefix phonePrefixParser p = maybe err pure (parsePhonePrefix p) where @@ -1362,6 +1365,8 @@ instance FromHttpApiData InvitationCode where instance ToHttpApiData InvitationCode where toQueryParam = cs . toByteString . fromInvitationCode +deriving instance C.Cql InvitationCode + -------------------------------------------------------------------------------- -- NewTeamUser @@ -1862,6 +1867,24 @@ instance Schema.ToSchema AccountStatus where Schema.element "pending-invitation" PendingInvitation ] +instance C.Cql AccountStatus where + ctype = C.Tagged C.IntColumn + + toCql Active = C.CqlInt 0 + toCql Suspended = C.CqlInt 1 + toCql Deleted = C.CqlInt 2 + toCql Ephemeral = C.CqlInt 3 + toCql PendingInvitation = C.CqlInt 4 + + fromCql (C.CqlInt i) = case i of + 0 -> pure Active + 1 -> pure Suspended + 2 -> pure Deleted + 3 -> pure Ephemeral + 4 -> pure PendingInvitation + n -> Left $ "unexpected account status: " ++ show n + fromCql _ = Left "account status: int expected" + data AccountStatusResp = AccountStatusResp {fromAccountStatusResp :: AccountStatus} deriving (Eq, Show, Generic) deriving (Arbitrary) via (GenericUniform AccountStatusResp) @@ -2007,6 +2030,13 @@ data BaseProtocolTag = BaseProtocolProteusTag | BaseProtocolMLSTag deriving (Arbitrary) via (GenericUniform BaseProtocolTag) deriving (FromJSON, ToJSON, S.ToSchema) via (Schema BaseProtocolTag) +instance C.Cql (Imports.Set BaseProtocolTag) where + ctype = C.Tagged C.IntColumn + + toCql = C.CqlInt . fromIntegral . protocolSetBits + fromCql (C.CqlInt bits) = pure $ protocolSetFromBits (fromIntegral bits) + fromCql _ = Left "Protocol set: Int expected" + baseProtocolMask :: BaseProtocolTag -> Word32 baseProtocolMask BaseProtocolProteusTag = 1 baseProtocolMask BaseProtocolMLSTag = 2 diff --git a/libs/wire-api/src/Wire/API/User/Activation.hs b/libs/wire-api/src/Wire/API/User/Activation.hs index e14b30bc326..8998854b2e2 100644 --- a/libs/wire-api/src/Wire/API/User/Activation.hs +++ b/libs/wire-api/src/Wire/API/User/Activation.hs @@ -35,6 +35,7 @@ module Wire.API.User.Activation ) where +import Cassandra qualified as C import Control.Lens ((?~)) import Data.Aeson qualified as A import Data.Aeson.Types (Parser) @@ -82,6 +83,8 @@ instance ToParamSchema ActivationKey where instance FromHttpApiData ActivationKey where parseUrlPiece = fmap ActivationKey . parseUrlPiece +deriving instance C.Cql ActivationKey + -------------------------------------------------------------------------------- -- ActivationCode @@ -100,6 +103,8 @@ instance ToParamSchema ActivationCode where instance FromHttpApiData ActivationCode where parseQueryParam = fmap ActivationCode . parseUrlPiece +deriving instance C.Cql ActivationCode + -------------------------------------------------------------------------------- -- Activate diff --git a/libs/wire-api/src/Wire/API/User/Client.hs b/libs/wire-api/src/Wire/API/User/Client.hs index c26b7c5b9b0..ecdc20531bd 100644 --- a/libs/wire-api/src/Wire/API/User/Client.hs +++ b/libs/wire-api/src/Wire/API/User/Client.hs @@ -68,7 +68,7 @@ module Wire.API.User.Client ) where -import Cassandra qualified as Cql +import Cassandra qualified as C import Control.Applicative import Control.Lens hiding (element, enum, set, (#), (.=)) import Data.Aeson (FromJSON (..), ToJSON (..)) @@ -157,12 +157,12 @@ instance ToSchema ClientCapability where enum @Text "ClientCapability" $ element "legalhold-implicit-consent" ClientSupportsLegalholdImplicitConsent -instance Cql.Cql ClientCapability where - ctype = Cql.Tagged Cql.IntColumn +instance C.Cql ClientCapability where + ctype = C.Tagged C.IntColumn - toCql ClientSupportsLegalholdImplicitConsent = Cql.CqlInt 1 + toCql ClientSupportsLegalholdImplicitConsent = C.CqlInt 1 - fromCql (Cql.CqlInt i) = case i of + fromCql (C.CqlInt i) = case i of 1 -> pure ClientSupportsLegalholdImplicitConsent n -> Left $ "Unexpected ClientCapability value: " ++ show n fromCql _ = Left "ClientCapability value: int expected" @@ -614,6 +614,17 @@ instance ToSchema ClientType where <> element "permanent" PermanentClientType <> element "legalhold" LegalHoldClientType +instance C.Cql ClientType where + ctype = C.Tagged C.IntColumn + toCql TemporaryClientType = C.CqlInt 0 + toCql PermanentClientType = C.CqlInt 1 + toCql LegalHoldClientType = C.CqlInt 2 + + fromCql (C.CqlInt 0) = pure TemporaryClientType + fromCql (C.CqlInt 1) = pure PermanentClientType + fromCql (C.CqlInt 2) = pure LegalHoldClientType + fromCql _ = Left "ClientType: Int [0, 2] expected" + data ClientClass = PhoneClient | TabletClient @@ -631,6 +642,19 @@ instance ToSchema ClientClass where <> element "desktop" DesktopClient <> element "legalhold" LegalHoldClient +instance C.Cql ClientClass where + ctype = C.Tagged C.IntColumn + toCql PhoneClient = C.CqlInt 0 + toCql TabletClient = C.CqlInt 1 + toCql DesktopClient = C.CqlInt 2 + toCql LegalHoldClient = C.CqlInt 3 + + fromCql (C.CqlInt 0) = pure PhoneClient + fromCql (C.CqlInt 1) = pure TabletClient + fromCql (C.CqlInt 2) = pure DesktopClient + fromCql (C.CqlInt 3) = pure LegalHoldClient + fromCql _ = Left "ClientClass: Int [0, 3] expected" + -------------------------------------------------------------------------------- -- NewClient diff --git a/libs/wire-api/src/Wire/API/User/Identity.hs b/libs/wire-api/src/Wire/API/User/Identity.hs index 2b88c1d3bd8..0475554bfeb 100644 --- a/libs/wire-api/src/Wire/API/User/Identity.hs +++ b/libs/wire-api/src/Wire/API/User/Identity.hs @@ -52,6 +52,7 @@ module Wire.API.User.Identity ) where +import Cassandra qualified as C import Control.Applicative (optional) import Control.Lens (dimap, over, (.~), (?~), (^.)) import Data.Aeson (FromJSON (..), ToJSON (..)) @@ -199,6 +200,16 @@ instance Arbitrary Email where domain <- Text.filter (/= '@') <$> arbitrary pure $ Email localPart domain +instance C.Cql Email where + ctype = C.Tagged C.TextColumn + + fromCql (C.CqlText t) = case parseEmail t of + Just e -> pure e + Nothing -> Left "fromCql: Invalid email" + fromCql _ = Left "fromCql: email: CqlText expected" + + toCql = C.toCql . fromEmail + fromEmail :: Email -> Text fromEmail (Email loc dom) = loc <> "@" <> dom @@ -283,6 +294,8 @@ instance Arbitrary Phone where maxi <- mkdigits =<< QC.chooseInt (0, 7) pure $ '+' : mini <> maxi +deriving instance C.Cql Phone + -- | Parses a phone number in E.164 format with a mandatory leading '+'. parsePhone :: Text -> Maybe Phone parsePhone p @@ -315,6 +328,16 @@ data UserSSOId deriving stock (Eq, Show, Generic) deriving (Arbitrary) via (GenericUniform UserSSOId) +instance C.Cql UserSSOId where + ctype = C.Tagged C.TextColumn + + fromCql (C.CqlText t) = case A.eitherDecode $ cs t of + Right i -> pure i + Left msg -> Left $ "fromCql: Invalid UserSSOId: " ++ msg + fromCql _ = Left "fromCql: UserSSOId: CqlText expected" + + toCql = C.toCql . cs @LByteString @Text . A.encode + -- | FUTUREWORK: This schema should ideally be a choice of either tenant+subject, or scim_external_id -- but this is currently not possible to derive in swagger2 -- Maybe this becomes possible with swagger 3? diff --git a/libs/wire-api/src/Wire/API/User/Password.hs b/libs/wire-api/src/Wire/API/User/Password.hs index 4f14e4ca7c6..a4c3f92c2ae 100644 --- a/libs/wire-api/src/Wire/API/User/Password.hs +++ b/libs/wire-api/src/Wire/API/User/Password.hs @@ -31,6 +31,7 @@ module Wire.API.User.Password ) where +import Cassandra qualified as C import Control.Lens ((?~)) import Data.Aeson qualified as A import Data.Aeson.Types (Parser) @@ -180,6 +181,8 @@ instance ToParamSchema PasswordResetKey where instance FromHttpApiData PasswordResetKey where parseQueryParam = fmap PasswordResetKey . parseQueryParam +deriving instance C.Cql PasswordResetKey + -------------------------------------------------------------------------------- -- PasswordResetCode @@ -190,6 +193,8 @@ newtype PasswordResetCode = PasswordResetCode deriving newtype (ToSchema, FromByteString, ToByteString, A.FromJSON, A.ToJSON) deriving (Arbitrary) via (Ranged 6 1024 AsciiBase64Url) +deriving instance C.Cql PasswordResetCode + -------------------------------------------------------------------------------- -- DEPRECATED diff --git a/libs/wire-api/src/Wire/API/User/Profile.hs b/libs/wire-api/src/Wire/API/User/Profile.hs index ae018f20b75..dafefa4b4a1 100644 --- a/libs/wire-api/src/Wire/API/User/Profile.hs +++ b/libs/wire-api/src/Wire/API/User/Profile.hs @@ -49,6 +49,7 @@ module Wire.API.User.Profile ) where +import Cassandra qualified as C import Control.Applicative (optional) import Control.Error (hush, note) import Data.Aeson (FromJSON (..), ToJSON (..)) @@ -85,6 +86,8 @@ mkName txt = Name . fromRange <$> checkedEitherMsg @_ @1 @128 "Name" txt instance ToSchema Name where schema = Name <$> fromName .= untypedRangedSchema 1 128 schema +deriving instance C.Cql Name + -------------------------------------------------------------------------------- -- Colour @@ -96,6 +99,8 @@ newtype ColourId = ColourId {fromColourId :: Int32} defaultAccentId :: ColourId defaultAccentId = ColourId 0 +deriving instance C.Cql ColourId + -------------------------------------------------------------------------------- -- Asset @@ -121,6 +126,45 @@ instance ToSchema Asset where enum @Text @NamedSwaggerDoc "AssetType" $ element "image" () +instance C.Cql Asset where + -- Note: Type name and column names and types must match up with the + -- Cassandra schema definition. New fields may only be added + -- (appended) but no fields may be removed. + ctype = + C.Tagged + ( C.UdtColumn + "asset" + [ ("typ", C.IntColumn), + ("key", C.TextColumn), + ("size", C.MaybeColumn C.IntColumn) + ] + ) + + fromCql (C.CqlUdt fs) = do + t <- required "typ" + k <- required "key" + s <- notrequired "size" + case (t :: Int32) of + 0 -> pure $! ImageAsset k s + _ -> Left $ "unexpected user asset type: " ++ show t + where + required :: C.Cql r => Text -> Either String r + required f = + maybe + (Left ("Asset: Missing required field '" ++ show f ++ "'")) + C.fromCql + (lookup f fs) + notrequired f = maybe (Right Nothing) C.fromCql (lookup f fs) + fromCql _ = Left "UserAsset: UDT expected" + + -- Note: Order must match up with the 'ctype' definition. + toCql (ImageAsset k s) = + C.CqlUdt + [ ("typ", C.CqlInt 0), + ("key", C.toCql k), + ("size", C.toCql s) + ] + data AssetSize = AssetComplete | AssetPreview deriving stock (Eq, Show, Generic) deriving (Arbitrary) via (GenericUniform AssetSize) @@ -134,6 +178,16 @@ instance ToSchema AssetSize where element "complete" AssetComplete ] +instance C.Cql AssetSize where + ctype = C.Tagged C.IntColumn + + fromCql (C.CqlInt 0) = pure AssetPreview + fromCql (C.CqlInt 1) = pure AssetComplete + fromCql n = Left $ "Unexpected asset size: " ++ show n + + toCql AssetPreview = C.CqlInt 0 + toCql AssetComplete = C.CqlInt 1 + -------------------------------------------------------------------------------- -- Locale @@ -172,6 +226,15 @@ newtype Language = Language {fromLanguage :: ISO639_1} deriving stock (Eq, Ord, Show, Generic) deriving newtype (Arbitrary, S.ToSchema) +instance C.Cql Language where + ctype = C.Tagged C.AsciiColumn + toCql = C.toCql . lan2Text + + fromCql (C.CqlAscii l) = case parseLanguage l of + Just l' -> pure l' + Nothing -> Left "Language: ISO 639-1 expected." + fromCql _ = Left "Language: ASCII expected" + languageParser :: Parser Language languageParser = codeParser "language" $ fmap Language . checkAndConvert isLower @@ -188,6 +251,15 @@ newtype Country = Country {fromCountry :: CountryCode} deriving stock (Eq, Ord, Show, Generic) deriving newtype (Arbitrary, S.ToSchema) +instance C.Cql Country where + ctype = C.Tagged C.AsciiColumn + toCql = C.toCql . con2Text + + fromCql (C.CqlAscii c) = case parseCountry c of + Just c' -> pure c' + Nothing -> Left "Country: ISO 3166-1-alpha2 expected." + fromCql _ = Left "Country: ASCII expected" + countryParser :: Parser Country countryParser = codeParser "country" $ fmap Country . checkAndConvert isUpper @@ -243,6 +315,16 @@ instance FromByteString ManagedBy where "scim" -> pure ManagedByScim x -> fail $ "Invalid ManagedBy value: " <> show x +instance C.Cql ManagedBy where + ctype = C.Tagged C.IntColumn + + fromCql (C.CqlInt 0) = pure ManagedByWire + fromCql (C.CqlInt 1) = pure ManagedByScim + fromCql n = Left $ "Unexpected ManagedBy: " ++ show n + + toCql ManagedByWire = C.CqlInt 0 + toCql ManagedByScim = C.CqlInt 1 + defaultManagedBy :: ManagedBy defaultManagedBy = ManagedByWire @@ -262,6 +344,17 @@ instance ToSchema Pict where instance Arbitrary Pict where arbitrary = pure $ Pict [] +instance C.Cql Pict where + ctype = C.Tagged (C.ListColumn C.BlobColumn) + + fromCql (C.CqlList l) = do + vs <- map (\(C.Blob lbs) -> lbs) <$> mapM C.fromCql l + as <- mapM (note "Failed to read asset" . A.decode) vs + pure $ Pict as + fromCql _ = pure noPict + + toCql = C.toCql . map (C.Blob . A.encode) . fromPict + noPict :: Pict noPict = Pict [] diff --git a/libs/wire-api/src/Wire/API/User/RichInfo.hs b/libs/wire-api/src/Wire/API/User/RichInfo.hs index 32a3db8fa19..e6723b9d651 100644 --- a/libs/wire-api/src/Wire/API/User/RichInfo.hs +++ b/libs/wire-api/src/Wire/API/User/RichInfo.hs @@ -43,6 +43,7 @@ module Wire.API.User.RichInfo ) where +import Cassandra qualified as C import Control.Lens ((%~), (?~), _1) import Data.Aeson qualified as A import Data.Aeson.Key qualified as A @@ -319,6 +320,12 @@ instance Arbitrary RichInfoAssocList where arbitrary = mkRichInfoAssocList <$> arbitrary shrink (RichInfoAssocList things) = mkRichInfoAssocList <$> QC.shrink things +instance C.Cql RichInfoAssocList where + ctype = C.Tagged C.BlobColumn + toCql = C.toCql . C.Blob . A.encode + fromCql (C.CqlBlob v) = A.eitherDecode v + fromCql _ = Left "RichInfo: Blob expected" + -------------------------------------------------------------------------------- -- RichField diff --git a/libs/wire-api/src/Wire/API/User/Search.hs b/libs/wire-api/src/Wire/API/User/Search.hs index 375e1f07dc2..8b2fa6fb710 100644 --- a/libs/wire-api/src/Wire/API/User/Search.hs +++ b/libs/wire-api/src/Wire/API/User/Search.hs @@ -33,6 +33,7 @@ module Wire.API.User.Search ) where +import Cassandra qualified as C import Control.Error import Control.Lens (makePrisms, (?~)) import Data.Aeson hiding (object, (.=)) @@ -317,4 +318,16 @@ instance ToSchema FederatedUserSearchPolicy where <> element "exact_handle_search" ExactHandleSearch <> element "full_search" FullSearch +instance C.Cql FederatedUserSearchPolicy where + ctype = C.Tagged C.IntColumn + + toCql NoSearch = C.CqlInt 0 + toCql ExactHandleSearch = C.CqlInt 1 + toCql FullSearch = C.CqlInt 2 + + fromCql (C.CqlInt 0) = pure NoSearch + fromCql (C.CqlInt 1) = pure ExactHandleSearch + fromCql (C.CqlInt 2) = pure FullSearch + fromCql n = Left $ "Unexpected SearchVisibilityInbound: " ++ show n + makePrisms ''FederatedUserSearchPolicy diff --git a/services/brig/brig.cabal b/services/brig/brig.cabal index f24644d2d67..a57c21f5e6c 100644 --- a/services/brig/brig.cabal +++ b/services/brig/brig.cabal @@ -110,7 +110,6 @@ library Brig.Data.Activation Brig.Data.Client Brig.Data.Connection - Brig.Data.Instances Brig.Data.LoginCode Brig.Data.MLS.KeyPackage Brig.Data.Nonce diff --git a/services/brig/src/Brig/Data/Instances.hs b/services/brig/src/Brig/Data/Instances.hs deleted file mode 100644 index 34309315771..00000000000 --- a/services/brig/src/Brig/Data/Instances.hs +++ /dev/null @@ -1,319 +0,0 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} - --- This file is part of the Wire Server implementation. --- --- Copyright (C) 2022 Wire Swiss GmbH --- --- 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 . - -module Brig.Data.Instances - ( - ) -where - -import Brig.Types.Common -import Brig.Types.Search -import Cassandra.CQL -import Control.Error (note) -import Data.Aeson (eitherDecode, encode) -import Data.Aeson qualified as JSON -import Data.ByteString.Conversion -import Data.Domain (Domain, domainText, mkDomain) -import Data.Handle (Handle (..)) -import Data.Id () -import Data.Range () -import Data.Text.Ascii () -import Data.Text.Encoding (encodeUtf8) -import Imports -import Wire.API.Asset (AssetKey, assetKeyToText, nilAssetKey) -import Wire.API.Connection (RelationWithHistory (..)) -import Wire.API.MLS.CipherSuite -import Wire.API.Properties -import Wire.API.User -import Wire.API.User.Activation -import Wire.API.User.Client -import Wire.API.User.Password -import Wire.API.User.RichInfo -import Wire.API.User.Search - -deriving instance Cql Name - -deriving instance Cql Handle - -deriving instance Cql ColourId - -deriving instance Cql Phone - -deriving instance Cql InvitationCode - -deriving instance Cql PasswordResetKey - -deriving instance Cql PasswordResetCode - -deriving instance Cql ActivationKey - -deriving instance Cql ActivationCode - -deriving instance Cql PropertyKey - -deriving instance Cql PhonePrefix - -instance Cql Email where - ctype = Tagged TextColumn - - fromCql (CqlText t) = case parseEmail t of - Just e -> pure e - Nothing -> Left "fromCql: Invalid email" - fromCql _ = Left "fromCql: email: CqlText expected" - - toCql = toCql . fromEmail - -instance Cql UserSSOId where - ctype = Tagged TextColumn - - fromCql (CqlText t) = case eitherDecode $ cs t of - Right i -> pure i - Left msg -> Left $ "fromCql: Invalid UserSSOId: " ++ msg - fromCql _ = Left "fromCql: UserSSOId: CqlText expected" - - toCql = toCql . cs @LByteString @Text . encode - -instance Cql RelationWithHistory where - ctype = Tagged IntColumn - - fromCql (CqlInt i) = case i of - 0 -> pure AcceptedWithHistory - 1 -> pure BlockedWithHistory - 2 -> pure PendingWithHistory - 3 -> pure IgnoredWithHistory - 4 -> pure SentWithHistory - 5 -> pure CancelledWithHistory - 6 -> pure MissingLegalholdConsentFromAccepted - 7 -> pure MissingLegalholdConsentFromBlocked - 8 -> pure MissingLegalholdConsentFromPending - 9 -> pure MissingLegalholdConsentFromIgnored - 10 -> pure MissingLegalholdConsentFromSent - 11 -> pure MissingLegalholdConsentFromCancelled - n -> Left $ "unexpected RelationWithHistory: " ++ show n - fromCql _ = Left "RelationWithHistory: int expected" - - toCql AcceptedWithHistory = CqlInt 0 - toCql BlockedWithHistory = CqlInt 1 - toCql PendingWithHistory = CqlInt 2 - toCql IgnoredWithHistory = CqlInt 3 - toCql SentWithHistory = CqlInt 4 - toCql CancelledWithHistory = CqlInt 5 - toCql MissingLegalholdConsentFromAccepted = CqlInt 6 - toCql MissingLegalholdConsentFromBlocked = CqlInt 7 - toCql MissingLegalholdConsentFromPending = CqlInt 8 - toCql MissingLegalholdConsentFromIgnored = CqlInt 9 - toCql MissingLegalholdConsentFromSent = CqlInt 10 - toCql MissingLegalholdConsentFromCancelled = CqlInt 11 - --- DEPRECATED -instance Cql Pict where - ctype = Tagged (ListColumn BlobColumn) - - fromCql (CqlList l) = do - vs <- map (\(Blob lbs) -> lbs) <$> mapM fromCql l - as <- mapM (note "Failed to read asset" . JSON.decode) vs - pure $ Pict as - fromCql _ = pure noPict - - toCql = toCql . map (Blob . JSON.encode) . fromPict - -instance Cql AssetKey where - ctype = Tagged TextColumn - toCql = CqlText . assetKeyToText - - -- if the asset key is invalid we will return the nil asset key (`3-1-00000000-0000-0000-0000-000000000000`) - fromCql (CqlText txt) = pure $ fromRight nilAssetKey $ runParser parser $ encodeUtf8 txt - fromCql _ = Left "AssetKey: Expected CqlText" - -instance Cql AssetSize where - ctype = Tagged IntColumn - - fromCql (CqlInt 0) = pure AssetPreview - fromCql (CqlInt 1) = pure AssetComplete - fromCql n = Left $ "Unexpected asset size: " ++ show n - - toCql AssetPreview = CqlInt 0 - toCql AssetComplete = CqlInt 1 - -instance Cql Asset where - -- Note: Type name and column names and types must match up with the - -- Cassandra schema definition. New fields may only be added - -- (appended) but no fields may be removed. - ctype = - Tagged - ( UdtColumn - "asset" - [ ("typ", IntColumn), - ("key", TextColumn), - ("size", MaybeColumn IntColumn) - ] - ) - - fromCql (CqlUdt fs) = do - t <- required "typ" - k <- required "key" - s <- optional "size" - case (t :: Int32) of - 0 -> pure $! ImageAsset k s - _ -> Left $ "unexpected user asset type: " ++ show t - where - required :: Cql r => Text -> Either String r - required f = - maybe - (Left ("Asset: Missing required field '" ++ show f ++ "'")) - fromCql - (lookup f fs) - optional f = maybe (Right Nothing) fromCql (lookup f fs) - fromCql _ = Left "UserAsset: UDT expected" - - -- Note: Order must match up with the 'ctype' definition. - toCql (ImageAsset k s) = - CqlUdt - [ ("typ", CqlInt 0), - ("key", toCql k), - ("size", toCql s) - ] - -instance Cql AccountStatus where - ctype = Tagged IntColumn - - toCql Active = CqlInt 0 - toCql Suspended = CqlInt 1 - toCql Deleted = CqlInt 2 - toCql Ephemeral = CqlInt 3 - toCql PendingInvitation = CqlInt 4 - - fromCql (CqlInt i) = case i of - 0 -> pure Active - 1 -> pure Suspended - 2 -> pure Deleted - 3 -> pure Ephemeral - 4 -> pure PendingInvitation - n -> Left $ "unexpected account status: " ++ show n - fromCql _ = Left "account status: int expected" - -instance Cql ClientType where - ctype = Tagged IntColumn - toCql TemporaryClientType = CqlInt 0 - toCql PermanentClientType = CqlInt 1 - toCql LegalHoldClientType = CqlInt 2 - - fromCql (CqlInt 0) = pure TemporaryClientType - fromCql (CqlInt 1) = pure PermanentClientType - fromCql (CqlInt 2) = pure LegalHoldClientType - fromCql _ = Left "ClientType: Int [0, 2] expected" - -instance Cql ClientClass where - ctype = Tagged IntColumn - toCql PhoneClient = CqlInt 0 - toCql TabletClient = CqlInt 1 - toCql DesktopClient = CqlInt 2 - toCql LegalHoldClient = CqlInt 3 - - fromCql (CqlInt 0) = pure PhoneClient - fromCql (CqlInt 1) = pure TabletClient - fromCql (CqlInt 2) = pure DesktopClient - fromCql (CqlInt 3) = pure LegalHoldClient - fromCql _ = Left "ClientClass: Int [0, 3] expected" - -instance Cql RawPropertyValue where - ctype = Tagged BlobColumn - toCql = toCql . Blob . rawPropertyBytes - fromCql (CqlBlob v) = pure (RawPropertyValue v) - fromCql _ = Left "PropertyValue: Blob expected" - -instance Cql Country where - ctype = Tagged AsciiColumn - toCql = toCql . con2Text - - fromCql (CqlAscii c) = case parseCountry c of - Just c' -> pure c' - Nothing -> Left "Country: ISO 3166-1-alpha2 expected." - fromCql _ = Left "Country: ASCII expected" - -instance Cql Language where - ctype = Tagged AsciiColumn - toCql = toCql . lan2Text - - fromCql (CqlAscii l) = case parseLanguage l of - Just l' -> pure l' - Nothing -> Left "Language: ISO 639-1 expected." - fromCql _ = Left "Language: ASCII expected" - -instance Cql ManagedBy where - ctype = Tagged IntColumn - - fromCql (CqlInt 0) = pure ManagedByWire - fromCql (CqlInt 1) = pure ManagedByScim - fromCql n = Left $ "Unexpected ManagedBy: " ++ show n - - toCql ManagedByWire = CqlInt 0 - toCql ManagedByScim = CqlInt 1 - -instance Cql RichInfoAssocList where - ctype = Tagged BlobColumn - toCql = toCql . Blob . JSON.encode - fromCql (CqlBlob v) = JSON.eitherDecode v - fromCql _ = Left "RichInfo: Blob expected" - -instance Cql Domain where - ctype = Tagged TextColumn - toCql = CqlText . domainText - fromCql (CqlText txt) = mkDomain txt - fromCql _ = Left "Domain: Text expected" - -instance Cql SearchVisibilityInbound where - ctype = Tagged IntColumn - - toCql SearchableByOwnTeam = CqlInt 0 - toCql SearchableByAllTeams = CqlInt 1 - - fromCql (CqlInt 0) = pure SearchableByOwnTeam - fromCql (CqlInt 1) = pure SearchableByAllTeams - fromCql n = Left $ "Unexpected SearchVisibilityInbound: " ++ show n - -instance Cql FederatedUserSearchPolicy where - ctype = Tagged IntColumn - - toCql NoSearch = CqlInt 0 - toCql ExactHandleSearch = CqlInt 1 - toCql FullSearch = CqlInt 2 - - fromCql (CqlInt 0) = pure NoSearch - fromCql (CqlInt 1) = pure ExactHandleSearch - fromCql (CqlInt 2) = pure FullSearch - fromCql n = Left $ "Unexpected SearchVisibilityInbound: " ++ show n - -instance Cql (Imports.Set BaseProtocolTag) where - ctype = Tagged IntColumn - - toCql = CqlInt . fromIntegral . protocolSetBits - fromCql (CqlInt bits) = pure $ protocolSetFromBits (fromIntegral bits) - fromCql _ = Left "Protocol set: Int expected" - -instance Cql CipherSuiteTag where - ctype = Tagged IntColumn - toCql = CqlInt . fromIntegral . cipherSuiteNumber . tagCipherSuite - - fromCql (CqlInt index) = - case cipherSuiteTag (CipherSuite (fromIntegral index)) of - Just tag -> Right tag - Nothing -> Left "CipherSuiteTag: unexpected index" - fromCql _ = Left "CipherSuiteTag: int expected" diff --git a/services/galley/src/Galley/Cassandra/Instances.hs b/services/galley/src/Galley/Cassandra/Instances.hs index 7e9c9f43406..ebb93e58d0d 100644 --- a/services/galley/src/Galley/Cassandra/Instances.hs +++ b/services/galley/src/Galley/Cassandra/Instances.hs @@ -164,12 +164,6 @@ instance Cql TeamSearchVisibility where toCql SearchVisibilityStandard = CqlInt 0 toCql SearchVisibilityNoNameOutsideTeam = CqlInt 1 -instance Cql Domain where - ctype = Tagged TextColumn - toCql = CqlText . domainText - fromCql (CqlText txt) = mkDomain txt - fromCql _ = Left "Domain: Text expected" - instance Cql Public.EnforceAppLock where ctype = Tagged IntColumn toCql (Public.EnforceAppLock False) = CqlInt 0 @@ -214,7 +208,7 @@ instance Cql Icon where fromCql (CqlText txt) = pure . fromRight DefaultIcon . runParser parser . T.encodeUtf8 $ txt fromCql _ = Left "Icon: Text expected" -instance Cql AssetKey where +instance Cql AssetKey where -- TODO: brig has a different instance (catches left and returns a null asset key). this is probably bad and should be stream-lined / fixed? ctype = Tagged TextColumn toCql = CqlText . assetKeyToText fromCql (CqlText txt) = runParser parser . T.encodeUtf8 $ txt diff --git a/tools/db/auto-whitelist/auto-whitelist.cabal b/tools/db/auto-whitelist/auto-whitelist.cabal index f62ee357952..09239aa43c9 100644 --- a/tools/db/auto-whitelist/auto-whitelist.cabal +++ b/tools/db/auto-whitelist/auto-whitelist.cabal @@ -75,6 +75,5 @@ executable auto-whitelist , tinylog , types-common , unliftio - , wire-api default-language: GHC2021 diff --git a/tools/db/auto-whitelist/src/Work.hs b/tools/db/auto-whitelist/src/Work.hs index 709ab1f4b9b..0bec1ccd169 100644 --- a/tools/db/auto-whitelist/src/Work.hs +++ b/tools/db/auto-whitelist/src/Work.hs @@ -33,9 +33,6 @@ import Imports import System.Logger (Logger) import System.Logger qualified as Log import UnliftIO.Async (pooledMapConcurrentlyN_) -import Wire.API.User - -deriving instance Cql Name runCommand :: Logger -> ClientState -> IO () runCommand l brig = runClient brig $ do diff --git a/tools/db/find-undead/src/Work.hs b/tools/db/find-undead/src/Work.hs index 64192cea6d8..4803e7dfb24 100644 --- a/tools/db/find-undead/src/Work.hs +++ b/tools/db/find-undead/src/Work.hs @@ -123,23 +123,3 @@ data WorkError instance Exception WorkError type Name = Text - --- FUTUREWORK: you can avoid this by loading brig-the-service as a library: --- @"services/brig/src/Brig/Data/Instances.hs:165:instance Cql AccountStatus where"@ -instance Cql AccountStatus where - ctype = Tagged IntColumn - - toCql Active = CqlInt 0 - toCql Suspended = CqlInt 1 - toCql Deleted = CqlInt 2 - toCql Ephemeral = CqlInt 3 - toCql PendingInvitation = CqlInt 4 - - fromCql (CqlInt i) = case i of - 0 -> pure Active - 1 -> pure Suspended - 2 -> pure Deleted - 3 -> pure Ephemeral - 4 -> pure PendingInvitation - n -> Left $ "unexpected account status: " ++ show n - fromCql _ = Left "account status: int expected" diff --git a/tools/db/migrate-sso-feature-flag/migrate-sso-feature-flag.cabal b/tools/db/migrate-sso-feature-flag/migrate-sso-feature-flag.cabal index aca192a3aa1..f95439b9596 100644 --- a/tools/db/migrate-sso-feature-flag/migrate-sso-feature-flag.cabal +++ b/tools/db/migrate-sso-feature-flag/migrate-sso-feature-flag.cabal @@ -78,6 +78,5 @@ executable migrate-sso-feature-flag , tinylog , types-common , unliftio - , wire-api default-language: GHC2021 diff --git a/tools/db/migrate-sso-feature-flag/src/Work.hs b/tools/db/migrate-sso-feature-flag/src/Work.hs index d64570ce438..d8c20a64672 100644 --- a/tools/db/migrate-sso-feature-flag/src/Work.hs +++ b/tools/db/migrate-sso-feature-flag/src/Work.hs @@ -35,9 +35,6 @@ import System.Logger (Logger) import System.Logger qualified as Log import UnliftIO.Async (pooledMapConcurrentlyN) import Wire.API.Team.Feature -import Wire.API.User - -deriving instance Cql Name runCommand :: Logger -> ClientState -> ClientState -> IO () runCommand l spar galley = do diff --git a/tools/db/move-team/src/Work.hs b/tools/db/move-team/src/Work.hs index 0472b082790..87de720d3a2 100644 --- a/tools/db/move-team/src/Work.hs +++ b/tools/db/move-team/src/Work.hs @@ -46,9 +46,6 @@ import System.IO qualified as IO import System.Logger qualified as Log import System.Process (system) import Types -import Wire.API.User - -deriving instance Cql Name assertTargetDirEmpty :: Env -> IO () assertTargetDirEmpty Env {..} = do diff --git a/tools/db/service-backfill/service-backfill.cabal b/tools/db/service-backfill/service-backfill.cabal index e725bbb75d3..c6806e06a39 100644 --- a/tools/db/service-backfill/service-backfill.cabal +++ b/tools/db/service-backfill/service-backfill.cabal @@ -75,6 +75,5 @@ executable service-backfill , tinylog , types-common , unliftio - , wire-api default-language: GHC2021 diff --git a/tools/db/service-backfill/src/Work.hs b/tools/db/service-backfill/src/Work.hs index 5846a8e9733..f3229dd0fc4 100644 --- a/tools/db/service-backfill/src/Work.hs +++ b/tools/db/service-backfill/src/Work.hs @@ -32,9 +32,6 @@ import Imports import System.Logger (Logger) import System.Logger qualified as Log import UnliftIO.Async (pooledMapConcurrentlyN) -import Wire.API.User - -deriving instance Cql Name runCommand :: Logger -> ClientState -> ClientState -> IO () runCommand l brig galley = diff --git a/tools/mlsstats/src/MlsStats/Run.hs b/tools/mlsstats/src/MlsStats/Run.hs index 211933295b2..803ea8a7bb5 100644 --- a/tools/mlsstats/src/MlsStats/Run.hs +++ b/tools/mlsstats/src/MlsStats/Run.hs @@ -249,9 +249,3 @@ instance Cql GroupId where fromCql (CqlBlob b) = Right . GroupId . LBS.toStrict $ b fromCql _ = Left "group_id: blob expected" - -instance Cql Domain where - ctype = Tagged TextColumn - toCql = CqlText . domainText - fromCql (CqlText txt) = mkDomain txt - fromCql _ = Left "Domain: Text expected" From 21527abde7dc34c4643da247e4d94c99f39d29ee Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Wed, 17 Apr 2024 10:08:57 +0200 Subject: [PATCH 2/7] Remove dead references to import Brig.Data.Instances --- services/brig/src/Brig/Code.hs | 1 - services/brig/src/Brig/Data/Client.hs | 1 - services/brig/src/Brig/Data/Connection.hs | 1 - services/brig/src/Brig/Data/LoginCode.hs | 1 - services/brig/src/Brig/Data/Nonce.hs | 1 - services/brig/src/Brig/Data/Properties.hs | 1 - services/brig/src/Brig/Data/User.hs | 1 - services/brig/src/Brig/Data/UserKey.hs | 1 - services/brig/src/Brig/Effects/CodeStore/Cassandra.hs | 1 - .../brig/src/Brig/Effects/FederationConfigStore/Cassandra.hs | 1 - services/brig/src/Brig/Provider/DB.hs | 1 - services/brig/src/Brig/Team/DB.hs | 1 - services/brig/src/Brig/Unique.hs | 1 - services/brig/src/Brig/User/Handle.hs | 1 - services/brig/src/Brig/User/Search/Index.hs | 1 - services/brig/src/Brig/User/Search/SearchIndex.hs | 1 - services/brig/src/Brig/User/Search/TeamSize.hs | 1 - services/brig/src/Brig/User/Search/TeamUserSearch.hs | 1 - tools/db/inconsistencies/src/DanglingHandles.hs | 1 - tools/db/inconsistencies/src/DanglingUserKeys.hs | 1 - tools/db/inconsistencies/src/EmailLessUsers.hs | 1 - tools/db/inconsistencies/src/HandleLessUsers.hs | 1 - tools/db/repair-handles/src/Options.hs | 1 - tools/db/repair-handles/src/Types.hs | 1 - tools/db/repair-handles/src/Work.hs | 1 - 25 files changed, 25 deletions(-) diff --git a/services/brig/src/Brig/Code.hs b/services/brig/src/Brig/Code.hs index 7840b8e3cb5..2ea506aa5e7 100644 --- a/services/brig/src/Brig/Code.hs +++ b/services/brig/src/Brig/Code.hs @@ -60,7 +60,6 @@ module Brig.Code ) where -import Brig.Data.Instances () import Brig.Email (emailKeyUniq, mkEmailKey) import Brig.Phone (mkPhoneKey, phoneKeyUniq) import Cassandra hiding (Value) diff --git a/services/brig/src/Brig/Data/Client.hs b/services/brig/src/Brig/Data/Client.hs index 9b864391503..69e9ac0b829 100644 --- a/services/brig/src/Brig/Data/Client.hs +++ b/services/brig/src/Brig/Data/Client.hs @@ -56,7 +56,6 @@ import Amazonka.DynamoDB.Lens qualified as AWS import Bilge.Retry (httpHandlers) import Brig.AWS import Brig.App -import Brig.Data.Instances () import Brig.Data.User (AuthError (..), ReAuthError (..)) import Brig.Data.User qualified as User import Brig.Types.Instances () diff --git a/services/brig/src/Brig/Data/Connection.hs b/services/brig/src/Brig/Data/Connection.hs index b624a7d9447..ec46f3fe406 100644 --- a/services/brig/src/Brig/Data/Connection.hs +++ b/services/brig/src/Brig/Data/Connection.hs @@ -52,7 +52,6 @@ module Brig.Data.Connection where import Brig.App -import Brig.Data.Instances () import Brig.Data.Types as T import Cassandra import Control.Monad.Morph diff --git a/services/brig/src/Brig/Data/LoginCode.hs b/services/brig/src/Brig/Data/LoginCode.hs index 197d28aa8d8..1f58dba7cc7 100644 --- a/services/brig/src/Brig/Data/LoginCode.hs +++ b/services/brig/src/Brig/Data/LoginCode.hs @@ -27,7 +27,6 @@ module Brig.Data.LoginCode where import Brig.App (Env, currentTime) -import Brig.Data.Instances () import Brig.User.Auth.DB.Instances () import Cassandra import Control.Lens (view) diff --git a/services/brig/src/Brig/Data/Nonce.hs b/services/brig/src/Brig/Data/Nonce.hs index 83f11d1b78f..8ca18fd1a53 100644 --- a/services/brig/src/Brig/Data/Nonce.hs +++ b/services/brig/src/Brig/Data/Nonce.hs @@ -21,7 +21,6 @@ module Brig.Data.Nonce ) where -import Brig.Data.Instances () import Cassandra import Control.Lens hiding (from) import Data.Id (UserId) diff --git a/services/brig/src/Brig/Data/Properties.hs b/services/brig/src/Brig/Data/Properties.hs index 4519fe9d3ad..b073394584f 100644 --- a/services/brig/src/Brig/Data/Properties.hs +++ b/services/brig/src/Brig/Data/Properties.hs @@ -26,7 +26,6 @@ module Brig.Data.Properties ) where -import Brig.Data.Instances () import Cassandra import Control.Error import Data.Id diff --git a/services/brig/src/Brig/Data/User.hs b/services/brig/src/Brig/Data/User.hs index 053e472a997..5eb86970276 100644 --- a/services/brig/src/Brig/Data/User.hs +++ b/services/brig/src/Brig/Data/User.hs @@ -76,7 +76,6 @@ module Brig.Data.User where import Brig.App (Env, currentTime, settings, viewFederationDomain, zauthEnv) -import Brig.Data.Instances () import Brig.Options import Brig.Types.Intra import Brig.ZAuth qualified as ZAuth diff --git a/services/brig/src/Brig/Data/UserKey.hs b/services/brig/src/Brig/Data/UserKey.hs index 6487a77e730..11128014a24 100644 --- a/services/brig/src/Brig/Data/UserKey.hs +++ b/services/brig/src/Brig/Data/UserKey.hs @@ -33,7 +33,6 @@ module Brig.Data.UserKey ) where -import Brig.Data.Instances () import Brig.Data.User qualified as User import Brig.Email import Brig.Phone diff --git a/services/brig/src/Brig/Effects/CodeStore/Cassandra.hs b/services/brig/src/Brig/Effects/CodeStore/Cassandra.hs index e6cae090996..26d4d2c7f32 100644 --- a/services/brig/src/Brig/Effects/CodeStore/Cassandra.hs +++ b/services/brig/src/Brig/Effects/CodeStore/Cassandra.hs @@ -22,7 +22,6 @@ module Brig.Effects.CodeStore.Cassandra ) where -import Brig.Data.Instances () import Brig.Effects.CodeStore import Cassandra import Data.ByteString.Conversion (toByteString') diff --git a/services/brig/src/Brig/Effects/FederationConfigStore/Cassandra.hs b/services/brig/src/Brig/Effects/FederationConfigStore/Cassandra.hs index 0d348dd4e3b..bc9fcd8f7b6 100644 --- a/services/brig/src/Brig/Effects/FederationConfigStore/Cassandra.hs +++ b/services/brig/src/Brig/Effects/FederationConfigStore/Cassandra.hs @@ -22,7 +22,6 @@ module Brig.Effects.FederationConfigStore.Cassandra ) where -import Brig.Data.Instances () import Brig.Effects.FederationConfigStore import Cassandra import Control.Exception (ErrorCall (ErrorCall)) diff --git a/services/brig/src/Brig/Provider/DB.hs b/services/brig/src/Brig/Provider/DB.hs index e83919f5bb0..77aefc29ea5 100644 --- a/services/brig/src/Brig/Provider/DB.hs +++ b/services/brig/src/Brig/Provider/DB.hs @@ -17,7 +17,6 @@ module Brig.Provider.DB where -import Brig.Data.Instances () import Brig.Email (EmailKey, emailKeyOrig, emailKeyUniq) import Brig.Types.Instances () import Brig.Types.Provider.Tag diff --git a/services/brig/src/Brig/Team/DB.hs b/services/brig/src/Brig/Team/DB.hs index fb62d5edf69..97db9efcded 100644 --- a/services/brig/src/Brig/Team/DB.hs +++ b/services/brig/src/Brig/Team/DB.hs @@ -38,7 +38,6 @@ module Brig.Team.DB where import Brig.App as App -import Brig.Data.Instances () import Brig.Data.Types as T import Brig.Options import Brig.Team.Template diff --git a/services/brig/src/Brig/Unique.hs b/services/brig/src/Brig/Unique.hs index 6c5d5f0a2a8..58c95630a8a 100644 --- a/services/brig/src/Brig/Unique.hs +++ b/services/brig/src/Brig/Unique.hs @@ -29,7 +29,6 @@ module Brig.Unique ) where -import Brig.Data.Instances () import Cassandra as C import Control.Concurrent.Timeout import Data.Id diff --git a/services/brig/src/Brig/User/Handle.hs b/services/brig/src/Brig/User/Handle.hs index 4335f76b4c2..fd62c770c3c 100644 --- a/services/brig/src/Brig/User/Handle.hs +++ b/services/brig/src/Brig/User/Handle.hs @@ -26,7 +26,6 @@ where import Brig.App import Brig.CanonicalInterpreter (runBrigToIO) -import Brig.Data.Instances () import Brig.Data.User qualified as User import Brig.Unique import Cassandra diff --git a/services/brig/src/Brig/User/Search/Index.hs b/services/brig/src/Brig/User/Search/Index.hs index 4428d8bdeed..b3a0b0834e5 100644 --- a/services/brig/src/Brig/User/Search/Index.hs +++ b/services/brig/src/Brig/User/Search/Index.hs @@ -56,7 +56,6 @@ import Bilge.RPC (RPCException (RPCException)) import Bilge.Request qualified as RPC (empty, host, method, port) import Bilge.Response (responseJsonThrow) import Bilge.Retry (rpcHandlers) -import Brig.Data.Instances () import Brig.Index.Types (CreateIndexSettings (..)) import Brig.Types.Search (SearchVisibilityInbound, defaultSearchVisibilityInbound, searchVisibilityInboundFromFeatureStatus) import Brig.User.Search.Index.Types as Types diff --git a/services/brig/src/Brig/User/Search/SearchIndex.hs b/services/brig/src/Brig/User/Search/SearchIndex.hs index b70fcf3deb3..d9803fff6b5 100644 --- a/services/brig/src/Brig/User/Search/SearchIndex.hs +++ b/services/brig/src/Brig/User/Search/SearchIndex.hs @@ -25,7 +25,6 @@ module Brig.User.Search.SearchIndex where import Brig.App (Env, viewFederationDomain) -import Brig.Data.Instances () import Brig.Types.Search import Brig.User.Search.Index import Control.Lens hiding (setting, (#), (.=)) diff --git a/services/brig/src/Brig/User/Search/TeamSize.hs b/services/brig/src/Brig/User/Search/TeamSize.hs index fa13b843bf4..1fd23bbf1c3 100644 --- a/services/brig/src/Brig/User/Search/TeamSize.hs +++ b/services/brig/src/Brig/User/Search/TeamSize.hs @@ -22,7 +22,6 @@ module Brig.User.Search.TeamSize ) where -import Brig.Data.Instances () import Brig.Types.Team (TeamSize (..)) import Brig.User.Search.Index import Control.Monad.Catch (throwM) diff --git a/services/brig/src/Brig/User/Search/TeamUserSearch.hs b/services/brig/src/Brig/User/Search/TeamUserSearch.hs index 1b60532c063..9722be1ad74 100644 --- a/services/brig/src/Brig/User/Search/TeamUserSearch.hs +++ b/services/brig/src/Brig/User/Search/TeamUserSearch.hs @@ -29,7 +29,6 @@ module Brig.User.Search.TeamUserSearch ) where -import Brig.Data.Instances () import Brig.User.Search.Index import Control.Error (lastMay) import Control.Monad.Catch (MonadThrow (throwM)) diff --git a/tools/db/inconsistencies/src/DanglingHandles.hs b/tools/db/inconsistencies/src/DanglingHandles.hs index d8bee670266..cd0bf2b178a 100644 --- a/tools/db/inconsistencies/src/DanglingHandles.hs +++ b/tools/db/inconsistencies/src/DanglingHandles.hs @@ -21,7 +21,6 @@ module DanglingHandles where -import Brig.Data.Instances () import Cassandra import Cassandra.Util import Conduit diff --git a/tools/db/inconsistencies/src/DanglingUserKeys.hs b/tools/db/inconsistencies/src/DanglingUserKeys.hs index 7d04d8348f3..0bf093984dc 100644 --- a/tools/db/inconsistencies/src/DanglingUserKeys.hs +++ b/tools/db/inconsistencies/src/DanglingUserKeys.hs @@ -22,7 +22,6 @@ module DanglingUserKeys where -import Brig.Data.Instances () import Brig.Data.UserKey import Brig.Email (EmailKey (..), mkEmailKey) import Brig.Phone (PhoneKey (..), mkPhoneKey) diff --git a/tools/db/inconsistencies/src/EmailLessUsers.hs b/tools/db/inconsistencies/src/EmailLessUsers.hs index 5ac4cb87389..e1193952194 100644 --- a/tools/db/inconsistencies/src/EmailLessUsers.hs +++ b/tools/db/inconsistencies/src/EmailLessUsers.hs @@ -21,7 +21,6 @@ module EmailLessUsers where -import Brig.Data.Instances () import Brig.Data.UserKey import Brig.Email import Cassandra diff --git a/tools/db/inconsistencies/src/HandleLessUsers.hs b/tools/db/inconsistencies/src/HandleLessUsers.hs index 21901ed02e8..2a6324a3a1d 100644 --- a/tools/db/inconsistencies/src/HandleLessUsers.hs +++ b/tools/db/inconsistencies/src/HandleLessUsers.hs @@ -21,7 +21,6 @@ module HandleLessUsers where -import Brig.Data.Instances () import Cassandra import Cassandra.Util import Conduit diff --git a/tools/db/repair-handles/src/Options.hs b/tools/db/repair-handles/src/Options.hs index 74a4761822b..ba506f8da51 100644 --- a/tools/db/repair-handles/src/Options.hs +++ b/tools/db/repair-handles/src/Options.hs @@ -17,7 +17,6 @@ module Options where -import Brig.Data.Instances () import Cassandra hiding (Set) import Data.Id import Data.UUID diff --git a/tools/db/repair-handles/src/Types.hs b/tools/db/repair-handles/src/Types.hs index 75e64fc272a..7409d1647ec 100644 --- a/tools/db/repair-handles/src/Types.hs +++ b/tools/db/repair-handles/src/Types.hs @@ -19,7 +19,6 @@ module Types where -import Brig.Data.Instances () import Cassandra hiding (Set) import Control.Lens import Data.Id diff --git a/tools/db/repair-handles/src/Work.hs b/tools/db/repair-handles/src/Work.hs index 313c4021179..7d7fcdbde73 100644 --- a/tools/db/repair-handles/src/Work.hs +++ b/tools/db/repair-handles/src/Work.hs @@ -19,7 +19,6 @@ module Work where -import Brig.Data.Instances () import Cassandra hiding (Set) import Cassandra qualified as Cas import Cassandra.Settings qualified as Cas From dface169ad7b0dfaf88002f0e5449b28685ba7fe Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Wed, 17 Apr 2024 10:21:09 +0200 Subject: [PATCH 3/7] Re/moved more orphan instances. --- libs/types-common/src/Data/Handle.hs | 4 +-- libs/wire-api/src/Wire/API/Asset.hs | 19 +++++++------- .../galley/src/Galley/Cassandra/Instances.hs | 25 ++++++------------- .../migrate-sso-feature-flag.cabal | 1 + tools/db/move-team/src/Types.hs | 6 ----- 5 files changed, 21 insertions(+), 34 deletions(-) diff --git a/libs/types-common/src/Data/Handle.hs b/libs/types-common/src/Data/Handle.hs index 56d61f5165a..59854e89ec8 100644 --- a/libs/types-common/src/Data/Handle.hs +++ b/libs/types-common/src/Data/Handle.hs @@ -51,6 +51,8 @@ newtype Handle = Handle deriving newtype (ToByteString, Hashable, S.ToParamSchema) deriving (FromJSON, ToJSON, S.ToSchema) via Schema Handle +deriving instance C.Cql Handle + instance ToSchema Handle where schema = fromHandle .= parsedText "Handle" p where @@ -66,8 +68,6 @@ instance ToHttpApiData Handle where instance FromByteString Handle where parser = handleParser -deriving instance C.Cql Handle - parseHandle :: Text -> Maybe Handle parseHandle = either (const Nothing) Just . parseHandleEither diff --git a/libs/wire-api/src/Wire/API/Asset.hs b/libs/wire-api/src/Wire/API/Asset.hs index 784f0081070..a37d6efd474 100644 --- a/libs/wire-api/src/Wire/API/Asset.hs +++ b/libs/wire-api/src/Wire/API/Asset.hs @@ -31,7 +31,6 @@ module Wire.API.Asset -- * AssetKey AssetKey (..), assetKeyToText, - nilAssetKey, -- * AssetToken AssetToken (..), @@ -187,16 +186,18 @@ instance S.ToParamSchema AssetKey where instance FromHttpApiData AssetKey where parseUrlPiece = first T.pack . runParser parser . T.encodeUtf8 -nilAssetKey :: AssetKey -nilAssetKey = AssetKeyV3 (Id UUID.nil) AssetVolatile - -instance C.Cql AssetKey where +instance C.Cql AssetKey where ctype = C.Tagged C.TextColumn toCql = C.CqlText . assetKeyToText - - -- if the asset key is invalid we will return the nil asset key (`3-1-00000000-0000-0000-0000-000000000000`) - fromCql (C.CqlText txt) = pure $ fromRight nilAssetKey $ runParser parser $ T.encodeUtf8 txt - fromCql _ = Left "AssetKey: Expected CqlText" + fromCql (C.CqlText txt) = runParser parser . T.encodeUtf8 $ txt + fromCql _ = Left "AssetKey: Text expected" +-- instance C.Cql AssetKey where +-- ctype = C.Tagged C.TextColumn +-- toCql = C.CqlText . assetKeyToText +-- +-- -- if the asset key is invalid we will return the nil asset key (`3-1-00000000-0000-0000-0000-000000000000`) +-- fromCql (C.CqlText txt) = pure $ fromRight nilAssetKey $ runParser parser $ T.encodeUtf8 txt +-- fromCql _ = Left "AssetKey: Expected CqlText" -------------------------------------------------------------------------------- -- AssetToken diff --git a/services/galley/src/Galley/Cassandra/Instances.hs b/services/galley/src/Galley/Cassandra/Instances.hs index ebb93e58d0d..9e6910ca1d6 100644 --- a/services/galley/src/Galley/Cassandra/Instances.hs +++ b/services/galley/src/Galley/Cassandra/Instances.hs @@ -27,13 +27,11 @@ import Cassandra.CQL import Control.Error (note) import Data.ByteString.Conversion import Data.ByteString.Lazy qualified as LBS -import Data.Domain (Domain, domainText, mkDomain) import Data.Either.Combinators hiding (fromRight) import Data.Text qualified as T import Data.Text.Encoding qualified as T import Galley.Types.Bot () import Imports -import Wire.API.Asset (AssetKey, assetKeyToText) import Wire.API.Conversation import Wire.API.Conversation.Protocol import Wire.API.MLS.CipherSuite @@ -208,11 +206,14 @@ instance Cql Icon where fromCql (CqlText txt) = pure . fromRight DefaultIcon . runParser parser . T.encodeUtf8 $ txt fromCql _ = Left "Icon: Text expected" -instance Cql AssetKey where -- TODO: brig has a different instance (catches left and returns a null asset key). this is probably bad and should be stream-lined / fixed? - ctype = Tagged TextColumn - toCql = CqlText . assetKeyToText - fromCql (CqlText txt) = runParser parser . T.encodeUtf8 $ txt - fromCql _ = Left "AssetKey: Text expected" +-- TODO: brig has a different instance (catches left and returns +-- a null asset key). this is probably bad and should +-- be stream-lined / fixed? +-- instance Cql AssetKey where +-- ctype = Tagged TextColumn +-- toCql = CqlText . assetKeyToText +-- fromCql (CqlText txt) = runParser parser . T.encodeUtf8 $ txt +-- fromCql _ = Left "AssetKey: Text expected" instance Cql Epoch where ctype = Tagged BigIntColumn @@ -220,16 +221,6 @@ instance Cql Epoch where fromCql (CqlBigInt n) = pure (Epoch (fromIntegral n)) fromCql _ = Left "epoch: bigint expected" -instance Cql CipherSuiteTag where - ctype = Tagged IntColumn - toCql = CqlInt . fromIntegral . cipherSuiteNumber . tagCipherSuite - - fromCql (CqlInt index) = - case cipherSuiteTag (CipherSuite (fromIntegral index)) of - Just tag -> Right tag - Nothing -> Left "CipherSuiteTag: unexpected index" - fromCql _ = Left "CipherSuiteTag: int expected" - instance Cql ProposalRef where ctype = Tagged BlobColumn toCql = CqlBlob . LBS.fromStrict . unProposalRef diff --git a/tools/db/migrate-sso-feature-flag/migrate-sso-feature-flag.cabal b/tools/db/migrate-sso-feature-flag/migrate-sso-feature-flag.cabal index f95439b9596..aca192a3aa1 100644 --- a/tools/db/migrate-sso-feature-flag/migrate-sso-feature-flag.cabal +++ b/tools/db/migrate-sso-feature-flag/migrate-sso-feature-flag.cabal @@ -78,5 +78,6 @@ executable migrate-sso-feature-flag , tinylog , types-common , unliftio + , wire-api default-language: GHC2021 diff --git a/tools/db/move-team/src/Types.hs b/tools/db/move-team/src/Types.hs index d10e7786049..3c3cfe4d722 100644 --- a/tools/db/move-team/src/Types.hs +++ b/tools/db/move-team/src/Types.hs @@ -29,7 +29,6 @@ import Cassandra import Data.Aeson (FromJSON (..), ToJSON (..), Value (String), withArray, withText) import Data.Aeson.Types (Value (Array)) import Data.ByteString.Lazy (fromStrict, toStrict) -import Data.Handle import Data.IP (IP (..)) import Data.Id import Data.Text qualified as T @@ -38,7 +37,6 @@ import Data.Vector qualified as V import Galley.Cassandra.Instances () import Imports import System.Logger (Logger) -import Wire.API.User.Password (PasswordResetKey (..)) data Env = Env { envLogger :: Logger, @@ -98,10 +96,6 @@ instance FromJSON IP where Nothing -> fail "not a formatted IP address" Just ip -> pure ip -deriving instance Cql Handle - -deriving instance Cql PasswordResetKey - deriving instance ToJSON Ascii deriving instance FromJSON Ascii From 1e9887319b8ea07347fe9170a3af44bf253c4f0d Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Wed, 17 Apr 2024 10:26:59 +0200 Subject: [PATCH 4/7] Lint things --- libs/wire-api/src/Wire/API/Asset.hs | 3 ++- services/galley/src/Galley/Cassandra/Instances.hs | 4 ++-- tools/db/auto-whitelist/default.nix | 2 -- tools/db/service-backfill/default.nix | 2 -- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/libs/wire-api/src/Wire/API/Asset.hs b/libs/wire-api/src/Wire/API/Asset.hs index a37d6efd474..6545a4eca54 100644 --- a/libs/wire-api/src/Wire/API/Asset.hs +++ b/libs/wire-api/src/Wire/API/Asset.hs @@ -186,11 +186,12 @@ instance S.ToParamSchema AssetKey where instance FromHttpApiData AssetKey where parseUrlPiece = first T.pack . runParser parser . T.encodeUtf8 -instance C.Cql AssetKey where +instance C.Cql AssetKey where ctype = C.Tagged C.TextColumn toCql = C.CqlText . assetKeyToText fromCql (C.CqlText txt) = runParser parser . T.encodeUtf8 $ txt fromCql _ = Left "AssetKey: Text expected" + -- instance C.Cql AssetKey where -- ctype = C.Tagged C.TextColumn -- toCql = C.CqlText . assetKeyToText diff --git a/services/galley/src/Galley/Cassandra/Instances.hs b/services/galley/src/Galley/Cassandra/Instances.hs index 9e6910ca1d6..ff61f65a204 100644 --- a/services/galley/src/Galley/Cassandra/Instances.hs +++ b/services/galley/src/Galley/Cassandra/Instances.hs @@ -207,9 +207,9 @@ instance Cql Icon where fromCql _ = Left "Icon: Text expected" -- TODO: brig has a different instance (catches left and returns --- a null asset key). this is probably bad and should +-- a null asset key). this is probably bad and should -- be stream-lined / fixed? --- instance Cql AssetKey where +-- instance Cql AssetKey where -- ctype = Tagged TextColumn -- toCql = CqlText . assetKeyToText -- fromCql (CqlText txt) = runParser parser . T.encodeUtf8 $ txt diff --git a/tools/db/auto-whitelist/default.nix b/tools/db/auto-whitelist/default.nix index d749f584c97..e7504cef918 100644 --- a/tools/db/auto-whitelist/default.nix +++ b/tools/db/auto-whitelist/default.nix @@ -14,7 +14,6 @@ , tinylog , types-common , unliftio -, wire-api }: mkDerivation { pname = "auto-whitelist"; @@ -32,7 +31,6 @@ mkDerivation { tinylog types-common unliftio - wire-api ]; description = "Backfill service tables"; license = lib.licenses.agpl3Only; diff --git a/tools/db/service-backfill/default.nix b/tools/db/service-backfill/default.nix index c778afe2db0..b4dbc2d6007 100644 --- a/tools/db/service-backfill/default.nix +++ b/tools/db/service-backfill/default.nix @@ -14,7 +14,6 @@ , tinylog , types-common , unliftio -, wire-api }: mkDerivation { pname = "service-backfill"; @@ -32,7 +31,6 @@ mkDerivation { tinylog types-common unliftio - wire-api ]; description = "Backfill service tables"; license = lib.licenses.agpl3Only; From 4dfd2373fc1f646c0b5dfec175a27ad7cd610c6a Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Wed, 17 Apr 2024 14:49:48 +0200 Subject: [PATCH 5/7] Delete dead code. --- libs/wire-api/src/Wire/API/Asset.hs | 8 -------- services/galley/src/Galley/Cassandra/Instances.hs | 9 --------- 2 files changed, 17 deletions(-) diff --git a/libs/wire-api/src/Wire/API/Asset.hs b/libs/wire-api/src/Wire/API/Asset.hs index 6545a4eca54..4718fa66ad5 100644 --- a/libs/wire-api/src/Wire/API/Asset.hs +++ b/libs/wire-api/src/Wire/API/Asset.hs @@ -192,14 +192,6 @@ instance C.Cql AssetKey where fromCql (C.CqlText txt) = runParser parser . T.encodeUtf8 $ txt fromCql _ = Left "AssetKey: Text expected" --- instance C.Cql AssetKey where --- ctype = C.Tagged C.TextColumn --- toCql = C.CqlText . assetKeyToText --- --- -- if the asset key is invalid we will return the nil asset key (`3-1-00000000-0000-0000-0000-000000000000`) --- fromCql (C.CqlText txt) = pure $ fromRight nilAssetKey $ runParser parser $ T.encodeUtf8 txt --- fromCql _ = Left "AssetKey: Expected CqlText" - -------------------------------------------------------------------------------- -- AssetToken diff --git a/services/galley/src/Galley/Cassandra/Instances.hs b/services/galley/src/Galley/Cassandra/Instances.hs index ff61f65a204..d1911434dd4 100644 --- a/services/galley/src/Galley/Cassandra/Instances.hs +++ b/services/galley/src/Galley/Cassandra/Instances.hs @@ -206,15 +206,6 @@ instance Cql Icon where fromCql (CqlText txt) = pure . fromRight DefaultIcon . runParser parser . T.encodeUtf8 $ txt fromCql _ = Left "Icon: Text expected" --- TODO: brig has a different instance (catches left and returns --- a null asset key). this is probably bad and should --- be stream-lined / fixed? --- instance Cql AssetKey where --- ctype = Tagged TextColumn --- toCql = CqlText . assetKeyToText --- fromCql (CqlText txt) = runParser parser . T.encodeUtf8 $ txt --- fromCql _ = Left "AssetKey: Text expected" - instance Cql Epoch where ctype = Tagged BigIntColumn toCql = CqlBigInt . fromIntegral . epochNumber From 7be198d94a7049d893bf8b906f247ed317d0564f Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Wed, 17 Apr 2024 15:21:48 +0200 Subject: [PATCH 6/7] Re-lint --- tools/db/auto-whitelist/src/Work.hs | 2 -- tools/db/migrate-sso-feature-flag/src/Work.hs | 2 -- tools/db/move-team/src/Work.hs | 2 -- tools/db/service-backfill/src/Work.hs | 2 -- 4 files changed, 8 deletions(-) diff --git a/tools/db/auto-whitelist/src/Work.hs b/tools/db/auto-whitelist/src/Work.hs index 0bec1ccd169..b3976b6447b 100644 --- a/tools/db/auto-whitelist/src/Work.hs +++ b/tools/db/auto-whitelist/src/Work.hs @@ -1,7 +1,5 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE StandaloneDeriving #-} {-# OPTIONS_GHC -fno-warn-orphans #-} -- This file is part of the Wire Server implementation. diff --git a/tools/db/migrate-sso-feature-flag/src/Work.hs b/tools/db/migrate-sso-feature-flag/src/Work.hs index d8c20a64672..36f5d5aba9b 100644 --- a/tools/db/migrate-sso-feature-flag/src/Work.hs +++ b/tools/db/migrate-sso-feature-flag/src/Work.hs @@ -1,7 +1,5 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE StandaloneDeriving #-} {-# OPTIONS_GHC -Wno-orphans -Wno-unused-imports #-} -- This file is part of the Wire Server implementation. diff --git a/tools/db/move-team/src/Work.hs b/tools/db/move-team/src/Work.hs index 87de720d3a2..b8a75722080 100644 --- a/tools/db/move-team/src/Work.hs +++ b/tools/db/move-team/src/Work.hs @@ -1,9 +1,7 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PartialTypeSignatures #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE StandaloneDeriving #-} {-# OPTIONS_GHC -Wno-orphans -Wno-unused-imports #-} -- This file is part of the Wire Server implementation. diff --git a/tools/db/service-backfill/src/Work.hs b/tools/db/service-backfill/src/Work.hs index f3229dd0fc4..82ae367134e 100644 --- a/tools/db/service-backfill/src/Work.hs +++ b/tools/db/service-backfill/src/Work.hs @@ -1,7 +1,5 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE StandaloneDeriving #-} {-# OPTIONS_GHC -fno-warn-orphans #-} -- This file is part of the Wire Server implementation. From eef48b797b24316bfd27db03e20f09d708e8fc4b Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Wed, 17 Apr 2024 15:38:58 +0200 Subject: [PATCH 7/7] Linting tool --- tools/db/repair-handles/default.nix | 2 -- tools/db/repair-handles/repair-handles.cabal | 1 - 2 files changed, 3 deletions(-) diff --git a/tools/db/repair-handles/default.nix b/tools/db/repair-handles/default.nix index c97deb7b45f..24336b506ea 100644 --- a/tools/db/repair-handles/default.nix +++ b/tools/db/repair-handles/default.nix @@ -4,7 +4,6 @@ # dependencies are added or removed. { mkDerivation , base -, brig , cassandra-util , conduit , containers @@ -27,7 +26,6 @@ mkDerivation { isExecutable = true; executableHaskellDepends = [ base - brig cassandra-util conduit containers diff --git a/tools/db/repair-handles/repair-handles.cabal b/tools/db/repair-handles/repair-handles.cabal index 79393d75a68..bd081ab8c21 100644 --- a/tools/db/repair-handles/repair-handles.cabal +++ b/tools/db/repair-handles/repair-handles.cabal @@ -67,7 +67,6 @@ executable repair-handles build-depends: base - , brig , cassandra-util , conduit , containers