Skip to content

Commit

Permalink
Merge pull request #2173 from input-output-hk/KtorZ/already-existing-…
Browse files Browse the repository at this point in the history
…metadata-fixup

add fallback for metadata JSON parsing from pre-existing database
  • Loading branch information
KtorZ authored Sep 24, 2020
2 parents 0c9ce88 + d8eb645 commit e3145b8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/core/src/Cardano/Wallet/DB/Sqlite/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,27 @@ instance PersistField TxMetadata where
Aeson.encode .
metadataToJson TxMetadataJsonDetailedSchema
fromPersistValue =
(left (T.pack . displayError) . metadataFromJson TxMetadataJsonDetailedSchema) <=<
(left (T.pack . displayError) . metadataFromJsonWithFallback) <=<
(left T.pack . Aeson.eitherDecode . BL.fromStrict . encodeUtf8) <=<
fromPersistValue
where
-- FIXME
-- Because of time constraints, we have had two consecutives releases
-- of cardano-wallet which ended up using different conversions method
-- for metadata to/from JSON.
-- As a result, some users' databases contain metadata using the direct
-- JSON conversion while we now expect the detailed schema variant.
--
-- We do therefore fallback when deserializing data do the direct
-- conversion (which will then be serialized back using the detailed
-- schema). We can remove that fallback after some time has passed since
-- release v2020-09-22.
metadataFromJsonWithFallback json =
case metadataFromJson TxMetadataJsonDetailedSchema json of
Right meta -> Right meta
Left e -> case metadataFromJson TxMetadataJsonNoSchema json of
Right meta -> Right meta
Left{} -> Left e

instance PersistFieldSql TxMetadata where
sqlType _ = sqlType (Proxy @Text)
Expand Down

0 comments on commit e3145b8

Please sign in to comment.