File tree Expand file tree Collapse file tree 6 files changed +65
-4
lines changed Expand file tree Collapse file tree 6 files changed +65
-4
lines changed Original file line number Diff line number Diff line change
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))
Original file line number Diff line number Diff line change 5
5
:url " https://www.eclipse.org/legal/epl-2.0/" }
6
6
:dependencies [[org.clojure/clojure " 1.10.1" ]
7
7
[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" ]]
9
12
:main ^:skip-aot wheel.core
10
13
: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" ]]}})
Original file line number Diff line number Diff line change 3
3
{:adapter " postgresql"
4
4
:username #or [#env " WHEEL_APP_DB_USERNAME" " postgres" ]
5
5
: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 " ]
7
7
:server-name #or [#env " WHEEL_APP_DB_SERVER" " localhost" ]
8
8
:port-number #or [#env " WHEEL_APP_DB_PORT" 5432 ]}}}
Original file line number Diff line number Diff line change 1
1
(ns wheel.core
2
+ (:require [wheel.infra.core :as infra])
2
3
(:gen-class ))
3
4
5
+ (defn add-shutdown-hook []
6
+ (.addShutdownHook (Runtime/getRuntime ) (Thread. infra/stop-app)))
7
+
4
8
(defn -main
5
- " I don't do a whole lot ... yet."
6
9
[& args]
10
+ (infra/start-app )
11
+ (add-shutdown-hook )
7
12
(println " Hello, World!" ))
Original file line number Diff line number Diff line change
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 ))
Original file line number Diff line number Diff line change
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 ))
You can’t perform that action at this time.
0 commit comments