Update database layer to use CreditTo
[?]
Oct 15, 2016, 5:12 AM
RN7EI6INGUUHGMNY5RU3NH56WPLRZY5ZMYDNFMNE3TGV4ESFLQIACDependencies
- [2]
POX3UAMTEnabling logging of time to contributor/project accounts - [3]
3QVT6MA6Add database support for event amend operations. - [4]
FD7SV5I6Fix handling of event_t columns. - [5]
KNSI575VCleanup of EventLog types. - [6]
A6HKMINBAttempting to improve JSON handling. - [7]
QMRKFEPGRefactor QDB to use a free monad algebra instead. - [8]
NLZ3JXLOFix formatting with stylish-haskell. - [9]
IZEVQF62Work in progress replacing sqlite with postgres. - [10]
NEDDHXUKReformat via stylish-haskell - [11]
Z7KS5XHHVery WIP. Wow. - [12]
O5FVTOM6Undo JSON silliness, enable a couple more routes. - [13]
7KZP4RHZSwitch from Data.Time to Data.Thyme - [14]
7HPY3QPFFix linting errors. (yay hlint!) - [15]
GCVQD44VCreate amends endpoint, switch to UUID primary keys - [16]
2XQD6KKKAdd invitation logic and clean up DBProg error handling. - [17]
ASF3UPJLAdd auction creation and bid handlers - [*]
W35DDBFYFactor common JSON conversions up into client lib module. - [*]
NVOCQVASInitial failing tests. - [*]
SCXG6TJWMake log reduction safer in presence of overlapping events.
Change contents
- edit in lib/Aftok/Database/PostgreSQL.hs at line 19
import Database.PostgreSQL.Simple.Types (Null) - edit in lib/Aftok/Database/PostgreSQL.hs at line 37[4.2026]→[4.2026:2027](∅→∅),[4.2027]→[4.39:94](∅→∅),[4.1124]→[4.39:94](∅→∅),[4.94]→[4.4:48](∅→∅),[4.1165]→[4.4:48](∅→∅),[4.48]→[4.1739:1769](∅→∅),[4.1769]→[4.113:158](∅→∅),[4.113]→[4.113:158](∅→∅),[4.158]→[4.1770:1814](∅→∅),[4.1814]→[4.203:469](∅→∅),[4.203]→[4.203:469](∅→∅),[4.469]→[4.1815:1824](∅→∅),[4.1824]→[4.479:522](∅→∅),[4.479]→[4.479:522](∅→∅),[4.522]→[4.1825:1867](∅→∅),[4.1867]→[4.565:765](∅→∅),[4.565]→[4.565:765](∅→∅)
eventTypeParser :: FieldParser (C.UTCTime -> LogEvent)eventTypeParser f v = dotn <- typename fcase tn of"event_t" ->let err = UnexpectedNull (B.unpack tn)(tableOid f)(maybe "" B.unpack (name f))"UTCTime -> LogEvent""columns of type event_t should not contain null values"in maybe (conversionError err) (nameEvent . decodeUtf8) v_ ->let err = Incompatible (B.unpack tn)(tableOid f)(maybe "" B.unpack (name f))"UTCTime -> LogEvent""column was not of type event_t"in conversionError err - edit in lib/Aftok/Database/PostgreSQL.hs at line 61
nullField :: RowParser NullnullField = fieldeventTypeParser :: FieldParser (C.UTCTime -> LogEvent)eventTypeParser f v = dotn <- typename fcase tn of"event_t" ->let err = UnexpectedNull (B.unpack tn)(tableOid f)(maybe "" B.unpack (name f))"UTCTime -> LogEvent""columns of type event_t should not contain null values"in maybe (conversionError err) (nameEvent . decodeUtf8) v_ ->let err = Incompatible (B.unpack tn)(tableOid f)(maybe "" B.unpack (name f))"UTCTime -> LogEvent""column was not of type event_t"in conversionError err - edit in lib/Aftok/Database/PostgreSQL.hs at line 84
creditToParser :: FieldParser (RowParser CreditTo)creditToParser f v = dotn <- typename flet parser :: Text -> Conversion (RowParser CreditTo)parser tname = pure $ case tname of"credit_to_btc_addr" -> CreditToAddress <$> (fieldWith btcAddrParser <* nullField <* nullField)"credit_to_user" -> CreditToUser <$> (nullField *> fieldWith uidParser <* nullField)"credit_to_project" -> CreditToProject <$> (nullField *> nullField *> fieldWith pidParser)_ -> emptycase tn of"credit_to_t" -> maybe empty (parser . decodeUtf8) v_ -> conversionError $Incompatible(B.unpack tn)(tableOid f)(maybe "" B.unpack (name f))"RowParser CreditTo""column was not of type event_t" - replacement in lib/Aftok/Database/PostgreSQL.hs at line 108
LogEntry <$> fieldWith btcAddrParserLogEntry <$> join (fieldWith creditToParser) - replacement in lib/Aftok/Database/PostgreSQL.hs at line 190
\(project_id, user_id, credit_to_btc_addr, event_type, event_time, event_metadata) \\VALUES (?, ?, ?, ?, ?, ?) \\(project_id, user_id, credit_to_type, credit_to_btc_addr, event_type, event_time, event_metadata) \\VALUES (?, ?, ?, ?, ?, ?, ?) \ - replacement in lib/Aftok/Database/PostgreSQL.hs at line 193
( pid, uid, addr ^. _BtcAddr, eventName e, fromThyme $ e ^. eventTime, m)( pid, uid, creditToName c, addr ^. _BtcAddr, eventName e, fromThyme $ e ^. eventTime, m) - replacement in lib/Aftok/Database/PostgreSQL.hs at line 195
CreditToProject pid ->CreditToProject pid' -> - replacement in lib/Aftok/Database/PostgreSQL.hs at line 198
\(project_id, user_id, credit_to_project_id, event_type, event_time, event_metadata) \\VALUES (?, ?, ?, ?, ?, ?) \\(project_id, user_id, credit_to_type, credit_to_project_id, event_type, event_time, event_metadata) \\VALUES (?, ?, ?, ?, ?, ?, ?) \ - replacement in lib/Aftok/Database/PostgreSQL.hs at line 201
( pid, uid, pid ^. _ProjectId, eventName e, fromThyme $ e ^. eventTime, m)( pid, uid, creditToName c, pid' ^. _ProjectId, eventName e, fromThyme $ e ^. eventTime, m) - replacement in lib/Aftok/Database/PostgreSQL.hs at line 203
CreditToUser uid ->CreditToUser uid' -> - replacement in lib/Aftok/Database/PostgreSQL.hs at line 206
\(project_id, user_id, credit_to_user_id, event_type, event_time, event_metadata) \\VALUES (?, ?, ?, ?, ?, ?) \\(project_id, user_id, credit_to_type, credit_to_user_id, event_type, event_time, event_metadata) \\VALUES (?, ?, ?, ?, ?, ?, ?) \ - replacement in lib/Aftok/Database/PostgreSQL.hs at line 209
( pid, uid, pid ^. _UserId, eventName e, fromThyme $ e ^. eventTime, m)( pid, uid, creditToName c, uid' ^. _UserId, eventName e, fromThyme $ e ^. eventTime, m) - replacement in lib/Aftok/Database/PostgreSQL.hs at line 213
"SELECT project_id, user_id, btc_addr, event_type, event_time, event_metadata FROM work_events \"SELECT project_id, user_id, \\credit_to_type, credit_to_btc_addr, credit_to_user_id, credit_to_project_id, \\event_type, event_time, event_metadata FROM work_events \ - replacement in lib/Aftok/Database/PostgreSQL.hs at line 242
dbEval (AmendEvent (EventId eid) (CreditToChange mt creditTo)) =case creditTo ofdbEval (AmendEvent (EventId eid) (CreditToChange mt c)) =case c of - replacement in lib/Aftok/Database/PostgreSQL.hs at line 249
( eid, fromThyme $ mt ^. _ModTime, "credit_to_address", addr ^. _BtcAddr )( eid, fromThyme $ mt ^. _ModTime, creditToName c, addr ^. _BtcAddr ) - replacement in lib/Aftok/Database/PostgreSQL.hs at line 256
( eid, fromThyme $ mt ^. _ModTime, "credit_to_project", pid ^. _ProjectId )( eid, fromThyme $ mt ^. _ModTime, creditToName c, pid ^. _ProjectId ) - edit in lib/Aftok/Database/PostgreSQL.hs at line 259
pinsert AmendmentId - replacement in lib/Aftok/Database/PostgreSQL.hs at line 263
( eid, fromThyme $ mt ^. _ModTime, "credit_to_user", uid ^. _UserId )( eid, fromThyme $ mt ^. _ModTime, creditToName c, uid ^. _UserId ) - edit in lib/Aftok/Json.hs at line 17
import Data.UUID as U - replacement in lib/Aftok/Json.hs at line 125
creditToJSON (CreditToAddress addr) = v2 $ object [ "creditToAddress" .= addr ]creditToJSON (CreditToUser uid) = v2 $ object [ "creditToUser" .= (uid ^. _UserId) ]creditToJSON (CreditToAddress addr) = v2 $ object [ "creditToAddress" .= (addr ^. _BtcAddr) ]creditToJSON (CreditToUser uid) = v2 $ object [ "creditToUser" .= tshow (uid ^. _UserId) ] - replacement in lib/Aftok/Json.hs at line 130
payoutsJSON (Payouts m) = v1 $toJSON $ (creditToJSON *** id) <$> MS.assocs mpayoutsJSON (Payouts m) = v2 $let payoutsRec :: (CreditTo, Rational) -> ValuepayoutsRec (c, r) = object [ "creditTo" .= creditToJSON c, "payoutRatio" .= r]in toJSON $ fmap payoutsRec (MS.assocs m) - replacement in lib/Aftok/Json.hs at line 137
workIndexJSONV1 :: WorkIndex -> ValueworkIndexJSONV1 (WorkIndex widx) = v1 $toJSON $ (L.toList . fmap intervalJSON) <$>MS.mapKeysMonotonic (^? (_CreditToAddress._BtcAddr)) widxworkIndexJSON :: WorkIndex -> ValueworkIndexJSON (WorkIndex widx) = v2 $let widxRec :: (CreditTo, NonEmpty Interval) -> ValuewidxRec (c, l) = object [ "creditTo" .= creditToJSON c, "intervals" .= (intervalJSON <$> L.toList l)]in toJSON $ fmap widxRec (MS.assocs widx) - replacement in lib/Aftok/Json.hs at line 166
parsePayoutsJSON = unv1 "payouts" $ \v ->Payouts . MS.mapKeys (CreditToAddress . BtcAddr) <$> parseJSON vparsePayoutsJSON = unversion $ \ver -> case ver of(Version 1 _) -> \v -> Payouts . MS.mapKeys (CreditToAddress . BtcAddr) <$> parseJSON v(Version 2 0) -> \v -> doxs <- parseJSON vlet parsePayoutRecord x = (,) <$> (parseCreditTo =<< (x .: "creditTo"))<*> x .: "payoutRatio"Payouts . MS.fromList <$> traverse parsePayoutRecord xs_ -> badVersion "Payouts" ver - replacement in lib/Aftok/Json.hs at line 187
parseA id = fail . show $ "Amendment type " <> id <> " not recognized."parseA tid = fail . show $ "Amendment type " <> tid <> " not recognized." - replacement in lib/Aftok/Json.hs at line 190
parseEventAmendmentV1 t x =parseEventAmendmentV1 _ x = - replacement in lib/Aftok/Json.hs at line 199
parseA id = fail . show $ "Amendment type " <> id <> " not recognized."parseA tid = fail . show $ "Amendment type " <> tid <> " not recognized." - replacement in lib/Aftok/Json.hs at line 202
parseEventAmendmentV2 t x =parseEventAmendmentV2 _ x = - replacement in lib/Aftok/Json.hs at line 212
Version 1 0 -> withObject "BtcAddr" parseCreditToV1Version 1 0 -> withObject "BtcAddr" parseCreditToV1 - edit in lib/Aftok/Json.hs at line 215
parseUUID :: Value -> Parser U.UUIDparseUUID v = dostr <- parseJSON vmaybe (fail $ "Value " <> str <> "Could not be parsed as a valid UUID.") pure $ U.fromString str - replacement in lib/Aftok/Json.hs at line 229
parseCreditToAddr x' = NothingparseCreditToAddr _ = Nothing - replacement in lib/Aftok/Json.hs at line 231
parseCreditToUser (Object x') = NothingparseCreditToUser x' = NothingparseCreditToUser (Object x') = douserText <- O.lookup "creditToUser" x'pure (CreditToUser . UserId <$> parseUUID userText)parseCreditToUser _ = Nothing - replacement in lib/Aftok/Json.hs at line 236
parseCreditToProject (Object x') = NothingparseCreditToProject x' = Nothing--parseCreditToProject (Object x') = NothingparseCreditToProject _ = Nothing - replacement in lib/Aftok/TimeLog.hs at line 6
, CreditTo(..), _CreditToAddress, _CreditToUser, _CreditToProject, CreditTo(..), _CreditToAddress, _CreditToUser, _CreditToProject, creditToName - edit in lib/Aftok/TimeLog.hs at line 68[21.432][4.4696]
creditToName :: CreditTo -> TextcreditToName (CreditToAddress _) = "credit_to_address"creditToName (CreditToUser _) = "credit_to_user"creditToName (CreditToProject _) = "credit_to_project" - replacement in migrations/2016-10-14_02-49-36_event-amendments.txt at line 10
alter table work_events rename column btc_addr to credit_to_btc_addr;alter table work_events rename column btc_addr to credit_to_address;