1
0
mirror of https://git.savannah.gnu.org/git/guix.git synced 2026-04-06 21:20:33 +02:00

services: postgresql: Add postgresql-role-service-type.

* gnu/services/databases.scm (postgresql-role,
postgresql-role?, postgresql-role-name,
postgresql-role-permissions, postgresql-role-create-database?,
postgresql-role-configuration, postgresql-role-configuration?,
postgresql-role-configuration-host, postgresql-role-configuration-roles,
postgresql-role-service-type): New procedures.
* gnu/tests/databases.scm: Test it.
* doc/guix.texi: Document it.
This commit is contained in:
Mathieu Othacehe
2021-01-18 11:10:28 +01:00
parent 33687aa3d0
commit ec145a2ff9
3 changed files with 207 additions and 1 deletions

View File

@@ -217,6 +217,9 @@
(define %postgresql-log-directory
"/var/log/postgresql")
(define %role-log-file
"/var/log/postgresql_roles.log")
(define %postgresql-os
(simple-operating-system
(service postgresql-service-type
@@ -229,7 +232,13 @@
("random_page_cost" 2)
("auto_explain.log_min_duration" "100 ms")
("work_mem" "500 MB")
("debug_print_plan" #t)))))))))
("debug_print_plan" #t)))))))
(service postgresql-role-service-type
(postgresql-role-configuration
(roles
(list (postgresql-role
(name "root")
(create-database? #t))))))))
(define (run-postgresql-test)
"Run tests in %POSTGRESQL-OS."
@@ -282,6 +291,39 @@
#t))
marionette))
(test-assert "database ready"
(begin
(marionette-eval
'(begin
(let loop ((i 10))
(unless (or (zero? i)
(and (file-exists? #$%role-log-file)
(string-contains
(call-with-input-file #$%role-log-file
get-string-all)
";\nCREATE DATABASE")))
(sleep 1)
(loop (- i 1)))))
marionette)))
(test-assert "database creation"
(marionette-eval
'(begin
(use-modules (gnu services herd)
(ice-9 popen))
(current-output-port
(open-file "/dev/console" "w0"))
(let* ((port (open-pipe*
OPEN_READ
#$(file-append postgresql "/bin/psql")
"-tAh" "/var/run/postgresql"
"-c" "SELECT 1 FROM pg_database WHERE
datname='root'"))
(output (get-string-all port)))
(close-pipe port)
(string-contains output "1")))
marionette))
(test-end)
(exit (= (test-runner-fail-count (test-runner-current)) 0)))))