diff --git a/resources/log4j.properties b/resources/log4j.properties index e6d168cbff584a30e28e57663fe782235f6b905d..b9812c7f7cbbbfe90293325da7a57e8f812f57e6 100644 --- a/resources/log4j.properties +++ b/resources/log4j.properties @@ -18,7 +18,6 @@ log4j.appender.metabase=metabase.logger.Appender # customizations to logging by package log4j.logger.metabase=INFO -log4j.logger.metabase.db=DEBUG log4j.logger.metabase.driver=DEBUG log4j.logger.metabase.query-processor=DEBUG log4j.logger.metabase.sync-database=DEBUG diff --git a/src/metabase/cmd/load_from_h2.clj b/src/metabase/cmd/load_from_h2.clj index 42c27fbdbc906108a7164207f3d516ec9e7c839c..326eff4eaa558a9375d127353cc88205dfdc91d4 100644 --- a/src/metabase/cmd/load_from_h2.clj +++ b/src/metabase/cmd/load_from_h2.clj @@ -32,7 +32,8 @@ [table :refer [Table]] [user :refer [User]] [view-log :refer [ViewLog]]) - [metabase.util :as u])) + [metabase.util :as u] + [clojure.set :as set])) (def ^:private entities "Entities in the order they should be serialized/deserialized. @@ -67,6 +68,27 @@ Label CardLabel]) +(defn- insert-entity [e objs] + (print (u/format-color 'blue "Transfering %d instances of %s..." (count objs) (:name e))) + (flush) + ;; The connection closes prematurely on occasion when we're inserting thousands of rows at once. Break into smaller chunks so connection stays alive + (doseq [chunk (partition-all 300 objs)] + (print (color/blue \.)) + (flush) + (k/insert e (k/values chunk))) + (println (color/green "[OK]"))) + +(defn- insert-self-referencing-entity [e objs] + (let [self-ref-attr (condp = e + RawColumn :fk_target_column_id + Field :fk_target_field_id) + self-referencing (filter self-ref-attr objs) + others (set/difference (set objs) (set self-referencing))] + ;; first insert the non-self-referencing objects + (insert-entity e others) + ;; then insert the rest, which should be safe to insert now + (insert-entity e self-referencing))) + (defn load-from-h2 "Transfer data from existing H2 database to the newly created (presumably MySQL or Postgres) DB specified by env vars. Intended as a tool for upgrading from H2 to a 'real' Database. @@ -82,12 +104,6 @@ :let [objs (kdb/with-db h2-db (k/select (k/database e h2-db)))] :when (seq objs)] - (print (u/format-color 'blue "Transfering %d instances of %s..." (count objs) (:name e))) - (flush) - - ;; The connection closes prematurely on occasion when we're inserting thousands of rows at once. Break into smaller chunks so connection stays alive - (doseq [chunk (partition-all 300 objs)] - (print (color/blue \.)) - (flush) - (k/insert e (k/values chunk))) - (println (color/green "[OK]")))))) + (if-not (contains? #{RawColumn Field} e) + (insert-entity e objs) + (insert-self-referencing-entity e objs))))))