diff --git a/resources/couchdb/design docs/posts.js b/resources/couchdb/design_docs/posts.js similarity index 100% rename from resources/couchdb/design docs/posts.js rename to resources/couchdb/design_docs/posts.js diff --git a/src/blarg/models/db.clj b/src/blarg/models/db.clj index 6793707..0e593f9 100644 --- a/src/blarg/models/db.clj +++ b/src/blarg/models/db.clj @@ -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))) \ No newline at end of file + `(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")))))))