2019-10-22 01:01:15 +00:00
|
|
|
{-# LANGUAGE FlexibleContexts #-}
|
|
|
|
module Util where
|
|
|
|
|
|
|
|
import Opaleye
|
|
|
|
|
2019-12-12 02:15:56 +00:00
|
|
|
import Data.Maybe (fromMaybe)
|
2019-10-22 01:01:15 +00:00
|
|
|
|
|
|
|
import Data.Profunctor.Product.Default (Default)
|
|
|
|
|
2021-02-01 01:25:08 +00:00
|
|
|
import Database.PostgreSQL.Simple
|
|
|
|
|
|
|
|
import Control.Monad (void)
|
|
|
|
|
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Model
|
|
|
|
|
2019-10-22 01:01:15 +00:00
|
|
|
printSql :: Default Unpackspec a a => Select a -> IO ()
|
2019-12-12 02:15:56 +00:00
|
|
|
printSql = putStrLn . fromMaybe "Empty query" . showSqlForPostgres
|
2021-02-01 01:25:08 +00:00
|
|
|
|
|
|
|
initDB :: Connection -> IO ()
|
|
|
|
initDB conn = do
|
|
|
|
execute_ conn initAvatar
|
|
|
|
execute_ conn initUser
|
|
|
|
execute_ conn initProduct
|
|
|
|
execute_ conn initToken
|
|
|
|
execute_ conn initAuthData
|
|
|
|
execute_ conn initAmount
|
|
|
|
execute_ conn initJournal
|
|
|
|
execute_ conn initRole
|
|
|
|
execute_ conn initUserToRole
|
|
|
|
void $ runInsertInitialRoles conn
|
2021-06-24 04:33:05 +00:00
|
|
|
|
|
|
|
-- This is only a dummy function.
|
|
|
|
-- TODO: Replace with proper translation function(s)!
|
|
|
|
__ = id
|