Skip to content
Snippets Groups Projects
Commit 3baa4cc1 authored by Cam Saul's avatar Cam Saul
Browse files

add `lein migration-summary` command that will list all Tables + fields

in Metabase DB
parent 677b2b1a
No related branches found
No related tags found
No related merge requests found
(ns leiningen.migration-summary
(:require [leiningen.core.eval :as lein]))
(defn migration-summary [project & args]
(lein/eval-in-project
project
`(do
(require '[metabase.config :as ~'config]
'[metabase.db :as ~'db]
'[metabase.driver.generic-sql.sync :as ~'sync])
(let [db# {:engine (name (config/config-kw :mb-db-type))
:details {:conn_str (db/metabase-db-conn-str)}}]
(->> (sync/table-names db#)
(map (fn [table-name#]
(println (format "\n* %s" table-name#))
(->> (sync/jdbc-columns db# table-name#)
(sort-by :column_name)
(map (fn [{:keys [~'type_name ~'column_name]}]
(println (format " * %s %s" ~'column_name ~'type_name))))
dorun)))
dorun)))))
......@@ -55,6 +55,15 @@
:password (config/config-str :mb-db-pass)
:host (config/config-str :mb-db-host)})))
(defn metabase-db-conn-str []
(case (config/config-kw :mb-db-type)
:h2 (db-file)
:postgres (format "host=%s port=%d dbname=%s user=%s password=%s"
(config/config-str :mb-db-host)
(config/config-int :mb-db-port)
(config/config-str :mb-db-dbname)
(config/config-str :mb-db-user)
(config/config-str :mb-db-pass))))
(defn test-db-conn
"Simple test of a JDBC connection."
......
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