use different profile resource-paths to include dev/prod site.configs

this also necessitated a change to how the couchdb table defs are
defined as aot-ing the prod profile caused code to get evaluated
which triggered at-compile-time-loading of site.config, which at that
point the prod resources-paths would not have been merged in causing
compilation errors
This commit is contained in:
Gered 2014-04-04 23:28:51 -04:00
parent 95540f0e72
commit a055c6e2ef
8 changed files with 60 additions and 41 deletions

View file

@ -0,0 +1,2 @@
{:env "DEV"
:database {:url "http://couchdb:5984/"}}

View file

@ -25,10 +25,12 @@
:destroy blarg.handler/destroy} :destroy blarg.handler/destroy}
:profiles :profiles
{:uberjar {:aot :all} {:uberjar {:aot :all}
:production {:ring {:open-browser? false :production {:ring {:open-browser? false
:stacktraces? false :stacktraces? false
:auto-reload? false}} :auto-reload? false}
:dev {:dependencies [[ring-mock "0.1.5"] :resource-paths ["env-resources/prod"]}
[ring/ring-devel "1.2.1"]] :dev {:dependencies [[ring-mock "0.1.5"]
:source-paths ["dev"]}} [ring/ring-devel "1.2.1"]]
:source-paths ["dev"]
:resource-paths ["env-resources/dev"]}}
:min-lein-version "2.0.0") :min-lein-version "2.0.0")

View file

@ -47,10 +47,10 @@
:params {:errorInfo e} :params {:errorInfo e}
:status 500))))) :status 500)))))
(defonce routes (find-routes "blarg.routes." app-routes)) (def routes (find-routes "blarg.routes." app-routes))
(defonce app (app-handler (def app (app-handler
routes routes
:middleware [wrap-exceptions wrap-servlet-context-path] :middleware [wrap-exceptions wrap-servlet-context-path]
:access-rules [{:redirect "/unauthorized" :rule auth-required}] :access-rules [{:redirect "/unauthorized" :rule auth-required}]
:formats [:json-kw :edn])) :formats [:json-kw :edn]))

View file

@ -14,9 +14,24 @@
:password pass) :password pass)
(cemerick.url/url url db)))) (cemerick.url/url url db))))
(def users (db-url "blarg_users")) (defmacro with-db [url & body]
(def posts (db-url "blarg_posts")) `(couch/with-db
(def files (db-url "blarg_files")) ~url
~@body))
(defn get-users-db []
(db-url "blarg_users"))
(defn get-posts-db []
(db-url "blarg_posts"))
(defn get-files-db []
(db-url "blarg_files"))
(defmacro with-users-db [& body]
`(with-db (get-users-db) ~@body))
(defmacro with-posts-db [& body]
`(with-db (get-posts-db) ~@body))
(defmacro with-files-db [& body]
`(with-db (get-files-db) ~@body))
(defmacro ->view-keys (defmacro ->view-keys
"returns a sequence of only the keys returned by running a view" "returns a sequence of only the keys returned by running a view"
@ -48,8 +63,8 @@
"verifies that the required databases are present, creating them if they "verifies that the required databases are present, creating them if they
are not there (including the views)." are not there (including the views)."
[] []
(couch/get-database users) (couch/get-database (get-users-db))
(when (couch/get-database files) (when (couch/get-database (get-files-db))
(touch-design-doc files "_design/files" "couchdb/design_docs/files.js")) (touch-design-doc (get-files-db) "_design/files" "couchdb/design_docs/files.js"))
(when (couch/get-database posts) (when (couch/get-database (get-posts-db))
(touch-design-doc posts "_design/posts" "couchdb/design_docs/posts.js"))) (touch-design-doc (get-posts-db) "_design/posts" "couchdb/design_docs/posts.js")))

View file

@ -7,7 +7,7 @@
(defn file-exists? [file] (defn file-exists? [file]
(let [f (ensure-prefix file "/")] (let [f (ensure-prefix file "/")]
(couch/with-db files (with-files-db
(not (zero? (count (couch/get-view "files" "listPublished" {:key f}))))))) (not (zero? (count (couch/get-view "files" "listPublished" {:key f})))))))
(defn get-file (defn get-file
@ -15,7 +15,7 @@
([file allow-unpublished?] ([file allow-unpublished?]
(let [f (ensure-prefix file "/") (let [f (ensure-prefix file "/")
view-name (if allow-unpublished? "listAll" "listPublished")] view-name (if allow-unpublished? "listAll" "listPublished")]
(couch/with-db files (with-files-db
(if-let [file-info (->first-view-value (if-let [file-info (->first-view-value
(couch/get-view "files" view-name {:key f}))] (couch/get-view "files" view-name {:key f}))]
(let [id (:_id file-info) (let [id (:_id file-info)
@ -30,7 +30,7 @@
(defn list-files [path] (defn list-files [path]
(let [p (ensure-prefix-suffix path "/")] (let [p (ensure-prefix-suffix path "/")]
(if-let [file-list (->view-values (if-let [file-list (->view-values
(couch/with-db files (with-files-db
(couch/get-view "files" "listAllByPath" {:key p})))] (couch/get-view "files" "listAllByPath" {:key p})))]
(map (map
(fn [f] (fn [f]
@ -45,11 +45,11 @@
(defn get-tree [] (defn get-tree []
(->view-keys (->view-keys
(couch/with-db files (with-files-db
(couch/get-view "files" "listPaths" {:group true})))) (couch/get-view "files" "listPaths" {:group true}))))
(defn add-file [path filename file content-type] (defn add-file [path filename file content-type]
(couch/with-db files (with-files-db
(let [p (ensure-prefix-suffix path "/") (let [p (ensure-prefix-suffix path "/")
id (str p filename)] id (str p filename)]
(if-let [doc (couch/put-document {:_id id (if-let [doc (couch/put-document {:_id id
@ -60,7 +60,7 @@
(couch/put-attachment doc file :filename filename :mime-type content-type))))) (couch/put-attachment doc file :filename filename :mime-type content-type)))))
(defn update-file [id file content-type] (defn update-file [id file content-type]
(couch/with-db files (with-files-db
(if-let [doc (couch/get-document id)] (if-let [doc (couch/get-document id)]
(let [filename (:filename doc) (let [filename (:filename doc)
attachment (second (first (:_attachments doc)))] attachment (second (first (:_attachments doc)))]
@ -70,13 +70,13 @@
(defn delete-file [id] (defn delete-file [id]
(let [safe-id (ensure-prefix id "/")] (let [safe-id (ensure-prefix id "/")]
(couch/with-db files (with-files-db
(if-let [doc (couch/get-document safe-id)] (if-let [doc (couch/get-document safe-id)]
(couch/delete-document doc))))) (couch/delete-document doc)))))
(defn publish-file [id publish?] (defn publish-file [id publish?]
(let [safe-id (ensure-prefix id "/")] (let [safe-id (ensure-prefix id "/")]
(couch/with-db files (with-files-db
(if-let [doc (couch/get-document safe-id)] (if-let [doc (couch/get-document safe-id)]
(couch/update-document (-> doc (couch/update-document (-> doc
(assoc :last_modified_at (get-timestamp)) (assoc :last_modified_at (get-timestamp))

View file

@ -48,19 +48,19 @@
(defn get-post [id] (defn get-post [id]
(merge-cached-post-md! (merge-cached-post-md!
(->single-post (->single-post
(couch/with-db posts (with-posts-db
(couch/get-document id))))) (couch/get-document id)))))
(defn get-post-by-date-slug [date slug] (defn get-post-by-date-slug [date slug]
(merge-cached-post-md! (merge-cached-post-md!
(->single-post (->single-post
(couch/with-db posts (with-posts-db
(couch/get-view "posts" "listPostsBySlug" {:key [date, slug]}))))) (couch/get-view "posts" "listPostsBySlug" {:key [date, slug]})))))
(defn add-post [title body user tags] (defn add-post [title body user tags]
(merge-cached-post-md! (merge-cached-post-md!
(->single-post (->single-post
(couch/with-db posts (with-posts-db
(couch/put-document (couch/put-document
{:title title {:title title
:slug (->slug title) :slug (->slug title)
@ -76,7 +76,7 @@
(if-let [post (get-post id)] (if-let [post (get-post id)]
(merge-cached-post-md! (merge-cached-post-md!
(->single-post (->single-post
(couch/with-db posts (with-posts-db
(couch/update-document (couch/update-document
(-> (date->string post timestamp-fields) (-> (date->string post timestamp-fields)
(merge (if title {:title title :slug (->slug title)})) (merge (if title {:title title :slug (->slug title)}))
@ -89,7 +89,7 @@
(defn delete-post [id] (defn delete-post [id]
(when-let [post (get-post id)] (when-let [post (get-post id)]
(couch/with-db posts (with-posts-db
(couch/delete-document post)) (couch/delete-document post))
(remove-cached-post! post) (remove-cached-post! post)
post)) post))
@ -99,7 +99,7 @@
(defn list-tags [] (defn list-tags []
(->view-keys (->view-keys
(couch/with-db posts (with-posts-db
(couch/get-view "posts" "listTags" {:group true})))) (couch/get-view "posts" "listTags" {:group true}))))
(defn list-posts (defn list-posts
@ -114,13 +114,13 @@
(map (map
merge-cached-post-md! merge-cached-post-md!
(->post-list (->post-list
(couch/with-db posts (with-posts-db
(couch/get-view "posts" viewName params))))))) (couch/get-view "posts" viewName params)))))))
(defn list-posts-by-tag [unpublished? tag] (defn list-posts-by-tag [unpublished? tag]
(let [view-name (if unpublished? "listPostsByTag" "listPublishedPostsByTag")] (let [view-name (if unpublished? "listPostsByTag" "listPublishedPostsByTag")]
(if-let [posts (->post-list (if-let [posts (->post-list
(couch/with-db posts (with-posts-db
(couch/get-view "posts" view-name {:key tag (couch/get-view "posts" view-name {:key tag
:descending true})))] :descending true})))]
;TODO: look into couchdb partial key matching to do this sort at the DB ;TODO: look into couchdb partial key matching to do this sort at the DB
@ -129,7 +129,7 @@
(defn list-posts-archive [unpublished?] (defn list-posts-archive [unpublished?]
(let [view-name (if unpublished? "listPostsArchive" "listPublishedPostsArchive")] (let [view-name (if unpublished? "listPostsArchive" "listPublishedPostsArchive")]
(if-let [posts (->post-list (if-let [posts (->post-list
(couch/with-db posts (with-posts-db
(couch/get-view "posts" view-name {:descending true})))] (couch/get-view "posts" view-name {:descending true})))]
(map (map
#(assoc % :mmyyyy (->nicer-month-year-str (:mmyyyy %))) #(assoc % :mmyyyy (->nicer-month-year-str (:mmyyyy %)))
@ -138,7 +138,7 @@
(defn count-posts (defn count-posts
[unpublished?] [unpublished?]
(->first-view-value (->first-view-value
(couch/with-db posts (with-posts-db
(couch/get-view (couch/get-view
"posts" "posts"
(if unpublished? "countPosts" "countPublishedPosts") (if unpublished? "countPosts" "countPublishedPosts")

View file

@ -6,7 +6,7 @@
(defn get-user (defn get-user
([id] ([id]
(couch/with-db users (with-users-db
(couch/get-document id))) (couch/get-document id)))
([id pass] ([id pass]
(if-let [user (get-user id)] (if-let [user (get-user id)]
@ -18,10 +18,10 @@
:password (crypt/encrypt pass) :password (crypt/encrypt pass)
:email email :email email
:created_at (get-timestamp)}] :created_at (get-timestamp)}]
(couch/with-db users (with-users-db
(couch/put-document user)))) (couch/put-document user))))
(defn delete-user [id] (defn delete-user [id]
(couch/with-db users (with-users-db
(if-let [user (get-user id)] (if-let [user (get-user id)]
(couch/delete-document user)))) (couch/delete-document user))))