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.
This commit is contained in:
parent
33cf8d66f6
commit
42c608e004
3 changed files with 35 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue