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.
This commit is contained in:
Christopher Baines 2020-02-24 21:15:43 +00:00
parent f57b5c4a9a
commit b337c5fcb2
1 changed files with 9 additions and 0 deletions

View File

@ -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