2019-07-21 12:53:00 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2019-07-21 12:40:49 +00:00
|
|
|
module Model.Amount where
|
|
|
|
|
|
|
|
import Data.Profunctor.Product (p5)
|
|
|
|
|
|
|
|
import qualified Database.PostgreSQL.Simple as PGS
|
|
|
|
|
|
|
|
import Opaleye as O
|
|
|
|
import Opaleye.Constant as C
|
|
|
|
|
|
|
|
initAmount :: PGS.Query
|
2019-07-21 14:05:31 +00:00
|
|
|
initAmount = mconcat
|
2019-07-21 12:40:49 +00:00
|
|
|
[ "CREATE TABLE IF NOT EXISTS \"amount\" ("
|
2019-07-21 14:39:23 +00:00
|
|
|
, "amount_product_id BIGINT NOT NULL REFERENCES \"product\"(\"product_id\") ON DELETE CASCADE,"
|
|
|
|
, "amount_timestamp TIMESTAMPTZ NOT NULL,"
|
|
|
|
, "amount_amount INTEGER NOT NULL,"
|
|
|
|
, "amount_price INTEGER NOT NULL,"
|
|
|
|
, "amount_verified BOOLEAN NOT NULL,"
|
|
|
|
, "PRIMARY KEY (amount_product_id, amount_timestamp)"
|
2019-07-21 14:14:18 +00:00
|
|
|
, ")"
|
2019-07-21 12:40:49 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
amountTable :: Table
|
|
|
|
( Field SqlInt4
|
|
|
|
, Field SqlDate
|
|
|
|
, Field SqlInt4
|
|
|
|
, Field SqlInt4
|
|
|
|
, Field SqlBool
|
|
|
|
)
|
|
|
|
( Field SqlInt4
|
|
|
|
, Field SqlDate
|
|
|
|
, Field SqlInt4
|
|
|
|
, Field SqlInt4
|
|
|
|
, Field SqlBool
|
|
|
|
)
|
|
|
|
amountTable = table "amount" (
|
|
|
|
p5
|
2019-07-27 12:05:00 +00:00
|
|
|
( tableField "amount_product_id"
|
2019-07-21 14:39:23 +00:00
|
|
|
, tableField "amount_timestamp"
|
|
|
|
, tableField "amount_amount"
|
|
|
|
, tableField "amount_price"
|
|
|
|
, tableField "amount_verified"
|
2019-07-21 12:40:49 +00:00
|
|
|
)
|
2019-07-21 12:53:00 +00:00
|
|
|
)
|