Skip to content

Commit

Permalink
Fix disconnect behavior inside Database/init (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ryan committed Nov 21, 2023
1 parent dab29cc commit 042175d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/migratus/database.clj
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@
(.setAutoCommit conn true))
{:connection conn}))

(defn disconnect* [db]
(defn disconnect* [db config]
(when-let [^Connection conn (:connection db)]
(when-not (.isClosed conn)
(when-not (or (.isClosed conn) (:managed-connection? (:db config)))
(.close conn))))

(defn completed-ids* [db table-name]
Expand Down Expand Up @@ -297,7 +297,7 @@
(get config :init-in-transaction? true)
(props/load-properties config))
(finally
(proto/disconnect this)))))
(disconnect* conn config)))))
(completed-ids [this]
(completed-ids* @connection (migration-table-name config)))
(completed [this]
Expand All @@ -322,8 +322,7 @@
(migration-table-name config)
(sql-mig/wrap-modify-sql-fn (:modify-sql-fn config))))
(disconnect [this]
(when-not (:managed-connection? (:db config))
(disconnect* @connection))
(disconnect* @connection config)
(reset! connection nil)))

(defmethod proto/make-store :database
Expand Down

0 comments on commit 042175d

Please sign in to comment.