From 45629d0abb89c77d30f97b0579d744ffea9432a2 Mon Sep 17 00:00:00 2001 From: nek0 Date: Mon, 1 Feb 2021 02:25:08 +0100 Subject: [PATCH] move initDB to library --- src/Util.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Util.hs b/src/Util.hs index 91aba92..b777d2c 100644 --- a/src/Util.hs +++ b/src/Util.hs @@ -7,5 +7,26 @@ import Data.Maybe (fromMaybe) import Data.Profunctor.Product.Default (Default) +import Database.PostgreSQL.Simple + +import Control.Monad (void) + +-- internal imports + +import Model + printSql :: Default Unpackspec a a => Select a -> IO () printSql = putStrLn . fromMaybe "Empty query" . showSqlForPostgres + +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