Created
July 23, 2024 12:25
-
-
Save qnkhuat/5fbe7dc688f525385dd16eed6d7572b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns oom-big-dashboard | |
(:require | |
[clojure.java.shell :as sh] | |
[metabase.test :as mt] | |
[metabase.util.log :as log] | |
[toucan2.core :as t2] | |
[toucan2.tools.with-temp :as t2.with-temp])) | |
(defn create-cards | |
[n] | |
(let [tables (t2/select :model/Table :db_id (t2/select-one-pk :model/Database :is_sample true)) | |
get-table (fn [i] (nth tables (mod i (count tables))))] | |
(t2/insert-returning-instances! :model/Card (for [i (range n) | |
:let [table (get-table i)]] | |
(merge | |
(t2.with-temp/with-temp-defaults :model/Card) | |
{:table_id (:id table) | |
:name (format "Card %d with table %s" i (:name table)) | |
:dataset_query {:database (:db_id table) | |
:type :query | |
:query {:source-table (:id table)}}}))))) | |
(defn create-dashboard-cards | |
[dashboard-id cards] | |
(t2/insert! :model/DashboardCard (for [card cards] | |
(merge | |
(t2.with-temp/with-temp-defaults :model/DashboardCard) | |
{:dashboard_id dashboard-id | |
:card_id (:id card)})))) | |
(defn make-big-dashboard | |
[n-dashcards] | |
(let [dashboard-id (t2/insert-returning-pk! :model/Dashboard (t2.with-temp/with-temp-defaults :model/Dashboard))] | |
(create-dashboard-cards dashboard-id (create-cards n-dashcards)) | |
dashboard-id)) | |
(make-big-dashboard 20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment