From b337c5fcb2cfca0454f28add31533a25d70641f2 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 24 Feb 2020 21:15:43 +0000 Subject: [PATCH] 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. --- guix-data-service/database.scm | 9 +++++++++ 1 file changed, 9 insertions(+) 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