add touch-databases to ensure db structure is present

This commit is contained in:
Gered 2013-05-20 20:07:11 -04:00
parent 88ce5616e0
commit 78170ceb10
2 changed files with 14 additions and 1 deletions

View file

@ -1,4 +1,5 @@
(ns blarg.models.db
(:use [blarg.util])
(:require [blarg.config :as config]
[com.ashafa.clutch :as couch]))
@ -26,4 +27,16 @@
(defmacro ->first-view-value
"returns only the first value from the sequence returned by running a view"
[& body]
`(first (->view-values ~@body)))
`(first (->view-values ~@body)))
(defn touch-databases
"verifies that the required databases are present, creating them if they
are not there (including the views)."
[]
(couch/get-database users)
(couch/get-database files)
(when (couch/get-database posts)
(couch/with-db posts
(let [doc (couch/get-document "_design/posts")]
(if (nil? doc)
(couch/put-document (load-json "couchdb/design_docs/posts.js")))))))