Skip to content

Commit

Permalink
Schema evolution for sets
Browse files Browse the repository at this point in the history
Summary:
This diff provides the bare minimum schema evolution to allow set types to be used in production.

My plan is to provide much more elaborate evolution in future diffs. But because sets are implemented as syscalls, and the schema machinery currently doesn't use syscalls, such a change is pretty involved.

Reviewed By: donsbot, simonmar

Differential Revision: D65896602

fbshipit-source-id: da82f01a1febbaf6f9a58432741ee066e5fa2590
  • Loading branch information
Josef Svenningsson authored and facebook-github-bot committed Nov 14, 2024
1 parent c780a89 commit 6af2302
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion glean/db/Glean/Query/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ transformTerm inner defaultForType src dst = go src dst
(recurse discard)
a
_ -> error $ "expected Array, got " <> show term

go (SetTy from) (SetTy to)
| from == to = Nothing
go (RecordTy from) (RecordTy to) =
let transformations = transformationsFor from to
sameFieldCount = length from == length to
Expand Down
7 changes: 7 additions & 0 deletions glean/hs/Glean/Schema/Evolve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ canEvolve types compatible new old = go new old
go StringTy StringTy = Nothing
go BooleanTy BooleanTy = Nothing
go (ArrayTy new) (ArrayTy old) = go new old
go (SetTy new) (SetTy old)
| new == old = Nothing
| otherwise = Just $ Text.pack $
"types inside sets cannot evolve. Type changed from " <>
show (displayDefault (SetTy old))
<> " to " <> show (displayDefault new)
go (PredicateTy new) (PredicateTy old)
| not (compatible new old) = Just
$ "type changed from " <> showRef old
Expand Down Expand Up @@ -421,6 +427,7 @@ canEvolve types compatible new old = go new old
BooleanTy -> True
ByteTy -> True
ArrayTy _ -> True
SetTy _ -> True
RecordTy fields -> all (hasDefault . fieldDefType) fields
EnumeratedTy{} -> True
SumTy (first : _) -> hasDefault (fieldDefType first)
Expand Down

0 comments on commit 6af2302

Please sign in to comment.