@@ -38,6 +38,8 @@ type family UpdateKey (acc :: [(Symbol, Schema)]) (fn :: Symbol) (fs :: [(Symbol
38 UpdateKey acc fn ( '(fn, n) ': tl ) s = '(fn, s) ': tl
38 UpdateKey acc fn ( '(fn, n) ': tl ) s = '(fn, s) ': tl
39 UpdateKey acc fn ( '(a, n) ': tl) s = UpdateKey (acc :++ '[ '(a,n) ]) fn tl s
39 UpdateKey acc fn ( '(a, n) ': tl) s = UpdateKey (acc :++ '[ '(a,n) ]) fn tl s
41type family Build (b :: Builder) :: Schema where
43type family Build (b :: Builder) :: Schema where
42 Build ('BKey ('SchemaObject fs) fn z) = 'SchemaObject (UpdateKey '[] fn fs (Build z))
44 Build ('BKey ('SchemaObject fs) fn z) = 'SchemaObject (UpdateKey '[] fn fs (Build z))
43 Build ('BTraverse ('SchemaArray acs s) z) = 'SchemaArray acs (Build z)
45 Build ('BTraverse ('SchemaArray acs s) z) = 'SchemaArray acs (Build z)
@@ -60,12 +62,19 @@ type family ApplyMigration (m :: Migration) (s :: Schema) :: (Revision, Schema)
60 ApplyMigration ('Migration r (d ': ds)) s =
62 ApplyMigration ('Migration r (d ': ds)) s =
61 '(r, Snd (ApplyMigration ('Migration r ds) (Build (MakeBuilder s d))))
63 '(r, Snd (ApplyMigration ('Migration r ds) (Build (MakeBuilder s d))))
65+-- working with revisions
63type family SchemaByRevision (r :: Revision) (vd :: Versioned) :: Schema where
67type family SchemaByRevision (r :: Revision) (vd :: Versioned) :: Schema where
64 SchemaByRevision r ('Versioned s (('Migration r ds) ': ms)) =
68 SchemaByRevision r ('Versioned s (('Migration r ds) ': ms)) =
65 Snd (ApplyMigration ('Migration r ds) s)
69 Snd (ApplyMigration ('Migration r ds) s)
66 SchemaByRevision r ('Versioned s (m ': ms)) =
70 SchemaByRevision r ('Versioned s (m ': ms)) =
67 SchemaByRevision r ('Versioned (Snd (ApplyMigration m s)) ms)
71 SchemaByRevision r ('Versioned (Snd (ApplyMigration m s)) ms)
73+type family TopVersion (vd :: Versioned) :: Schema where
74+ TopVersion ('Versioned s '[]) = s
75+ TopVersion ('Versioned s (m ': ms)) =
76+ TopVersion ('Versioned (Snd (ApplyMigration m s)) ms)
69class MigrateSchema (a :: Schema) (b :: Schema) where
78class MigrateSchema (a :: Schema) (b :: Schema) where
70 migrate :: JsonRepr a -> JsonRepr b
79 migrate :: JsonRepr a -> JsonRepr b
@@ -111,8 +120,6 @@ data instance Sing (m :: Migration) where
112data Versioned = Versioned Schema [Migration]
121data Versioned = Versioned Schema [Migration]
114−type family TypedVersionedSchema
116data instance Sing (v :: Versioned) where
123data instance Sing (v :: Versioned) where
117 SVersioned
124 SVersioned
118 :: (Known (Sing s), Known (Sing ms))
125 :: (Known (Sing s), Known (Sing ms))
@@ -130,7 +137,7 @@ type VS =
130 '[ 'Migration "test_revision"
137 '[ 'Migration "test_revision"
131 '[ 'Diff '[ 'PKey "foo" ] ('Update ('SchemaText '[])) ] ]
138 '[ 'Diff '[ 'PKey "foo" ] ('Update ('SchemaText '[])) ] ]
133−jsonExample :: JsonRepr (SchemaByRevision "test_revision" VS)
140+jsonExample :: JsonRepr (TopVersion VS)
134jsonExample = ReprObject $
141jsonExample = ReprObject $
135 FieldRepr (ReprText "foo")
142 FieldRepr (ReprText "foo")
136 :& FieldRepr (ReprOptional (Just (ReprText "bar")))
143 :& FieldRepr (ReprOptional (Just (ReprText "bar")))