From e398b337d46774ee98e09a2f013388b0bf939fa9 Mon Sep 17 00:00:00 2001 From: gered Date: Mon, 20 May 2013 20:12:30 -0400 Subject: [PATCH] refactor touch-databases a bit, add code to create files db design doc --- src/blarg/models/db.clj | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/blarg/models/db.clj b/src/blarg/models/db.clj index 0e593f9..102f60a 100644 --- a/src/blarg/models/db.clj +++ b/src/blarg/models/db.clj @@ -29,14 +29,21 @@ [& body] `(first (->view-values ~@body))) +(defn touch-design-doc + "verifies that a design doc is present in the given db, creating it if + it is not there" + [db design-doc-id doc-js-path] + (couch/with-db db + (let [doc (couch/get-document design-doc-id)] + (if (nil? doc) + (couch/put-document (load-json doc-js-path)))))) + (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 files) + (touch-design-doc posts "_design/files" "couchdb/design_docs/files.js")) (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"))))))) + (touch-design-doc posts "_design/posts" "couchdb/design_docs/posts.js")))