aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-02-24 21:15:43 +0000
committerChristopher Baines <mail@cbaines.net>2020-02-24 21:15:43 +0000
commitb337c5fcb2cfca0454f28add31533a25d70641f2 (patch)
tree0827c56aa248b74a4252c65bdeadf636926604d9
parentf57b5c4a9a932f77952585f547671c12d8103b02 (diff)
downloaddata-service-b337c5fcb2cfca0454f28add31533a25d70641f2.tar
data-service-b337c5fcb2cfca0454f28add31533a25d70641f2.tar.gz
Add a function to check if the test database is being used
This helps avoid problems when running the tests, and the test database not being used.
-rw-r--r--guix-data-service/database.scm9
1 files changed, 9 insertions, 0 deletions
diff --git a/guix-data-service/database.scm b/guix-data-service/database.scm
index 257d48b..448f16f 100644
--- a/guix-data-service/database.scm
+++ b/guix-data-service/database.scm
@@ -17,10 +17,13 @@
(define-module (guix-data-service database)
#:use-module (system foreign)
+ #:use-module (ice-9 match)
#:use-module (squee)
#:export (with-postgresql-connection
with-postgresql-transaction
+ check-test-database!
+
with-advisory-session-lock
obtain-advisory-transaction-lock
@@ -63,6 +66,12 @@
(lambda (key . args)
(exec-query conn "ROLLBACK;"))))
+(define (check-test-database! conn)
+ (match (exec-query conn "SELECT current_database()")
+ (((name))
+ (unless (string=? name "guix_data_service_test")
+ (error "tests being run against non test database")))))
+
(define (with-advisory-session-lock conn lock f)
(let ((lock-number (number->string (symbol-hash lock))))
(exec-query conn