<commit_before>{-# LANGUAGE CPP #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Bead.Persistence.SQL.Entities where

import           Control.Monad.Logger
import           Control.Monad.Trans.Resource
import           Data.ByteString.Char8 (ByteString)
import           Data.Maybe
import           Data.Text (Text)
import qualified Data.Text as Text
import           Data.Time hiding (TimeZone)

import           Database.Persist.Sql
import           Database.Persist.TH

import qualified Bead.Domain.Entities as Domain

#ifdef TEST
import           Database.Persist.Sqlite
#endif

-- String represents a JSON value
type JSONText = String

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|

Assessment
  description Text
  evalConfig  JSONText
  deriving Show

Assignment
  name        Text
  description Text
  type        JSONText
  start       UTCTime
  end         UTCTime
  created     UTCTime
  evalConfig  JSONText
  deriving Show

Comment
  text   Text
  author Text
  date   UTCTime
  type   JSONText
  deriving Show

Course
  name        Text
  description Text
  testScriptType JSONText
  deriving Show

Evaluation
  result  JSONText
  written Text
  deriving Show

Feedback
  info JSONText
  date UTCTime
  deriving Show

Group
  name        Text
  description Text
  deriving Show

Notification
  message     Text
  deriving Show

Score
  score JSONText
  deriving Show

Submission
  simple   Text       Maybe
  zipped   ByteString Maybe
  postDate UTCTime
  deriving Show

TestCase
  name         Text
  description  Text
  simpleValue  Text       Maybe
  zippedValue  ByteString Maybe
  info         Text
  deriving Show

TestScript
  name        Text
  description Text
  notes       Text
  script      Text
  testScriptType JSONText
  deriving Show

User
  role     JSONText
  username Text
  email    Text
  name     Text
  timeZone JSONText
  language Text
  uid      Text
  UniqueUsername username
  deriving Show
<commit_msg>Use longblob type for Zip values.<commit_after>{-# LANGUAGE CPP #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Bead.Persistence.SQL.Entities where

import           Control.Monad.Logger
import           Control.Monad.Trans.Resource
import           Data.ByteString.Char8 (ByteString)
import           Data.Maybe
import           Data.Text (Text)
import qualified Data.Text as Text
import           Data.Time hiding (TimeZone)

import           Database.Persist.Sql
import           Database.Persist.TH

import qualified Bead.Domain.Entities as Domain

#ifdef TEST
import           Database.Persist.Sqlite
#endif

-- String represents a JSON value
type JSONText = String

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|

Assessment
  description Text
  evalConfig  JSONText
  deriving Show

Assignment
  name        Text
  description Text
  type        JSONText
  start       UTCTime
  end         UTCTime
  created     UTCTime
  evalConfig  JSONText
  deriving Show

Comment
  text   Text
  author Text
  date   UTCTime
  type   JSONText
  deriving Show

Course
  name        Text
  description Text
  testScriptType JSONText
  deriving Show

Evaluation
  result  JSONText
  written Text
  deriving Show

Feedback
  info JSONText
  date UTCTime
  deriving Show

Group
  name        Text
  description Text
  deriving Show

Notification
  message     Text
  deriving Show

Score
  score JSONText
  deriving Show

Submission
  simple   Text       Maybe
  zipped   ByteString Maybe sqltype=longblob
  postDate UTCTime
  deriving Show

TestCase
  name         Text
  description  Text
  simpleValue  Text       Maybe
  zippedValue  ByteString Maybe sqltype=longblob
  info         Text
  deriving Show

TestScript
  name        Text
  description Text
  notes       Text
  script      Text
  testScriptType JSONText
  deriving Show

User
  role     JSONText
  username Text
  email    Text
  name     Text
  timeZone JSONText
  language Text
  uid      Text
  UniqueUsername username
  deriving Show

{'fraction_non_alphanumeric': 0.048337707786526685, 'fraction_numerical': 0.0004374453193350831, 'mean_word_length': 2.603624901497242, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2475229', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1398, 'n_words': 423}