Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from rtacconi/master
Fix several errors
- Loading branch information
Showing
5 changed files
with
41 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
web: lein trampoline run | ||
web: java $JVM_OPTS -jar target/shouter-standalone.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
(defproject shouter "0.0.1" | ||
(defproject shouter "0.0.2" | ||
:description "Shouter app" | ||
:url "http://github.com/abedra/shouter" | ||
:url "https://github.com/technomancy/shouter" | ||
:min-lein-version "2.0.0" | ||
:license {:name "Eclipse Public License" | ||
:url "http://www.eclipse.org/legal/epl-v10.html"} | ||
:dependencies [[org.clojure/clojure "1.4.0"] | ||
[org.clojure/java.jdbc "0.2.3"] | ||
[postgresql "9.1-901.jdbc4"] | ||
[ring/ring-jetty-adapter "1.1.6"] | ||
[compojure "1.1.3"] | ||
[hiccup "1.0.2"]] | ||
:main shouter.core | ||
:aot [shouter.core]) | ||
:dependencies [[org.clojure/clojure "1.7.0"] | ||
[org.clojure/java.jdbc "0.4.1"] | ||
[org.postgresql/postgresql "9.4-1201-jdbc41"] | ||
[ring/ring-jetty-adapter "1.4.0"] | ||
[compojure "1.4.0"] | ||
[ring/ring-defaults "0.1.2"] | ||
[hiccup "1.0.5"]] | ||
:main ^:skip-aot shouter.core | ||
:uberjar-name "shouter-standalone.jar" | ||
:plugins [[lein-ring "0.8.13"]] | ||
:ring {:handler shouter.web/application | ||
:init shouter.models.migration/migrate} | ||
:profiles {:dev {:dependencies [[javax.servlet/servlet-api "2.5"] | ||
[ring-mock "0.1.5"]]} | ||
:uberjar {:aot :all}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,3 @@ | |
(schema/migrate) | ||
(let [port (Integer/parseInt (or (System/getenv "PORT") "8080"))] | ||
(start port))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
(ns shouter.models.migration | ||
(:require [clojure.java.jdbc :as sql])) | ||
(:require [clojure.java.jdbc :as sql] | ||
[shouter.models.shout :as shout])) | ||
|
||
(defn migrated? [] | ||
(not (zero? | ||
(sql/with-connection (System/getenv "DATABASE_URL") | ||
(sql/with-query-results results | ||
["select count(*) from information_schema.tables where table_name='shouts'"] | ||
(:count (first results))))))) | ||
(-> (sql/query shout/spec | ||
[(str "select count(*) from information_schema.tables " | ||
"where table_name='shouts'")]) | ||
first :count pos?)) | ||
|
||
(defn migrate [] | ||
(when (not (migrated?)) | ||
(print "Creating database structure...") (flush) | ||
(sql/with-connection (System/getenv "DATABASE_URL") | ||
(sql/create-table :shouts | ||
[:id :serial "PRIMARY KEY"] | ||
[:body :varchar "NOT NULL"] | ||
[:created_at :timestamp "NOT NULL" "DEFAULT CURRENT_TIMESTAMP"])) | ||
(println " done"))) | ||
(sql/db-do-commands shout/spec | ||
(sql/create-table-ddl | ||
:shouts | ||
[:id :serial "PRIMARY KEY"] | ||
[:body :varchar "NOT NULL"] | ||
[:created_at :timestamp | ||
"NOT NULL" "DEFAULT CURRENT_TIMESTAMP"])) | ||
(println " done"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
(ns shouter.models.shout | ||
(:require [clojure.java.jdbc :as sql])) | ||
(:require [clojure.java.jdbc :as sql])) | ||
|
||
(defn all [] | ||
(sql/with-connection (System/getenv "DATABASE_URL") | ||
(sql/with-query-results results | ||
["select * from shouts order by id desc"] | ||
(into [] results)))) | ||
(def spec (or (System/getenv "DATABASE_URL") | ||
"postgresql://localhost:5432/shouter")) | ||
|
||
(defn create [shout] | ||
(sql/with-connection (System/getenv "DATABASE_URL") | ||
(sql/insert-values :shouts [:body] [shout]))) | ||
(defn all [] | ||
(into [] (sql/query spec ["select * from shouts order by id desc"]))) | ||
|
||
(defn create [shout] | ||
(sql/insert! spec :shouts [:body] [shout])) |