Improving docker setup & terraform init.
This commit is contained in:
19
src/db.scm
19
src/db.scm
@@ -3,7 +3,7 @@
|
||||
connection-spec
|
||||
|
||||
;;functions
|
||||
with-db with-db/transaction
|
||||
with-db with-db/transaction db-init
|
||||
|
||||
create-user delete-user
|
||||
create-instance get-user-instances
|
||||
@@ -30,13 +30,15 @@
|
||||
(chicken file)
|
||||
(chicken string)
|
||||
(chicken port)
|
||||
(chicken io)
|
||||
postgresql
|
||||
sql-null
|
||||
srfi-1
|
||||
srfi-13
|
||||
(openssl cipher)
|
||||
(openssl random)
|
||||
crypto-tools)
|
||||
crypto-tools
|
||||
spiffy)
|
||||
|
||||
(define connection-spec (make-parameter '((dbname . "nassella") (user . "nassella") (password . "password") (host . "127.0.0.1"))))
|
||||
(define db-connection (make-parameter #f))
|
||||
@@ -525,6 +527,19 @@ returning users.user_id;"
|
||||
""
|
||||
(user-decrypt-from-db (alist-ref 'state_backup_enc res) user-key user-iv user-id)))))))
|
||||
|
||||
(define (db-init)
|
||||
(with-db/transaction
|
||||
(lambda (db)
|
||||
(if (value-at (query db "SELECT EXISTS (SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = 'users');"))
|
||||
#t
|
||||
(begin
|
||||
(log-to (debug-log) "tables not found in db. Creating...")
|
||||
(for-each
|
||||
(lambda (statement)
|
||||
(query db (conc statement ";")))
|
||||
(string-split (with-input-from-file "db-init.sql" read-string) ";"))
|
||||
(log-to (debug-log) "table completion complete"))))))
|
||||
|
||||
;; (with-db/transaction (lambda (db) (get-user-deployments db 1)))
|
||||
;; (with-db/transaction (lambda (db) (get-most-recent-deployment-progress db 7)))
|
||||
;; (with-db/transaction (lambda (db) (get-deployment-progress db 14)))
|
||||
|
||||
Reference in New Issue
Block a user