Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Update backend docs on Tue Jan 9 17:24:41 UTC 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jan 9, 2024
1 parent 963f58a commit f990090
Showing 1 changed file with 135 additions and 1 deletion.
136 changes: 135 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25126,6 +25126,7 @@ <h2>Important Libraries</h2>
(:require
[cheshire.core :as json]
[clojure.core.match :refer [match]]
[clojure.java.io :as io]
[clojure.set :as set]
[clojure.walk :as walk]
[clojurewerkz.quartzite.jobs :as jobs]
Expand All @@ -25140,6 +25141,7 @@ <h2>Important Libraries</h2>
[toucan2.core :as t2]
[toucan2.execute :as t2.execute])
(:import
(java.util Locale)
(liquibase Scope)
(liquibase.change Change)
(liquibase.change.custom CustomTaskChange CustomTaskRollback)
Expand Down Expand Up @@ -25186,6 +25188,12 @@ <h2>Important Libraries</h2>
</td><td class="codes"><pre class="brush: clojure">(defmacro define-migration
[name &amp; migration-body]
`(define-reversible-migration ~name (do ~@migration-body) (no-op ~(str name))))</pre></td></tr><tr><td class="docs"><p>+----------------------------------------------------------------------------------------------------------------+
| HELPERS |
+----------------------------------------------------------------------------------------------------------------+</p>
</td><td class="codes"></td></tr><tr><td class="docs"><p>metabase.util/upper-case-en</p>
</td><td class="codes"><pre class="brush: clojure">(defn- upper-case-en
[s]
(.toUpperCase (str s) (Locale/US)))</pre></td></tr><tr><td class="docs"><p>+----------------------------------------------------------------------------------------------------------------+
| MIGRATIONS |
+----------------------------------------------------------------------------------------------------------------+</p>
</td><td class="codes"></td></tr><tr><td class="docs">
Expand Down Expand Up @@ -25939,7 +25947,133 @@ <h2>Important Libraries</h2>
(remove-admin-group-from-mappings-by-setting-key! :jwt-group-mappings)
(remove-admin-group-from-mappings-by-setting-key! :saml-group-mappings))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(define-migration MigrateRemoveAdminFromGroupMappingIfNeeded
(migrate-remove-admin-from-group-mapping-if-needed))</pre></td></tr><tr><td class="spacer docs">&nbsp;</td><td class="codes" /></tr><tr><td class="docs"><div class="docs-header"><a class="anchor" href="#metabase.db.data-source" name="metabase.db.data-source"><h1 class="project-name">metabase.db.data-source</h1><a class="toc-link" href="#toc">toc</a></a></div></td><td class="codes" /></tr><tr><td class="docs">
(migrate-remove-admin-from-group-mapping-if-needed))</pre></td></tr><tr><td class="docs"><p>Each unified column is 3 items sequence [table-name, column-name, is-nullable?]</p>
</td><td class="codes"><pre class="brush: clojure">(defn- db-type-&gt;to-unified-columns
[db-type]
(case db-type
:h2 [[:activity :timestamp false]
[:application_permissions_revision :created_at false]
[:collection_permission_graph_revision :created_at false]
[:core_session :created_at false]
[:core_user :date_joined false]
[:core_user :last_login true]
[:core_user :updated_at true]
[:dependency :created_at false]
[:dimension :created_at false]
[:dimension :updated_at false]
[:metabase_database :created_at false]
[:metabase_database :updated_at false]
[:metabase_field :created_at false]
[:metabase_field :updated_at false]
[:metabase_field :last_analyzed true]
[:metabase_fieldvalues :created_at false]
[:metabase_table :created_at false]
[:metabase_table :updated_at false]
[:metric :created_at false]
[:metric :updated_at false]
[:permissions_revision :created_at false]
[:pulse :created_at false]
[:pulse :updated_at false]
[:pulse_channel :created_at false]
[:pulse_channel :updated_at false]
[:recent_views :timestamp false]
[:report_card :created_at false]
[:report_cardfavorite :created_at false]
[:report_cardfavorite :updated_at false]
[:report_dashboard :created_at false]
[:report_dashboard :updated_at false]
[:report_dashboardcard :created_at false]
[:report_dashboardcard :updated_at false]
[:segment :created_at false]
[:segment :updated_at false]]
:mysql [[:activity :timestamp false]
[:application_permissions_revision :created_at false]
[:collection_permission_graph_revision :created_at false]
[:core_session :created_at false]
[:core_user :date_joined false]
[:core_user :last_login true]
[:core_user :updated_at true]
[:dependency :created_at false]
[:dimension :created_at false]
[:dimension :updated_at false]
[:metabase_field :created_at false]
[:metabase_field :last_analyzed true]
[:metabase_field :updated_at false]
[:metabase_fieldvalues :created_at false]
[:metabase_table :created_at false]
[:metabase_table :updated_at false]
[:metric :created_at false]
[:metric :updated_at false]
[:permissions_revision :created_at false]
[:pulse :created_at false]
[:pulse :updated_at false]
[:pulse_channel :created_at false]
[:pulse_channel :updated_at false]
[:recent_views :timestamp false]
[:report_card :created_at false]
[:report_cardfavorite :created_at false]
[:report_cardfavorite :updated_at false]
[:report_dashboard :created_at false]
[:report_dashboard :updated_at false]
[:segment :created_at false]
[:segment :updated_at false]]
:postgres [[:application_permissions_revision :created_at false]
[:collection_permission_graph_revision :created_at false]
[:core_user :updated_at true]
[:dimension :updated_at false]
[:dimension :created_at false]
[:permissions_revision :created_at false]
[:recent_views :timestamp false]]))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(defn- alter-table-column-type-sql
[db-type table column ttype nullable?]
(let [ttype (name ttype)
db-type (if (and (= db-type :mysql)
(with-open [conn (.getConnection (mdb.connection/data-source))]
(= &quot;MariaDB&quot; (.getDatabaseProductName (.getMetaData conn)))))
:mariadb
db-type)]
(case db-type
:postgres
(format &quot;ALTER TABLE \&quot;%s\&quot; ALTER COLUMN \&quot;%s\&quot; TYPE %s USING (\&quot;%s\&quot;::%s), ALTER COLUMN %s %s&quot;
table column ttype column ttype column (if nullable? &quot;DROP NOT NULL&quot; &quot;SET NOT NULL&quot;))
:mysql
(format &quot;ALTER TABLE `%s` MODIFY `%s` %s %s&quot;
table column ttype (if nullable? &quot;NULL&quot; &quot;NOT NULL&quot;))
;; maridb will automatically add extra on update set current_timestamp if you don't have a default value for not
;; nullable columns.
;; We don't want this property for created_at columns. so adding a default value here to avoid that default extra
:mariadb
(format &quot;ALTER TABLE `%s` MODIFY `%s` %s %s&quot;
table column ttype (if nullable? &quot;NULL&quot; &quot;NOT NULL DEFAULT CURRENT_TIMESTAMP&quot;))
:h2
(format &quot;ALTER TABLE \&quot;%s\&quot; ALTER COLUMN \&quot;%s\&quot; %s %s&quot;
(upper-case-en table) (upper-case-en column) ttype (if nullable? &quot;NULL&quot; &quot;NOT NULL&quot;)))))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(defn- unify-time-column-type!
[direction]
(let [db-type (mdb.connection/db-type)
columns (db-type-&gt;to-unified-columns db-type)
timestamp-type (case db-type
(:postgres :h2) &quot;TIMESTAMP WITH TIME ZONE&quot;
:mysql &quot;TIMESTAMP(6)&quot;)
datetime-type (case db-type
(:postgres :h2) &quot;TIMESTAMP WITHOUT TIME ZONE&quot;
:mysql &quot;DATETIME&quot;)
target-type (case direction
:up timestamp-type
:down datetime-type)]
(doseq [[table column nullable?] columns
;; core_user.updated_at is referenced in a view in postgres, and PG doesn't allow changing column types if a
;; view depends on it. so we need to drop the view before changing the type, then re-create it again
:let [is-pg-specical-case? (= [db-type table column]
[:postgres :core_user :updated_at])]]
(when is-pg-specical-case?
(t2/query [(format &quot;DROP VIEW IF EXISTS v_users;&quot;)]))
(t2/query [(alter-table-column-type-sql db-type (name table) (name column) target-type nullable?)])
(when is-pg-specical-case?
(t2/query [(slurp (io/resource &quot;migrations/instance_analytics_views/users/v1/postgres-users.sql&quot;))])))))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(define-reversible-migration UnifyTimeColumnsType
(unify-time-column-type! :up)
(unify-time-column-type! :down))</pre></td></tr><tr><td class="spacer docs">&nbsp;</td><td class="codes" /></tr><tr><td class="docs"><div class="docs-header"><a class="anchor" href="#metabase.db.data-source" name="metabase.db.data-source"><h1 class="project-name">metabase.db.data-source</h1><a class="toc-link" href="#toc">toc</a></a></div></td><td class="codes" /></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(ns metabase.db.data-source
(:require
[clojure.set :as set]
Expand Down

0 comments on commit f990090

Please sign in to comment.