From 78170ceb10ed659a3a89865410b929e5a13a58fa Mon Sep 17 00:00:00 2001 From: gered Date: Mon, 20 May 2013 20:07:11 -0400 Subject: [PATCH] add touch-databases to ensure db structure is present --- .../couchdb/{design docs => design_docs}/posts.js | 0 src/blarg/models/db.clj | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) rename resources/couchdb/{design docs => design_docs}/posts.js (100%) 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")))))))