diff --git a/changelog.d/5-internal/refactored-schema-version-tracking b/changelog.d/5-internal/refactored-schema-version-tracking new file mode 100644 index 0000000000..16d655ef96 --- /dev/null +++ b/changelog.d/5-internal/refactored-schema-version-tracking @@ -0,0 +1 @@ +Refactored schema version tracking from manually managed to automatic. diff --git a/services/gundeck/default.nix b/services/gundeck/default.nix index 18410fe998..ddf49dc9fa 100644 --- a/services/gundeck/default.nix +++ b/services/gundeck/default.nix @@ -120,6 +120,7 @@ mkDerivation { mtl network-uri psqueues + raw-strings-qq resourcet retry safe-exceptions @@ -153,7 +154,6 @@ mkDerivation { cassandra-util containers exceptions - extended gundeck-types HsOpenSSL http-client @@ -167,7 +167,6 @@ mkDerivation { network-uri optparse-applicative random - raw-strings-qq retry safe tagged diff --git a/services/gundeck/gundeck.cabal b/services/gundeck/gundeck.cabal index 7a116433a4..277c81fea7 100644 --- a/services/gundeck/gundeck.cabal +++ b/services/gundeck/gundeck.cabal @@ -16,6 +16,7 @@ flag static default: False library + -- cabal-fmt: expand src exposed-modules: Gundeck.API Gundeck.API.Internal @@ -42,6 +43,17 @@ library Gundeck.Redis Gundeck.Redis.HedisExtensions Gundeck.Run + Gundeck.Schema.Run + Gundeck.Schema.V1 + Gundeck.Schema.V10 + Gundeck.Schema.V2 + Gundeck.Schema.V3 + Gundeck.Schema.V4 + Gundeck.Schema.V5 + Gundeck.Schema.V6 + Gundeck.Schema.V7 + Gundeck.Schema.V8 + Gundeck.Schema.V9 Gundeck.ThreadBudget Gundeck.ThreadBudget.Internal Gundeck.Util @@ -130,6 +142,7 @@ library , mtl >=2.2 , network-uri >=2.6 , psqueues >=0.2.2 + , raw-strings-qq , resourcet >=1.1 , retry >=0.5 , safe-exceptions @@ -318,20 +331,7 @@ executable gundeck-integration executable gundeck-schema main-is: Main.hs - other-modules: - Paths_gundeck - V1 - V10 - V2 - V3 - V4 - V5 - V6 - V7 - V8 - V9 - - hs-source-dirs: schema/src + hs-source-dirs: schema default-extensions: NoImplicitPrelude AllowAmbiguousTypes @@ -380,12 +380,8 @@ executable gundeck-schema -threaded -Wredundant-constraints -Wunused-packages build-depends: - base - , cassandra-util - , extended + gundeck , imports - , raw-strings-qq - , types-common if flag(static) ld-options: -static diff --git a/services/gundeck/schema/Main.hs b/services/gundeck/schema/Main.hs new file mode 100644 index 0000000000..bf76183bd5 --- /dev/null +++ b/services/gundeck/schema/Main.hs @@ -0,0 +1,24 @@ +-- 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 Main where + +import Gundeck.Schema.Run qualified as Run +import Imports + +main :: IO () +main = Run.main diff --git a/services/gundeck/schema/src/Main.hs b/services/gundeck/src/Gundeck/Schema/Run.hs similarity index 61% rename from services/gundeck/schema/src/Main.hs rename to services/gundeck/src/Gundeck/Schema/Run.hs index 56ef98f095..056363c244 100644 --- a/services/gundeck/schema/src/Main.hs +++ b/services/gundeck/src/Gundeck/Schema/Run.hs @@ -15,23 +15,23 @@ -- You should have received a copy of the GNU Affero General Public License along -- with this program. If not, see . -module Main where +module Gundeck.Schema.Run where import Cassandra.Schema import Control.Exception (finally) +import Gundeck.Schema.V1 qualified as V1 +import Gundeck.Schema.V10 qualified as V10 +import Gundeck.Schema.V2 qualified as V2 +import Gundeck.Schema.V3 qualified as V3 +import Gundeck.Schema.V4 qualified as V4 +import Gundeck.Schema.V5 qualified as V5 +import Gundeck.Schema.V6 qualified as V6 +import Gundeck.Schema.V7 qualified as V7 +import Gundeck.Schema.V8 qualified as V8 +import Gundeck.Schema.V9 qualified as V9 import Imports import System.Logger.Extended qualified as Log import Util.Options -import V1 qualified -import V10 qualified -import V2 qualified -import V3 qualified -import V4 qualified -import V5 qualified -import V6 qualified -import V7 qualified -import V8 qualified -import V9 qualified main :: IO () main = do @@ -40,18 +40,25 @@ main = do migrateSchema l o - [ V1.migration, - V2.migration, - V3.migration, - V4.migration, - V5.migration, - V6.migration, - V7.migration, - V8.migration, - V9.migration, - V10.migration - ] + migrations `finally` Log.close l where desc = "Gundeck Cassandra Schema Migrations" defaultPath = "/etc/wire/gundeck/conf/gundeck-schema.yaml" + +lastSchemaVersion :: Int32 +lastSchemaVersion = migVersion $ last migrations + +migrations :: [Migration] +migrations = + [ V1.migration, + V2.migration, + V3.migration, + V4.migration, + V5.migration, + V6.migration, + V7.migration, + V8.migration, + V9.migration, + V10.migration + ] diff --git a/services/gundeck/schema/src/V1.hs b/services/gundeck/src/Gundeck/Schema/V1.hs similarity index 98% rename from services/gundeck/schema/src/V1.hs rename to services/gundeck/src/Gundeck/Schema/V1.hs index ae1a296ab9..f3b71a70ef 100644 --- a/services/gundeck/schema/src/V1.hs +++ b/services/gundeck/src/Gundeck/Schema/V1.hs @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU Affero General Public License along -- with this program. If not, see . -module V1 +module Gundeck.Schema.V1 ( migration, ) where diff --git a/services/gundeck/schema/src/V10.hs b/services/gundeck/src/Gundeck/Schema/V10.hs similarity index 98% rename from services/gundeck/schema/src/V10.hs rename to services/gundeck/src/Gundeck/Schema/V10.hs index d37ed26974..322c36cd7c 100644 --- a/services/gundeck/schema/src/V10.hs +++ b/services/gundeck/src/Gundeck/Schema/V10.hs @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU Affero General Public License along -- with this program. If not, see . -module V10 +module Gundeck.Schema.V10 ( migration, ) where diff --git a/services/gundeck/schema/src/V2.hs b/services/gundeck/src/Gundeck/Schema/V2.hs similarity index 97% rename from services/gundeck/schema/src/V2.hs rename to services/gundeck/src/Gundeck/Schema/V2.hs index a970bc2a2d..175aa4d34b 100644 --- a/services/gundeck/schema/src/V2.hs +++ b/services/gundeck/src/Gundeck/Schema/V2.hs @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU Affero General Public License along -- with this program. If not, see . -module V2 +module Gundeck.Schema.V2 ( migration, ) where diff --git a/services/gundeck/schema/src/V3.hs b/services/gundeck/src/Gundeck/Schema/V3.hs similarity index 98% rename from services/gundeck/schema/src/V3.hs rename to services/gundeck/src/Gundeck/Schema/V3.hs index fb6055f8f4..09d94cfbfa 100644 --- a/services/gundeck/schema/src/V3.hs +++ b/services/gundeck/src/Gundeck/Schema/V3.hs @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU Affero General Public License along -- with this program. If not, see . -module V3 +module Gundeck.Schema.V3 ( migration, ) where diff --git a/services/gundeck/schema/src/V4.hs b/services/gundeck/src/Gundeck/Schema/V4.hs similarity index 97% rename from services/gundeck/schema/src/V4.hs rename to services/gundeck/src/Gundeck/Schema/V4.hs index e9f39f51b7..ee2908219e 100644 --- a/services/gundeck/schema/src/V4.hs +++ b/services/gundeck/src/Gundeck/Schema/V4.hs @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU Affero General Public License along -- with this program. If not, see . -module V4 +module Gundeck.Schema.V4 ( migration, ) where diff --git a/services/gundeck/schema/src/V5.hs b/services/gundeck/src/Gundeck/Schema/V5.hs similarity index 97% rename from services/gundeck/schema/src/V5.hs rename to services/gundeck/src/Gundeck/Schema/V5.hs index 77e7907ea5..97abe2a4b3 100644 --- a/services/gundeck/schema/src/V5.hs +++ b/services/gundeck/src/Gundeck/Schema/V5.hs @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU Affero General Public License along -- with this program. If not, see . -module V5 +module Gundeck.Schema.V5 ( migration, ) where diff --git a/services/gundeck/schema/src/V6.hs b/services/gundeck/src/Gundeck/Schema/V6.hs similarity index 98% rename from services/gundeck/schema/src/V6.hs rename to services/gundeck/src/Gundeck/Schema/V6.hs index d9b7ae9518..9e2785244b 100644 --- a/services/gundeck/schema/src/V6.hs +++ b/services/gundeck/src/Gundeck/Schema/V6.hs @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU Affero General Public License along -- with this program. If not, see . -module V6 +module Gundeck.Schema.V6 ( migration, ) where diff --git a/services/gundeck/schema/src/V7.hs b/services/gundeck/src/Gundeck/Schema/V7.hs similarity index 98% rename from services/gundeck/schema/src/V7.hs rename to services/gundeck/src/Gundeck/Schema/V7.hs index a5c1ac1ea9..c44dab3fba 100644 --- a/services/gundeck/schema/src/V7.hs +++ b/services/gundeck/src/Gundeck/Schema/V7.hs @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU Affero General Public License along -- with this program. If not, see . -module V7 +module Gundeck.Schema.V7 ( migration, ) where diff --git a/services/gundeck/schema/src/V8.hs b/services/gundeck/src/Gundeck/Schema/V8.hs similarity index 97% rename from services/gundeck/schema/src/V8.hs rename to services/gundeck/src/Gundeck/Schema/V8.hs index 50812186be..914557eb6b 100644 --- a/services/gundeck/schema/src/V8.hs +++ b/services/gundeck/src/Gundeck/Schema/V8.hs @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU Affero General Public License along -- with this program. If not, see . -module V8 +module Gundeck.Schema.V8 ( migration, ) where diff --git a/services/gundeck/schema/src/V9.hs b/services/gundeck/src/Gundeck/Schema/V9.hs similarity index 98% rename from services/gundeck/schema/src/V9.hs rename to services/gundeck/src/Gundeck/Schema/V9.hs index 2583384eff..6ba7b0d61b 100644 --- a/services/gundeck/schema/src/V9.hs +++ b/services/gundeck/src/Gundeck/Schema/V9.hs @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU Affero General Public License along -- with this program. If not, see . -module V9 +module Gundeck.Schema.V9 ( migration, ) where