2022-07-04 12:30:53 +03:00
|
|
|
module Hasura.Server.Migrate.Version
|
|
|
|
( MetadataCatalogVersion (..),
|
|
|
|
SourceCatalogVersion (..),
|
|
|
|
)
|
|
|
|
where
|
2022-03-16 03:39:21 +03:00
|
|
|
|
2022-06-29 11:18:32 +03:00
|
|
|
import Data.List (isPrefixOf)
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Prelude
|
2022-07-04 12:30:53 +03:00
|
|
|
import Hasura.SQL.Backend (BackendType)
|
2022-06-29 11:18:32 +03:00
|
|
|
import Language.Haskell.TH.Lift (Lift)
|
|
|
|
|
|
|
|
-- | Represents the catalog version. This is stored in the database and then
|
|
|
|
-- compared with the latest version on startup.
|
2022-07-04 12:30:53 +03:00
|
|
|
data MetadataCatalogVersion
|
2022-06-29 11:18:32 +03:00
|
|
|
= -- | A typical catalog version.
|
2022-07-04 12:30:53 +03:00
|
|
|
MetadataCatalogVersion Int
|
2022-06-29 11:18:32 +03:00
|
|
|
| -- | Maintained for compatibility with catalog version 0.8.
|
2022-07-04 12:30:53 +03:00
|
|
|
MetadataCatalogVersion08
|
2022-06-29 11:18:32 +03:00
|
|
|
deriving stock (Eq, Lift)
|
|
|
|
|
2022-07-04 12:30:53 +03:00
|
|
|
instance Ord MetadataCatalogVersion where
|
2022-06-29 11:18:32 +03:00
|
|
|
compare = compare `on` toFloat
|
|
|
|
where
|
2022-07-04 12:30:53 +03:00
|
|
|
toFloat :: MetadataCatalogVersion -> Float
|
|
|
|
toFloat (MetadataCatalogVersion v) = fromIntegral v
|
|
|
|
toFloat MetadataCatalogVersion08 = 0.8
|
2022-06-29 11:18:32 +03:00
|
|
|
|
2022-07-04 12:30:53 +03:00
|
|
|
instance Enum MetadataCatalogVersion where
|
|
|
|
toEnum = MetadataCatalogVersion
|
|
|
|
fromEnum (MetadataCatalogVersion v) = v
|
|
|
|
fromEnum MetadataCatalogVersion08 = error "Cannot enumerate unstable catalog versions."
|
2020-02-24 17:33:56 +03:00
|
|
|
|
2022-07-04 12:30:53 +03:00
|
|
|
instance Show MetadataCatalogVersion where
|
|
|
|
show (MetadataCatalogVersion v) = show v
|
|
|
|
show MetadataCatalogVersion08 = "0.8"
|
2019-10-11 08:13:57 +03:00
|
|
|
|
2022-07-04 12:30:53 +03:00
|
|
|
instance Read MetadataCatalogVersion where
|
2022-06-29 11:18:32 +03:00
|
|
|
readsPrec prec s
|
|
|
|
| "0.8" `isPrefixOf` s =
|
2022-07-04 12:30:53 +03:00
|
|
|
[(MetadataCatalogVersion08, drop 3 s)]
|
2022-06-29 11:18:32 +03:00
|
|
|
| otherwise =
|
2022-07-04 12:30:53 +03:00
|
|
|
map (first MetadataCatalogVersion) $ filter ((>= 0) . fst) $ readsPrec @Int prec s
|
|
|
|
|
|
|
|
-- | This is the source catalog version, used when deciding whether to (re-)create event triggers.
|
|
|
|
newtype SourceCatalogVersion (backend :: BackendType) = SourceCatalogVersion Int
|
|
|
|
deriving newtype (Eq, Enum, Show, Read)
|
|
|
|
deriving stock (Lift)
|