From d8054f185b6e3e84e29886f091eaeac76660b331 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Fri, 29 May 2020 18:22:51 -0400 Subject: [PATCH] Initialize the schema in a transaction It's probably not strictly necessary but it's sort of nice. --- src/PaymentServer/Persistence.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/PaymentServer/Persistence.hs b/src/PaymentServer/Persistence.hs index 04ac899..6f9548f 100644 --- a/src/PaymentServer/Persistence.hs +++ b/src/PaymentServer/Persistence.hs @@ -337,8 +337,9 @@ sqlite path = dbConn <- Sqlite.open (unpack path) let exec = Sqlite.execute_ dbConn exec "PRAGMA foreign_keys = ON" - exec "CREATE TABLE IF NOT EXISTS vouchers (id INTEGER PRIMARY KEY, name TEXT UNIQUE)" - exec "CREATE TABLE IF NOT EXISTS redeemed (id INTEGER PRIMARY KEY, voucher_id INTEGER, counter INTEGER, fingerprint TEXT, FOREIGN KEY (voucher_id) REFERENCES vouchers(id))" - return dbConn + Sqlite.withExclusiveTransaction dbConn $ do + exec "CREATE TABLE IF NOT EXISTS vouchers (id INTEGER PRIMARY KEY, name TEXT UNIQUE)" + exec "CREATE TABLE IF NOT EXISTS redeemed (id INTEGER PRIMARY KEY, voucher_id INTEGER, counter INTEGER, fingerprint TEXT, FOREIGN KEY (voucher_id) REFERENCES vouchers(id))" + return dbConn in return . SQLiteDB $ connect -- GitLab