From a15c075d772942eb796cb3b5d692d49b06e2c93a Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 21 Jul 2019 15:02:59 +0200 Subject: [PATCH] more beauty --- src/Model/Auth.hs | 8 +++++++- src/Model/Product.hs | 20 ++++++++++++++++++-- src/Model/User.hs | 18 +++++++++++++++--- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/Model/Auth.hs b/src/Model/Auth.hs index 461cd75..41abe46 100644 --- a/src/Model/Auth.hs +++ b/src/Model/Auth.hs @@ -49,7 +49,13 @@ import Model.User initToken :: PGS.Query -initToken = "create table if not exists \"token\" (token_string bytea not null primary key, token_user integer references \"user\"(user_id) not null, token_expiry timestamptz not null)" +initToken = foldl (<>) "" $ + [ "create table if not exists \"token\" (" + , "token_string bytea not null primary key," + , "token_user integer references \"user\"(user_id) not null," + , "token_expiry timestamptz not null" + , ")" + ] tokenTable :: Table ( Field SqlBytea diff --git a/src/Model/Product.hs b/src/Model/Product.hs index 604c9e5..6783f1d 100644 --- a/src/Model/Product.hs +++ b/src/Model/Product.hs @@ -4,7 +4,7 @@ module Model.Product where import Servant.Server -import Data.Text as T hiding (head) +import Data.Text as T hiding (head, foldl) import Data.Time.Calendar (Day) import Data.Profunctor.Product (p13) @@ -31,7 +31,23 @@ import Opaleye.Constant as C import Types initProduct :: PGS.Query -initProduct = "create Table if not exists \"product\" (product_id serial primary key, product_ident varchar(128) not null, product_price integer not null, product_amount integer not null, product_vanish integer not null, product_ml integer not null, product_avatar integer, product_supplier integer, product_max_amount integer not null, product_total_bought integer not null, product_amount_per_crate integer not null, product_price_per_crate integer, product_art_nr varchar(128))" +initProduct = foldl (<>) "" $ + [ "create table if not exists \"product\" (" + , "product_id serial primary key," + , "product_ident varchar(128) not null," + , "product_price integer not null," + , "product_amount integer not null," + , "product_vanish integer not null," + , "product_ml integer not null," + , "product_avatar integer," + , "product_supplier integer," + , "product_max_amount integer not null," + , "product_total_bought integer not null," + , "product_amount_per_crate integer not null," + , "product_price_per_crate integer," + , "product_art_nr varchar(128)" + , ")" + ] productTable :: Table ( Maybe (Field SqlInt4) diff --git a/src/Model/User.hs b/src/Model/User.hs index 2848994..a2cb5eb 100644 --- a/src/Model/User.hs +++ b/src/Model/User.hs @@ -3,7 +3,7 @@ {-# LANGUAGE DuplicateRecordFields #-} module Model.User where -import Data.Text as T hiding (head) +import Data.Text as T hiding (head, foldl) import Data.Time.Calendar import Data.Time.Clock @@ -11,7 +11,7 @@ import Data.Profunctor.Product (p9) import Data.Maybe (fromJust, isJust, fromMaybe) -import Data.ByteString hiding (head) +import Data.ByteString hiding (head, foldl) import Data.Int (Int64) @@ -34,7 +34,19 @@ import Types.Auth import Types.Reader initUser :: PGS.Query -initUser = "create table if not exists \"user\" (user_id serial primary key, user_ident varchar(128) not null, user_balance integer not null, user_timestamp date not null, user_email varchar(128), user_avatar integer, user_salt bytea not null, user_hash bytea, user_algo integer)" +initUser = foldl (<>) "" $ + [ "create table if not exists \"user\" (" + , "user_id serial primary key," + , "user_ident varchar(128) not null," + , "user_balance integer not null," + , "user_timestamp date not null," + , "user_email varchar(128)," + , "user_avatar integer," + , "user_salt bytea not null," + , "user_hash bytea," + , "user_algo integer" + , ")" + ] userTable :: Table ( Maybe (Field SqlInt4)