diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | guix-data-service/config.scm.in | 8 | ||||
-rw-r--r-- | scripts/guix-data-service.in | 29 |
3 files changed, 35 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac index 225e894..ccf2071 100644 --- a/configure.ac +++ b/configure.ac @@ -35,6 +35,8 @@ guilemoduledir="${datarootdir}/guile/site/${GUILE_EFFECTIVE_VERSION}" AC_SUBST([guilemoduledir]) AC_SUBST([GUILE_EFFECTIVE_VERSION]) +AC_PATH_PROG([sqitch], [sqitch]) + dnl Substitute placeholders to generate these target files AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([guix-data-service/config.scm]) diff --git a/guix-data-service/config.scm.in b/guix-data-service/config.scm.in index d2e699b..ad6452a 100644 --- a/guix-data-service/config.scm.in +++ b/guix-data-service/config.scm.in @@ -30,6 +30,12 @@ ;; TODO: use @assetsdir@ variable here "@prefix@/share/guix-data-service/assets"))) (host . "localhost") - (port . 8765)))) + (port . 8765) + + (sqitch . "@sqitch@") + + (database-user . "guix_data_service") + (database-host . "localhost") + (database-name . "guix_data_service")))) (lambda (key) (assoc-ref config key)))) diff --git a/scripts/guix-data-service.in b/scripts/guix-data-service.in index fd8b7ce..9e91436 100644 --- a/scripts/guix-data-service.in +++ b/scripts/guix-data-service.in @@ -26,6 +26,7 @@ (use-modules (srfi srfi-1) (srfi srfi-37) (system repl server) + (guix-data-service config) (guix-data-service web server)) (define %default-repl-server-port @@ -42,11 +43,15 @@ (if port (alist-cons 'listen-repl port (alist-delete 'listen-repl result)) - (error "invalid REPL server port" arg))))))) + (error "invalid REPL server port" arg))))) + (option '("update-database") #f #f + (lambda (opt name _ result) + (alist-cons 'update-database #t result))))) (define %default-options ;; Alist of default option values - `((listen-repl . #f))) + `((listen-repl . #f) + (update-database . #f))) (define (parse-options args) (args-fold @@ -60,6 +65,24 @@ (let ((opts (parse-options (cdr (program-arguments))))) (let ((repl-port (assoc-ref opts 'listen-repl))) (when repl-port - (spawn-server (make-tcp-server-socket #:port repl-port))))) + (spawn-server (make-tcp-server-socket #:port repl-port)))) + + (when (assoc-ref opts 'update-database) + (let ((command + (list (%config 'sqitch) + "deploy" + (string-append "db:pg://" + (%config 'database-user) + "@" + (%config 'database-host) + "/" + (%config 'database-name))))) + (simple-format #t "running command: ~A\n" + (string-join command)) + (unless (zero? (apply system* command)) + (simple-format + (current-error-port) + "error: sqitch command failed\n") + (exit 1))))) (start-guix-data-service-web-server 8765) |