Skip to content

Commit 3ab3e3e

Browse files
committed
Add spar-migrate-data, remove migrate-external-ids
1 parent 5e63cd0 commit 3ab3e3e

File tree

17 files changed

+572
-370
lines changed

17 files changed

+572
-370
lines changed

tools/db/migrate-external-ids/src/Main.hs renamed to services/spar/migrate-data/src/Main.hs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{-# LANGUAGE OverloadedStrings #-}
2-
31
-- This file is part of the Wire Server implementation.
42
--
53
-- Copyright (C) 2020 Wire Swiss GmbH <[email protected]>
@@ -17,13 +15,10 @@
1715
-- You should have received a copy of the GNU Affero General Public License along
1816
-- with this program. If not, see <https://www.gnu.org/licenses/>.
1917

20-
module Main
21-
( main,
22-
)
23-
where
18+
module Main where
2419

2520
import Imports
26-
import qualified Work
21+
import qualified Spar.DataMigration.Run as Run
2722

2823
main :: IO ()
29-
main = Work.main
24+
main = Run.main

services/spar/package.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ dependencies:
3030
- bytestring-conversion
3131
- case-insensitive
3232
- cassandra-util
33+
- conduit
3334
- containers
3435
- cookie
36+
- cql
3537
- cryptonite
3638
- data-default
3739
- email-validate
@@ -125,6 +127,13 @@ executables:
125127
dependencies:
126128
- spar
127129

130+
spar-migrate-data:
131+
main: Main.hs
132+
source-dirs: migrate-data/src
133+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
134+
dependencies:
135+
- spar
136+
128137
spar-integration:
129138
main: Spec.hs
130139
source-dirs:

services/spar/schema/src/Main.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import qualified V1
2727
import qualified V10
2828
import qualified V11
2929
import qualified V12
30+
import qualified V13
3031
import qualified V2
3132
import qualified V3
3233
import qualified V4
@@ -57,7 +58,8 @@ main = do
5758
V9.migration,
5859
V10.migration,
5960
V11.migration,
60-
V12.migration
61+
V12.migration,
62+
V13.migration
6163
-- When adding migrations here, don't forget to update
6264
-- 'schemaVersion' in Spar.Data
6365

services/spar/schema/src/V13.hs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- This file is part of the Wire Server implementation.
2+
--
3+
-- Copyright (C) 2020 Wire Swiss GmbH <[email protected]>
4+
--
5+
-- This program is free software: you can redistribute it and/or modify it under
6+
-- the terms of the GNU Affero General Public License as published by the Free
7+
-- Software Foundation, either version 3 of the License, or (at your option) any
8+
-- later version.
9+
--
10+
-- This program is distributed in the hope that it will be useful, but WITHOUT
11+
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12+
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13+
-- details.
14+
--
15+
-- You should have received a copy of the GNU Affero General Public License along
16+
-- with this program. If not, see <https://www.gnu.org/licenses/>.
17+
18+
module V13
19+
( migration,
20+
)
21+
where
22+
23+
import Cassandra.Schema
24+
import Imports
25+
import Text.RawString.QQ
26+
27+
migration :: Migration
28+
migration = Migration 13 "Create table `data_migration`" $ do
29+
schema'
30+
[r|
31+
CREATE TABLE data_migration (
32+
id int,
33+
version int,
34+
descr text,
35+
date timestamp,
36+
PRIMARY KEY (id, version)
37+
);
38+
|]

services/spar/spar.cabal

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cabal-version: 1.12
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: d5476ea0ce8d09ebda5cea51897773fb0372e5cae747e17a5dc89f7460c75604
7+
-- hash: 3c81df1298b4c17e7c600b0ce3b168e1ed99b271f4dee5cc565e43485d08025c
88

99
name: spar
1010
version: 0.1
@@ -27,6 +27,11 @@ library
2727
Spar.App
2828
Spar.Data
2929
Spar.Data.Instances
30+
Spar.DataMigration.Options
31+
Spar.DataMigration.RIO
32+
Spar.DataMigration.Run
33+
Spar.DataMigration.Types
34+
Spar.DataMigration.V1_ExternalIds
3035
Spar.Error
3136
Spar.Intra.Brig
3237
Spar.Intra.Galley
@@ -60,8 +65,10 @@ library
6065
, bytestring-conversion
6166
, case-insensitive
6267
, cassandra-util
68+
, conduit
6369
, containers
6470
, cookie
71+
, cql
6572
, cryptonite
6673
, data-default
6774
, email-validate
@@ -140,8 +147,10 @@ executable spar
140147
, bytestring-conversion
141148
, case-insensitive
142149
, cassandra-util
150+
, conduit
143151
, containers
144152
, cookie
153+
, cql
145154
, cryptonite
146155
, data-default
147156
, email-validate
@@ -238,8 +247,10 @@ executable spar-integration
238247
, bytestring-conversion
239248
, case-insensitive
240249
, cassandra-util
250+
, conduit
241251
, containers
242252
, cookie
253+
, cql
243254
, cryptonite
244255
, data-default
245256
, email-validate
@@ -310,6 +321,89 @@ executable spar-integration
310321
, zauth
311322
default-language: Haskell2010
312323

324+
executable spar-migrate-data
325+
main-is: Main.hs
326+
other-modules:
327+
Paths_spar
328+
hs-source-dirs:
329+
migrate-data/src
330+
default-extensions: AllowAmbiguousTypes BangPatterns ConstraintKinds DataKinds DefaultSignatures DerivingStrategies DeriveFunctor DeriveGeneric DeriveLift DeriveTraversable EmptyCase FlexibleContexts FlexibleInstances FunctionalDependencies GADTs InstanceSigs KindSignatures LambdaCase MultiParamTypeClasses MultiWayIf NamedFieldPuns NoImplicitPrelude OverloadedStrings PackageImports PatternSynonyms PolyKinds QuasiQuotes RankNTypes ScopedTypeVariables StandaloneDeriving TemplateHaskell TupleSections TypeApplications TypeFamilies TypeFamilyDependencies TypeOperators UndecidableInstances ViewPatterns
331+
ghc-options: -O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path -j -Wno-redundant-constraints -Werror -threaded -rtsopts -with-rtsopts=-N
332+
build-depends:
333+
HsOpenSSL
334+
, aeson
335+
, aeson-pretty
336+
, aeson-qq
337+
, attoparsec
338+
, base
339+
, base64-bytestring
340+
, bilge
341+
, binary
342+
, brig-types
343+
, bytestring
344+
, bytestring-conversion
345+
, case-insensitive
346+
, cassandra-util
347+
, conduit
348+
, containers
349+
, cookie
350+
, cql
351+
, cryptonite
352+
, data-default
353+
, email-validate
354+
, errors
355+
, exceptions
356+
, extended
357+
, extra
358+
, galley-types
359+
, ghc-prim
360+
, hscim
361+
, http-api-data
362+
, http-client
363+
, http-client-tls
364+
, http-media
365+
, http-types
366+
, imports
367+
, insert-ordered-containers
368+
, interpolate
369+
, lens
370+
, memory
371+
, metrics-core
372+
, metrics-wai
373+
, mtl
374+
, network-uri
375+
, optparse-applicative
376+
, prometheus-client
377+
, raw-strings-qq
378+
, retry
379+
, saml2-web-sso >=0.18
380+
, scientific
381+
, servant
382+
, servant-multipart
383+
, servant-server
384+
, servant-swagger
385+
, spar
386+
, string-conversions
387+
, swagger2
388+
, text
389+
, text-latin1
390+
, time
391+
, tinylog
392+
, transformers
393+
, types-common
394+
, unordered-containers
395+
, uri-bytestring
396+
, uuid
397+
, wai
398+
, wai-middleware-prometheus
399+
, wai-utilities
400+
, warp
401+
, wire-api
402+
, x509
403+
, xml-conduit
404+
, yaml
405+
default-language: Haskell2010
406+
313407
executable spar-schema
314408
main-is: Main.hs
315409
other-modules:
@@ -318,6 +412,7 @@ executable spar-schema
318412
V10
319413
V11
320414
V12
415+
V13
321416
V2
322417
V3
323418
V4
@@ -346,8 +441,10 @@ executable spar-schema
346441
, bytestring-conversion
347442
, case-insensitive
348443
, cassandra-util
444+
, conduit
349445
, containers
350446
, cookie
447+
, cql
351448
, cryptonite
352449
, data-default
353450
, email-validate
@@ -436,8 +533,10 @@ test-suite spec
436533
, bytestring-conversion
437534
, case-insensitive
438535
, cassandra-util
536+
, conduit
439537
, containers
440538
, cookie
539+
, cql
441540
, cryptonite
442541
, data-default
443542
, email-validate

services/spar/src/Spar/Data.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ import qualified Prelude
110110

111111
-- | A lower bound: @schemaVersion <= whatWeFoundOnCassandra@, not @==@.
112112
schemaVersion :: Int32
113-
schemaVersion = 12
113+
schemaVersion = 13
114114

115115
----------------------------------------------------------------------
116116
-- helpers

tools/db/migrate-external-ids/src/Options.hs renamed to services/spar/src/Spar/DataMigration/Options.hs

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{-# LANGUAGE OverloadedStrings #-}
2-
{-# LANGUAGE TemplateHaskell #-}
3-
41
-- This file is part of the Wire Server implementation.
52
--
63
-- Copyright (C) 2020 Wire Swiss GmbH <[email protected]>
@@ -18,7 +15,7 @@
1815
-- You should have received a copy of the GNU Affero General Public License along
1916
-- with this program. If not, see <https://www.gnu.org/licenses/>.
2017

21-
module Options
18+
module Spar.DataMigration.Options
2219
( setCasSpar,
2320
setCasBrig,
2421
setDebug,
@@ -28,8 +25,6 @@ module Options
2825
cPort,
2926
cKeyspace,
3027
settingsParser,
31-
Debug (..),
32-
DryRun (..),
3328
)
3429
where
3530

@@ -38,40 +33,15 @@ import Control.Lens
3833
import Data.Text.Strict.Lens
3934
import Imports
4035
import Options.Applicative
41-
42-
data MigratorSettings = MigratorSettings
43-
{ _setCasSpar :: !CassandraSettings,
44-
_setCasBrig :: !CassandraSettings,
45-
_setDebug :: Debug,
46-
_setDryRun :: DryRun,
47-
_setPageSize :: Int32
48-
}
49-
deriving (Show)
50-
51-
data CassandraSettings = CassandraSettings
52-
{ _cHosts :: !String,
53-
_cPort :: !Word16,
54-
_cKeyspace :: !C.Keyspace
55-
}
56-
deriving (Show)
57-
58-
data Debug = Debug | NoDebug
59-
deriving (Show)
60-
61-
data DryRun = DryRun | NoDryRun
62-
deriving (Show)
63-
64-
makeLenses ''MigratorSettings
65-
66-
makeLenses ''CassandraSettings
36+
import Spar.DataMigration.Types
6737

6838
settingsParser :: Parser MigratorSettings
6939
settingsParser =
7040
MigratorSettings
7141
<$> cassandraSettingsParser "spar"
7242
<*> cassandraSettingsParser "brig"
73-
<*> flag NoDebug Debug (long "debug")
74-
<*> flag NoDryRun DryRun (long "dry-run" <> short 'n')
43+
<*> switch (long "debug")
44+
<*> switch (long "dry-run" <> short 'n')
7545
<*> option auto (long "page-size" <> short 'p' <> value 1000)
7646

7747
cassandraSettingsParser :: String -> Parser CassandraSettings
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2+
3+
-- This file is part of the Wire Server implementation.
4+
--
5+
-- Copyright (C) 2020 Wire Swiss GmbH <[email protected]>
6+
--
7+
-- This program is free software: you can redistribute it and/or modify it under
8+
-- the terms of the GNU Affero General Public License as published by the Free
9+
-- Software Foundation, either version 3 of the License, or (at your option) any
10+
-- later version.
11+
--
12+
-- This program is distributed in the hope that it will be useful, but WITHOUT
13+
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14+
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
15+
-- details.
16+
--
17+
-- You should have received a copy of the GNU Affero General Public License along
18+
-- with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
module Spar.DataMigration.RIO where
21+
22+
import Imports
23+
24+
newtype RIO env a = RIO {unRIO :: ReaderT env IO a}
25+
deriving newtype (Functor, Applicative, Monad, MonadIO, MonadReader env)
26+
27+
runRIO :: env -> RIO env a -> IO a
28+
runRIO e f = runReaderT (unRIO f) e
29+
30+
modifyRef :: (env -> IORef a) -> (a -> a) -> RIO env ()
31+
modifyRef get_ mod' = do
32+
ref <- asks get_
33+
liftIO (modifyIORef ref mod')
34+
35+
readRef :: (env -> IORef b) -> RIO env b
36+
readRef g = do
37+
ref <- asks g
38+
liftIO $ readIORef ref

0 commit comments

Comments
 (0)