diff --git a/Model.hs b/Model.hs index 353bafb..f6820d4 100644 --- a/Model.hs +++ b/Model.hs @@ -3,6 +3,8 @@ module Model where import ClassyPrelude.Yesod import Database.Persist.Quasi +import PersistSHA1 + -- You can define all of your database entities in the entities file. -- You can find more information on persistent and how to declare entities -- at: diff --git a/PersistSHA1.hs b/PersistSHA1.hs new file mode 100644 index 0000000..a25e766 --- /dev/null +++ b/PersistSHA1.hs @@ -0,0 +1,23 @@ +module PersistSHA1 where + +import ClassyPrelude.Yesod +import Database.Persist.Sql + +import qualified Data.ByteString as B +import qualified Data.ByteString.Char8 as BC +import Numeric (showHex) + +data SHA1 = SHA1 ByteString + deriving Show + +toHex :: ByteString -> ByteString +toHex = BC.pack . concat . (map (flip showHex "")) . B.unpack + +instance PersistField SHA1 where + toPersistValue (SHA1 t) = PersistDbSpecific t + + fromPersistValue (PersistDbSpecific t) = Right $ SHA1 $ B.concat ["E'\\x", toHex(t), "'"] + fromPersistValue _ = Left "SHA1 values must be converted from PersistDbSpecific" + +instance PersistFieldSql SHA1 where + sqlType _ = SqlOther "BYTEA" diff --git a/config/models b/config/models index cd7d6ca..d6a4947 100644 --- a/config/models +++ b/config/models @@ -8,5 +8,27 @@ Email user UserId Maybe verkey Text Maybe UniqueEmail email - - -- By default this file is used in Model.hs (which is imported by Foundation.hs) +Repo + url Text + branch Text + currentCommit SHA1 + owner UserId + ready Bool default=False + stamp UTCTime default=now() + UniqueUrlBranch url branch + deriving Show +Challenge + publicRepo RepoId + privateRepo RepoId + name Text + UniqueName name + title Text + description Text + stamp UTCTime default=now() +Test + challenge ChallengeId + checksum SHA1 + commit SHA1 + active Bool default=True + UniqueChallengeChecksum challenge checksum +-- By default this file is used in Model.hs (which is imported by Foundation.hs) diff --git a/gonito.cabal b/gonito.cabal index 5145464..36e3c8a 100644 --- a/gonito.cabal +++ b/gonito.cabal @@ -18,6 +18,7 @@ library Import Import.NoFoundation Model + PersistSHA1 Settings Settings.StaticFiles SharedTypes