Skip to content

Commit 1292a23

Browse files
committed
[WIP] part-2 wheel
1 parent cb71b43 commit 1292a23

File tree

6 files changed

+65
-4
lines changed

6 files changed

+65
-4
lines changed

clojure/wheel/dev/user.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(ns user
2+
(:require [wheel.infra.core :refer [start-app stop-app migrate-database] :as infra]
3+
[clojure.tools.namespace.repl :as repl]))
4+
5+
(defn reset []
6+
(stop-app)
7+
(repl/refresh :after 'infra/start-app))

clojure/wheel/project.clj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
:url "https://www.eclipse.org/legal/epl-2.0/"}
66
:dependencies [[org.clojure/clojure "1.10.1"]
77
[aero "1.1.3"]
8-
[mount "0.1.16"]]
8+
[mount "0.1.16"]
9+
[hikari-cp "2.8.0"]
10+
[org.postgresql/postgresql "42.2.6"]
11+
[org.flywaydb/flyway-core "5.2.4"]]
912
:main ^:skip-aot wheel.core
1013
:target-path "target/%s"
11-
:profiles {:uberjar {:aot :all}})
14+
:profiles {:uberjar {:aot :all}
15+
:dev {:source-paths ["dev"]
16+
:dependencies [[org.clojure/tools.namespace "0.3.1"]]}})

clojure/wheel/resources/config.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
{:adapter "postgresql"
44
:username #or [#env "WHEEL_APP_DB_USERNAME" "postgres"]
55
:password #or [#env "WHEEL_APP_DB_PASSWORD" "postgres"]
6-
:database-name #or [#env "WHEEL_APP_DB_NAME" "my_tasks"]
6+
:database-name #or [#env "WHEEL_APP_DB_NAME" "wheel"]
77
:server-name #or [#env "WHEEL_APP_DB_SERVER" "localhost"]
88
:port-number #or [#env "WHEEL_APP_DB_PORT" 5432]}}}

clojure/wheel/src/wheel/core.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
(ns wheel.core
2+
(:require [wheel.infra.core :as infra])
23
(:gen-class))
34

5+
(defn add-shutdown-hook []
6+
(.addShutdownHook (Runtime/getRuntime) (Thread. infra/stop-app)))
7+
48
(defn -main
5-
"I don't do a whole lot ... yet."
69
[& args]
10+
(infra/start-app)
11+
(add-shutdown-hook)
712
(println "Hello, World!"))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(ns wheel.infra.core
2+
(:require [mount.core :as mount]
3+
[wheel.infra.config :as config]
4+
[wheel.infra.database :as db]))
5+
6+
(defn start-app []
7+
(mount/start))
8+
9+
(defn stop-app []
10+
(mount/stop))
11+
12+
(defn migrate-database []
13+
(mount/start #'config/root #'db/datasource)
14+
(db/migrate)
15+
(mount/stop))
16+
17+
(comment
18+
(start-app)
19+
(stop-app)
20+
(migrate-database))
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(ns wheel.infra.database
2+
(:require [wheel.infra.config :as config]
3+
[mount.core :as mount]
4+
[hikari-cp.core :as hikari])
5+
(:import [org.flywaydb.core Flyway]))
6+
7+
(defn- make-datasource []
8+
(hikari/make-datasource (config/database)))
9+
10+
(mount/defstate datasource
11+
:start (make-datasource)
12+
:stop (hikari/close-datasource datasource))
13+
14+
(defn migrate []
15+
(.. (Flyway/configure)
16+
(dataSource datasource)
17+
(locations (into-array String ["classpath:db/migration"]))
18+
load
19+
migrate))
20+
21+
(comment
22+
(mount/start)
23+
(migrate)
24+
(mount/stop))

0 commit comments

Comments
 (0)