Skip to content
Snippets Groups Projects
Commit 2e69c2cc authored by Cam Saül's avatar Cam Saül
Browse files

Merge pull request #201 from metabase/lein_migration-summary

Lein migration summary
parents 5a1638f8 f617f05c
No related branches found
No related tags found
No related merge requests found
......@@ -64,6 +64,11 @@ You can update the GitHub pages documentation using
You should be on the `master` branch without any uncommited local changes before doing so. Also, make sure you've fetched the branch `gh-pages` and can push it back to `origin`.
## Migration Summary
lein migration-summary
Will give you a list of all tables + fields in the Metabase DB.
## Bootstrapping (for Development)
......@@ -80,7 +85,7 @@ You'll be walked through the steps to get started.
You can make API calls from the REPL using `metabase.http-client`:
(use 'metabase.http-client)
(defn cl [& args]
(defn cl [& args]
(-> (apply client {:email "crowberto@metabase.com", :password "blackjet"} args)
clojure.pprint/pprint))
(cl :get "user/current")
......
(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,18 @@
:password (config/config-str :mb-db-pass)
:host (config/config-str :mb-db-host)})))
(defn metabase-db-conn-str
"A connection string that can be used when pretending the Metabase DB is itself a `Database`
(e.g., to use the Generic SQL driver functions on the Metabase DB itself)."
[]
(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