mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-24 16:03:37 +03:00
2be2200b1a
This reflects the two different usages, which should not be conflated. We also propagate the type a little more, to avoid `Text`. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4931 GitOrigin-RevId: 16278f14aa4c2cb5667ea54bbb6b25e6d362835c
48 lines
1.6 KiB
Haskell
48 lines
1.6 KiB
Haskell
module Hasura.Server.Migrate.Version
|
|
( MetadataCatalogVersion (..),
|
|
SourceCatalogVersion (..),
|
|
)
|
|
where
|
|
|
|
import Data.List (isPrefixOf)
|
|
import Hasura.Prelude
|
|
import Hasura.SQL.Backend (BackendType)
|
|
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.
|
|
data MetadataCatalogVersion
|
|
= -- | A typical catalog version.
|
|
MetadataCatalogVersion Int
|
|
| -- | Maintained for compatibility with catalog version 0.8.
|
|
MetadataCatalogVersion08
|
|
deriving stock (Eq, Lift)
|
|
|
|
instance Ord MetadataCatalogVersion where
|
|
compare = compare `on` toFloat
|
|
where
|
|
toFloat :: MetadataCatalogVersion -> Float
|
|
toFloat (MetadataCatalogVersion v) = fromIntegral v
|
|
toFloat MetadataCatalogVersion08 = 0.8
|
|
|
|
instance Enum MetadataCatalogVersion where
|
|
toEnum = MetadataCatalogVersion
|
|
fromEnum (MetadataCatalogVersion v) = v
|
|
fromEnum MetadataCatalogVersion08 = error "Cannot enumerate unstable catalog versions."
|
|
|
|
instance Show MetadataCatalogVersion where
|
|
show (MetadataCatalogVersion v) = show v
|
|
show MetadataCatalogVersion08 = "0.8"
|
|
|
|
instance Read MetadataCatalogVersion where
|
|
readsPrec prec s
|
|
| "0.8" `isPrefixOf` s =
|
|
[(MetadataCatalogVersion08, drop 3 s)]
|
|
| otherwise =
|
|
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)
|