aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-06-07 07:33:34 +0100
committerChristopher Baines <mail@cbaines.net>2019-06-07 07:33:34 +0100
commit42c608e00417a3f57f9c410daca1f84b3f9550bc (patch)
treef155994d260013ee6b5e0d78c4b27aef1a411fcd
parent33cf8d66f6076d0690f286eea7084a36417a6cb2 (diff)
downloaddata-service-42c608e00417a3f57f9c410daca1f84b3f9550bc.tar
data-service-42c608e00417a3f57f9c410daca1f84b3f9550bc.tar.gz
Add a --update-database option
This runs Sqitch on startup, which should make managing the database easier, as you just have to restart the service with this option, and the database should be updated if necessary.
-rw-r--r--configure.ac2
-rw-r--r--guix-data-service/config.scm.in8
-rw-r--r--scripts/guix-data-service.in29
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)