Skip to content
Snippets Groups Projects
Unverified Commit 2dbd0779 authored by Walter Leibbrandt's avatar Walter Leibbrandt Committed by GitHub
Browse files

Remove fs dep (#12959)

* Remove fs dep

I was about to switch it to the maintained fork at clj-commons/fs, but
found that it's only used once, and where `io/delete-file` would serve
just as well.

* Add some tests for dump-to-h2

* Setup dump target db only if there's something to do

Added test to try and pass cloverage

* Undo move of setup-db! calls

And keep test from mangling real connection state that will be used in
other tests.
parent 726ec841
No related branches found
No related tags found
No related merge requests found
......@@ -105,7 +105,6 @@
javax.jms/jms
com.sun.jdmk/jmxtools
com.sun.jmx/jmxri]]
[me.raynes/fs "1.4.6"] ; Filesystem tools
[medley "1.3.0"] ; lightweight lib of useful functions
[metabase/connection-pool "1.1.1"] ; simple wrapper around C3P0. JDBC connection pools
[metabase/throttle "1.0.2"] ; Tools for throttling access to API endpoints and other code pathways
......
......@@ -12,7 +12,6 @@
[jdbc :as jdbc]]
[clojure.string :as str]
[colorize.core :as color]
[me.raynes.fs :as fs]
[metabase
[db :as mdb]
[util :as u]]
......@@ -99,11 +98,10 @@
Defaults to using `@metabase.db/db-file` as the connection string."
[h2-filename]
(let [h2-filename (or h2-filename "metabase_dump.h2")]
(println "Dumping to " h2-filename)
(doseq [filename [h2-filename
(str h2-filename ".mv.db")]]
(println "Dumping to" h2-filename)
(doseq [filename [h2-filename (str h2-filename ".mv.db")]]
(when (.exists (io/file filename))
(fs/delete filename)
(io/delete-file filename)
(println (u/format-color 'red (trs "Output H2 database already exists: %s, removing.") filename))))
(println "Dumping from configured Metabase db to H2 file" h2-filename)
......
(ns metabase.cmd.dump-to-h2-test
(:require [clojure.java.io :as io]
[clojure.test :refer :all]
[flatland.ordered.map :as ordered-map]
[metabase.cmd.dump-to-h2 :as dump-to-h2]
[metabase.db :as mdb]
[metabase.util.files :as u.files]
[toucan.db :as db]))
(deftest path-test
(testing "works without file: schema"
(is (= {:classname "org.h2.Driver"
:subprotocol "h2"
:subname "file:/path/to/metabase.db"
:type :h2}
(#'dump-to-h2/h2-details "/path/to/metabase.db"))))
(testing "works with file: schema"
(is (= {:classname "org.h2.Driver"
:subprotocol "h2"
:subname "file:/path/to/metabase.db"
:type :h2}
(#'dump-to-h2/h2-details "file:/path/to/metabase.db")))))
(deftest casing-corner-cases-test
(testing "objects->colums+values property handles columns with weird casing: `sizeX` and `sizeY`"
(let [cols+vals (binding [db/*quoting-style* :ansi]
(-> (#'dump-to-h2/objects->colums+values
;; using ordered-map so the results will be in a predictable order
[(ordered-map/ordered-map
:id 281
:row 0
:sizex 18
:sizey 9)])
(update :cols vec)))]
(is (= {:cols ["\"id\"" "\"row\"" "\"sizeX\"" "\"sizeY\""]
:vals [[281 0 18 9]]}
cols+vals)))))
(deftest dump-deletes-target-db-files-tests
(let [tmp-h2-db (str (u.files/get-path (System/getProperty "java.io.tmpdir") "mbtest_dump.h2"))
tmp-h2-db-mv (str tmp-h2-db ".mv.db")
file-contents {tmp-h2-db "Not really an H2 DB"
tmp-h2-db-mv "Not really another H2 DB"}]
;; keep setup-db!/setup-db!* from changing connection state
(with-redefs [mdb/setup-db! (constantly nil)
mdb/setup-db!* (constantly nil)]
(try
(doseq [[filename contents] file-contents]
(spit filename contents))
(dump-to-h2/dump-to-h2! tmp-h2-db)
(doseq [filename (keys file-contents)]
(testing (str filename " was deleted")
(is (false? (.exists (io/file filename))))))
(finally
(doseq [filename (keys file-contents)
:let [file (io/file filename)]]
(when (.exists file)
(io/delete-file file))))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment