@@ -0,0 +1,62 @@
1+{-# LANGUAGE TemplateHaskell #-}
3+module Data.Schematic.Migration where
6+import Data.Schematic.Path
7+import Data.Schematic.Schema
8+import Data.Schematic.Utils
9+import Data.Singletons.Prelude
10+import Data.Singletons.TypeLits
13+data Action = AddKey Symbol Schema | Update Schema | DeleteKey
15+data instance Sing (a :: Action) where
17+ :: (Known (Sing n), Known (Sing s))
20+ -> Sing ('AddKey n s)
21+ SUpdate :: Known (Sing s) => Sing s -> Sing ('Update s)
22+ SDelete :: Sing 'DeleteKey
24+instance (Known (Sing n), Known (Sing s)) => Known (Sing ('AddKey n s)) where
25+ known = SAddKey known known
26+instance (Known (Sing s)) => Known (Sing ('Update s)) where known = SUpdate known
27+instance Known (Sing 'DeleteKey) where known = SDelete
29+data Diff = DiffSchema [PathSegment] Action
31+data instance Sing (diff :: Diff) where
33+ :: (Known (Sing jp), Known (Sing a))
34+ => Sing (jp :: [PathSegment])
35+ -> Sing (a :: Action)
36+ -> Sing ('DiffSchema jp a)
38+type Revision = Symbol
40+data Migration = Migration Revision [Diff]
42+data instance Sing (m :: Migration) where
44+ :: (KnownSymbol r, Known (Sing ds))
47+ -> Sing ('Migration r ds)
49+data Versioned = Versioned
50+ Schema -- base version
51+ [Migration] -- a bunch of migrations
53+data instance (Sing (v :: Versioned)) where
55+ :: (Known (Sing s), Known (Sing ms))
58+ -> Sing ('Versioned s ms)
60+type family Typed (s :: Schema) (ps :: PathSegment) :: Constraint where
61+ Typed ('SchemaObject '[]) ('Key fn) = FalseConstraint fn
62+ Typed ('SchemaObject ( '(fn, s) ': tl)) ('Key fn) = ()