summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorMathieu Othacehe <othacehe@gnu.org>2021-01-18 10:25:18 +0100
committerMathieu Othacehe <othacehe@gnu.org>2021-01-28 12:57:26 +0100
commita38d0b0137400b4d54bab5181538fd7eeeefa49a (patch)
tree6f4484af3b6d1f9f8f9e0d49ee28594a373a0e95 /gnu
parentff0ff69315fa2cffa224b6f4b2f879a8e0bdbb89 (diff)
services: postgresql: Use Guile datatypes.
* gnu/services/databases.scm (postgresql-config-file-compiler): Support Guile datatypes in the "extra-config" field. * gnu/tests/databases.scm (%postgresql-os): Test it. * doc/guix.texi (Database Services): Document it.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/services/databases.scm38
-rw-r--r--gnu/tests/databases.scm10
2 files changed, 31 insertions, 17 deletions
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index d2dc5f0da8..bb0e40632e 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -115,22 +115,28 @@ host all all ::1/128 md5"))
(match file
(($ <postgresql-config-file> log-destination hba-file
ident-file extra-config)
- (define (single-quote string)
- (if string
- (list "'" string "'")
- '()))
-
- (define contents
- (append-map
- (match-lambda
- ((key) '())
- ((key . #f) '())
- ((key values ...) `(,key " = " ,@values "\n")))
-
- `(("log_destination" ,@(single-quote log-destination))
- ("hba_file" ,@(single-quote hba-file))
- ("ident_file" ,@(single-quote ident-file))
- ,@extra-config)))
+ ;; See: https://www.postgresql.org/docs/current/config-setting.html.
+ (define (format-value value)
+ (cond
+ ((boolean? value)
+ (list (if value "on" "off")))
+ ((number? value)
+ (list (number->string value)))
+ (else
+ (list "'" value "'"))))
+
+ (define contents
+ (append-map
+ (match-lambda
+ ((key) '())
+ ((key . #f) '())
+ ((key values ...)
+ `(,key " = " ,@(append-map format-value values) "\n")))
+
+ `(("log_destination" ,log-destination)
+ ("hba_file" ,hba-file)
+ ("ident_file" ,ident-file)
+ ,@extra-config)))
(gexp->derivation
"postgresql.conf"
diff --git a/gnu/tests/databases.scm b/gnu/tests/databases.scm
index 31d5ae4c6a..7338007919 100644
--- a/gnu/tests/databases.scm
+++ b/gnu/tests/databases.scm
@@ -218,7 +218,15 @@
(simple-operating-system
(service postgresql-service-type
(postgresql-configuration
- (postgresql postgresql-10)))))
+ (postgresql postgresql-10)
+ (config-file
+ (postgresql-config-file
+ (extra-config
+ '(("session_preload_libraries" "auto_explain")
+ ("random_page_cost" 2)
+ ("auto_explain.log_min_duration" "100 ms")
+ ("work_mem" "500 MB")
+ ("debug_print_plan" #t)))))))))
(define (run-postgresql-test)
"Run tests in %POSTGRESQL-OS."