diff options
author | Christopher Baines <mail@cbaines.net> | 2019-06-07 07:33:34 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2019-06-07 07:33:34 +0100 |
commit | 42c608e00417a3f57f9c410daca1f84b3f9550bc (patch) | |
tree | f155994d260013ee6b5e0d78c4b27aef1a411fcd /scripts | |
parent | 33cf8d66f6076d0690f286eea7084a36417a6cb2 (diff) | |
download | data-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.
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/guix-data-service.in | 29 |
1 files changed, 26 insertions, 3 deletions
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) |