From bfc2c52afef9574a6da3b5a2bb64bdbb2e51fc2a Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@leastauthority.com>
Date: Thu, 17 Oct 2019 15:57:26 +0530
Subject: [PATCH] Persistence: create and open the tables

---
 src/PaymentServer/Persistence.hs | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/PaymentServer/Persistence.hs b/src/PaymentServer/Persistence.hs
index d13414d..fb3cb5b 100644
--- a/src/PaymentServer/Persistence.hs
+++ b/src/PaymentServer/Persistence.hs
@@ -140,3 +140,9 @@ getPaidVouchers dbConn = Set.fromList <$>
 getVoucherFingerprint :: Sqlite.Connection -> Voucher -> IO [Fingerprint]
 getVoucherFingerprint dbConn voucher = do
   Sqlite.query dbConn "SELECT redeemed.fingerprint FROM vouchers INNER JOIN redeemed ON vouchers.id = redeemed.voucher_id AND vouchers.name = ?" (Sqlite.Only voucher)
+
+getDBConnection :: Text -> IO ()
+getDBConnection name = do
+  dbConn <- Sqlite.open name
+  Sqlite.execute_ dbConn "CREATE TABLE vouchers (id INTEGER PRIMARY KEY, name TEXT)"
+  Sqlite.execute_ dbConn "CREATE TABLE redeemed (id INTEGER PRIMARY KEY, voucher_id INTEGER, fingerprint TEXT, FOREIGN KEY (voucher_id) REFERENCES vouchers(id))"
-- 
GitLab