@@ -38,6 +38,8 @@ type family UpdateKey (acc :: [(Symbol, Schema)]) (fn :: Symbol) (fs :: [(Symbol
3838 UpdateKey acc fn ( '(fn, n) ': tl ) s = '(fn, s) ': tl
3939 UpdateKey acc fn ( '(a, n) ': tl) s = UpdateKey (acc :++ '[ '(a,n) ]) fn tl s
4040
41+-- schema updates
42+
4143type family Build (b :: Builder) :: Schema where
4244 Build ('BKey ('SchemaObject fs) fn z) = 'SchemaObject (UpdateKey '[] fn fs (Build z))
4345 Build ('BTraverse ('SchemaArray acs s) z) = 'SchemaArray acs (Build z)
@@ -60,12 +62,19 @@ type family ApplyMigration (m :: Migration) (s :: Schema) :: (Revision, Schema)
6062 ApplyMigration ('Migration r (d ': ds)) s =
6163 '(r, Snd (ApplyMigration ('Migration r ds) (Build (MakeBuilder s d))))
6264
65+-- working with revisions
66+
6367type family SchemaByRevision (r :: Revision) (vd :: Versioned) :: Schema where
6468 SchemaByRevision r ('Versioned s (('Migration r ds) ': ms)) =
6569 Snd (ApplyMigration ('Migration r ds) s)
6670 SchemaByRevision r ('Versioned s (m ': ms)) =
6771 SchemaByRevision r ('Versioned (Snd (ApplyMigration m s)) ms)
6872
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)
77+
6978class MigrateSchema (a :: Schema) (b :: Schema) where
7079 migrate :: JsonRepr a -> JsonRepr b
7180
@@ -111,8 +120,6 @@ data instance Sing (m :: Migration) where
111120
112121data Versioned = Versioned Schema [Migration]
113122
114−type family TypedVersionedSchema
115−
116123data instance Sing (v :: Versioned) where
117124 SVersioned
118125 :: (Known (Sing s), Known (Sing ms))
@@ -130,7 +137,7 @@ type VS =
130137 '[ 'Migration "test_revision"
131138 '[ 'Diff '[ 'PKey "foo" ] ('Update ('SchemaText '[])) ] ]
132139
133−jsonExample :: JsonRepr (SchemaByRevision "test_revision" VS)
140+jsonExample :: JsonRepr (TopVersion VS)
134141jsonExample = ReprObject $
135142 FieldRepr (ReprText "foo")
136143 :& FieldRepr (ReprOptional (Just (ReprText "bar")))