Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

entity_id is always present; drop the identity-hash machinery (#78452)

Alexander Polyankin9fc9f53a1f81
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.edn
index 0957c494973..abefbfc5e6c 100644
--- a/.clj-kondo/config/modules/config.edn
+++ b/.clj-kondo/config/modules/config.edn
@@ -3540,8 +3540,7 @@
settings
system
users
- util
- enterprise/serialization}
+ util}
:model-imports #{:model/ApiKey
:model/PermissionsGroup
:model/PermissionsGroupMembership
@@ -3609,10 +3608,7 @@
enterprise/serialization
{:team "Graphy"
- :api #{metabase-enterprise.serialization.api
- metabase-enterprise.serialization.cmd
- metabase-enterprise.serialization.core
- metabase-enterprise.serialization.v2.backfill-ids}
+ :api #{metabase-enterprise.serialization.api metabase-enterprise.serialization.cmd metabase-enterprise.serialization.core}
:friends #{enterprise/memoize-monitor}
:uses #{analytics
api
diff --git a/docs/installation-and-operation/commands.md b/docs/installation-and-operation/commands.md
index 939bf43736e..84756dac271 100644
--- a/docs/installation-and-operation/commands.md
+++ b/docs/installation-and-operation/commands.md
@@ -34,10 +34,6 @@ Generates a markdown file with some documentation and an example configuration f
Print a list of all multimethods available for a driver to implement, optionally with their docstrings.
-## `drop-entity-ids`
-
-Drop entity IDs for instances of serializable models. Useful for migrating from v1 serialization (x.46 and earlier) to v2 (x.47+).
-
## `dump-to-h2 h2-filename opts`
Transfer data from existing database to newly created H2 DB with specified filename. Target H2 file is deleted before dump, unless the --keep-existing flag is given.
@@ -103,10 +99,6 @@ Reset the password for a user with `email-address`.
Rotate the encryption key of a metabase database. The MB_ENCRYPTION_SECRET_KEY environment variable has to be set to the current key, and the parameter `new-key` has to be the new key. `new-key` has to be at least 16 chars.
-## `seed-entity-ids`
-
-Add entity IDs for instances of serializable models that don't already have them.
-
## `version`
Print version information about Metabase and the current system.
diff --git a/enterprise/backend/src/metabase_enterprise/audit_app/analytics_dev.clj b/enterprise/backend/src/metabase_enterprise/audit_app/analytics_dev.clj
index bf70dcb28de..c73e1fd651a 100644
--- a/enterprise/backend/src/metabase_enterprise/audit_app/analytics_dev.clj
+++ b/enterprise/backend/src/metabase_enterprise/audit_app/analytics_dev.clj
@@ -171,7 +171,7 @@
temp-dir (copy-and-transform-yamls! plugins-dir user-email)]
(log/info "Ingesting YAMLs from" temp-dir)
(try
- (let [report (serdes/with-cache (serialization/load-metabase! (serialization/ingest-yaml temp-dir) {:backfill? false}))]
+ (let [report (serdes/with-cache (serialization/load-metabase! (serialization/ingest-yaml temp-dir) {}))]
(log/info "Import complete:" (count (:seen report)) "entities loaded")
(when (seq (:errors report))
(log/warn "Import had errors:" (:errors report)))
diff --git a/enterprise/backend/src/metabase_enterprise/audit_app/audit.clj b/enterprise/backend/src/metabase_enterprise/audit_app/audit.clj
index 7385331bc72..1a7ece59b34 100644
--- a/enterprise/backend/src/metabase_enterprise/audit_app/audit.clj
+++ b/enterprise/backend/src/metabase_enterprise/audit_app/audit.clj
@@ -280,7 +280,7 @@
;; The EE token might not have :serialization enabled, but audit features should still be able to use it.
(let [report (log/with-no-logs
(serialization.cmd/v2-load-internal! (str (instance-analytics-plugin-dir (plugins/plugins-dir)))
- {:backfill? false}
+ {}
:token-check? false
:require-initialized-db? false))
loaded? (empty? (:errors report))]
diff --git a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin.clj b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin.clj
index dd9d7387318..2e47ee90f80 100644
--- a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin.clj
+++ b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin.clj
@@ -93,10 +93,6 @@
:id (:identifier entity)
:label (:identifier entity)}])
-(defmethod serdes/hash-fields :model/CustomVizPlugin
- [_model]
- [:identifier])
-
(defmethod serdes/load-find-local "CustomVizPlugin" [path]
(let [{:keys [id]} (last path)]
(t2/select-one :model/CustomVizPlugin :identifier id)))
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj
index f1c568d9abd..e8754ebc764 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj
@@ -460,7 +460,7 @@
(serdes/with-cache
(serialization/load-metabase!
(source.ingestable/wrap-progress-ingestable task-id 0.7 ingestable)
- :backfill? false :reindex? false)))
+ :reindex? false)))
imported-data (spec/extract-imported-entities (:seen load-result))
loaded-eid? (fn [model-type eid]
;; by-entity-id holds sets of raw entity_id strings, keyed by model type
diff --git a/enterprise/backend/src/metabase_enterprise/scim/api.clj b/enterprise/backend/src/metabase_enterprise/scim/api.clj
index 25ffdaed02f..6563738a466 100644
--- a/enterprise/backend/src/metabase_enterprise/scim/api.clj
+++ b/enterprise/backend/src/metabase_enterprise/scim/api.clj
@@ -1,7 +1,6 @@
(ns metabase-enterprise.scim.api
"/api/ee/scim/ endpoints"
(:require
- [metabase-enterprise.serialization.v2.backfill-ids :as serdes.backfill]
[metabase.api-keys.core :as api-key]
[metabase.api.common :as api]
[metabase.api.macros :as api.macros]
@@ -16,12 +15,6 @@
;; translated.
(format "Metabase SCIM API Key - %s" (random-uuid)))
-(defn- backfill-required-entity-ids!
- "Backfills entity IDs for Users and Groups whenever a SCIM key is generated, in case any are not set"
- []
- (serdes.backfill/backfill-ids-for! :model/User)
- (serdes.backfill/backfill-ids-for! :model/PermissionsGroup))
-
(defn- refresh-scim-api-key!
"Generates a new SCIM API key and deletes any that already exist."
[user-id]
@@ -63,5 +56,4 @@
this is equivalent to enabling SCIM."
[]
(api/check-superuser)
- (backfill-required-entity-ids!)
(refresh-scim-api-key! api/*current-user-id*))
diff --git a/enterprise/backend/src/metabase_enterprise/serialization/cmd.clj b/enterprise/backend/src/metabase_enterprise/serialization/cmd.clj
index 10f9f2c139c..e9beda0981e 100644
--- a/enterprise/backend/src/metabase_enterprise/serialization/cmd.clj
+++ b/enterprise/backend/src/metabase_enterprise/serialization/cmd.clj
@@ -2,7 +2,6 @@
(:require
[clojure.java.io :as io]
[clojure.string :as str]
- [metabase-enterprise.serialization.v2.entity-ids :as v2.entity-ids]
[metabase-enterprise.serialization.v2.extract :as v2.extract]
[metabase-enterprise.serialization.v2.ingest :as v2.ingest]
[metabase-enterprise.serialization.v2.load :as v2.load]
@@ -34,7 +33,6 @@
`opts` are passed to [[v2.load/load-metabase]]."
[path :- :string
opts :- [:map
- [:backfill? {:optional true} [:maybe :boolean]]
[:continue-on-error {:optional true} [:maybe :boolean]]
[:reindex? {:optional true} [:maybe :boolean]]]
;; Deliberately separate from the opts so it can't be set from the CLI.
@@ -62,7 +60,6 @@
opts are passed to load-metabase"
[path :- :string
opts :- [:map
- [:backfill? {:optional true} [:maybe :boolean]]
[:continue-on-error {:optional true} [:maybe :boolean]]
[:full-stacktrace {:optional true} [:maybe :boolean]]]]
(let [timer (u/start-timer)
@@ -145,22 +142,3 @@
(comment
(v2-dump! "/tmp/serdes" {}))
-
-(defn seed-entity-ids!
- "Add entity IDs for instances of serializable models that don't already have them.
-
- Returns truthy if all entity IDs were added successfully, or falsey if any errors were encountered."
- []
- (v2.entity-ids/seed-entity-ids!))
-
-(defn drop-entity-ids!
- "Drop entity IDs for all instances of serializable models.
-
- This is needed for some cases of migrating from v1 to v2 serdes. v1 doesn't dump `entity_id`, so they may have been
- randomly generated independently in both instances. Then when v2 serdes is used to export and import, the randomly
- generated IDs don't match and the entities get duplicated. Dropping `entity_id` from both instances first will force
- them to be regenerated based on the hashes, so they should match up if the receiving instance is a copy of the sender.
-
- Returns truthy if all entity IDs have been dropped, or falsey if any errors were encountered."
- []
- (v2.entity-ids/drop-entity-ids!))
diff --git a/enterprise/backend/src/metabase_enterprise/serialization/v2/backfill_ids.clj b/enterprise/backend/src/metabase_enterprise/serialization/v2/backfill_ids.clj
deleted file mode 100644
index 0d9a0476a0b..00000000000
--- a/enterprise/backend/src/metabase_enterprise/serialization/v2/backfill_ids.clj
+++ /dev/null
@@ -1,43 +0,0 @@
-(ns metabase-enterprise.serialization.v2.backfill-ids
- "Finds all models with `:entity_id` columns, scans them for anything without a blank ID, and
- generates consistent entity_id based on their hashes.
-
- Note that cross-JVM portability is required - but that's specified for [[java.util.Random]],
- so this should produce identical IDs on all platforms and JVM implementations."
- (:require
- [metabase-enterprise.serialization.v2.models :as serdes.models]
- [metabase.models.interface :as mi]
- [metabase.models.serialization :as serdes]
- [metabase.util.log :as log]
- [toucan2.core :as t2]
- [toucan2.model :as t2.model]))
-
-(defn backfill-ids-for!
- "Updates all rows of a particular model to have `:entity_id` set, based on the [[serdes/identity-hash]]."
- [model]
- (let [missing (t2/select model :entity_id nil)
- pk (first (t2/primary-keys model))]
- (when (seq missing)
- (log/infof "Backfilling entity_id for %s rows of %s" (pr-str (count missing)) (name model))
- (doseq [entity missing
- :let [eid (serdes/backfill-entity-id entity)]]
- (t2/update! model (get entity pk) {:entity_id eid})))))
-
-(defn has-entity-id?
- "Returns true if the model has an `:entity_id` column."
- [model]
- (or
- ;; toucan1 models
- (isa? model ::mi/entity-id)
- ;; toucan2 models
- (isa? model :hook/entity-id)))
-
-(defn backfill-ids!
- "Updates all rows of all models that are (a) serialized and (b) have `entity_id` columns to have the
- `entity_id` set. If the `entity_id` is NULL, it is set based on the [[serdes/identity-hash]] for that
- row."
- []
- (doseq [model-name (concat serdes.models/exported-models serdes.models/inlined-models)
- :let [model (t2.model/resolve-model (symbol model-name))]
- :when (has-entity-id? model)]
- (backfill-ids-for! model)))
diff --git a/enterprise/backend/src/metabase_enterprise/serialization/v2/entity_ids.clj b/enterprise/backend/src/metabase_enterprise/serialization/v2/entity_ids.clj
deleted file mode 100644
index 75d920da43c..00000000000
--- a/enterprise/backend/src/metabase_enterprise/serialization/v2/entity_ids.clj
+++ /dev/null
@@ -1,158 +0,0 @@
-(ns metabase-enterprise.serialization.v2.entity-ids
- (:require
- [clojure.set :as set]
- [clojure.string :as str]
- [metabase.app-db.core :as mdb]
- [metabase.collections.models.collection :as collection]
- [metabase.models.resolution :as models.resolution]
- [metabase.models.serialization :as serdes]
- [metabase.util :as u]
- [metabase.util.i18n :refer [trs]]
- [metabase.util.log :as log]
- [toucan2.core :as t2]))
-
-(set! *warn-on-reflection* true)
-
-(def ^:private ignored-entity-id-table-names
- "Legacy (V1) Metrics are no longer supported, and all their code has been removed. However the Tables are still in the
- app DB (for now)... ignore them."
- #{"metric" "METRIC" "metric_important_field" "METRIC_IMPORTANT_FIELD"})
-
-(defn- entity-id-table-names
- "Return a set of lower-cased names of all application database tables that have an `entity_id` column, excluding
- views."
- []
- (with-open [conn (.getConnection (mdb/app-db))]
- (let [dbmeta (.getMetaData conn)]
- (with-open [tables-rset (.getTables dbmeta nil nil nil (into-array String ["TABLE"]))]
- (let [non-view-tables (into #{} (map (comp u/lower-case-en :table_name)) (resultset-seq tables-rset))]
- (with-open [rset (.getColumns dbmeta nil nil nil (case (mdb/db-type)
- :h2 "ENTITY_ID"
- (:mysql :postgres) "entity_id"))]
- (let [entity-id-tables (into #{} (map (comp u/lower-case-en :table_name)) (resultset-seq rset))]
- (-> (set/intersection non-view-tables entity-id-tables)
- (set/difference ignored-entity-id-table-names)))))))))
-
-(defn toucan-models
- "Return a list of all toucan models."
- []
- (keys models.resolution/model->namespace))
-
-(defn- make-table-name->model
- "Create a map of (lower-cased) application DB table name -> corresponding Toucan model."
- []
- (into {}
- (for [model (toucan-models)
- :let [table-name (some-> model t2/table-name name)]
- :when table-name
- ;; ignore any models defined in test namespaces.
- :when (not (str/includes? (namespace model) "test"))]
- [table-name model])))
-
-(defn- entity-id-models
- "Return a set of all Toucan models that have an `entity_id` column."
- []
- (let [entity-id-table-names (entity-id-table-names)
- table-name->model (make-table-name->model)
- entity-id-table-name->model (into {}
- (map (fn [table-name]
- (if-let [model (table-name->model table-name)]
- [table-name model]
- (throw (ex-info (trs "Model not found for table {0}" table-name)
- {:table-name table-name
- :error ::model-not-found})))))
- entity-id-table-names)
- entity-id-models (set (vals entity-id-table-name->model))]
- ;; make sure we've resolved all the tables that have entity_id to their corresponding models.
- (when-not (= (count entity-id-table-names)
- (count entity-id-models))
- (throw (ex-info (trs "{0} tables have entity_id; expected to resolve the same number of models, but only got {1}"
- (count entity-id-table-names)
- (count entity-id-models))
- {:tables entity-id-table-names
- :resolved entity-id-table-name->model
- :error ::mismatched-model-count})))
- (set entity-id-models)))
-
-(defn- seed-entity-id-for-instance! [model instance]
- (let [primary-key (first (t2/primary-keys model))
- pk-value (get instance primary-key)]
- (try
- (when-not (some? pk-value)
- (throw (ex-info (format "Missing value for primary key column %s" (pr-str primary-key))
- {:model (name model)
- :table (t2/table-name model)
- :instance instance
- :primary-key primary-key
- :error ::missing-pk})))
- (let [new-hash (serdes/identity-hash instance)]
- (log/infof "Update %s %s entity ID => %s" (name model) (pr-str pk-value) (pr-str new-hash))
- (t2/update! model pk-value {:entity_id new-hash}))
- {:update-count 1}
- (catch Throwable e
- (let [data (ex-data e)]
- (log/errorf e "Error updating entity ID for %s %s: %s %s" (name model) (pr-str pk-value) (ex-message e)
- (or (some-> data pr-str) "")))
- {:error-count 1}))))
-
-(defn- seed-entity-ids-for-model! [model]
- (log/infof "Seeding Entity IDs for model %s" (name model))
- (let [reducible-instances (t2/reducible-select model :entity_id nil)]
- (transduce
- (map (fn [instance]
- (seed-entity-id-for-instance! model instance)))
- (completing
- (partial merge-with +)
- (fn [{:keys [update-count error-count], :as results}]
- (when (pos? update-count)
- (log/infof "Updated %d %s instance(s) successfully." update-count (name model)))
- (when (pos? error-count)
- (log/infof "Failed to update %d %s instance(s) because of errors." error-count (name model)))
- results))
- {:update-count 0, :error-count 0}
- reducible-instances)))
-
-(defn seed-entity-ids!
- "Create entity IDs for any instances of models that support them but do not have them, i.e. find instances of models
- that have an `entity_id` column whose `entity_id` is `nil` and populate that column.
-
- Returns truthy if all missing entity IDs were created successfully, and falsey if there were any errors."
- []
- (log/info "Seeding Entity IDs")
- (mdb/setup-db! :create-sample-content? false)
- (let [{:keys [error-count]} (transduce
- (map seed-entity-ids-for-model!)
- (completing (partial merge-with +))
- {:update-count 0, :error-count 0}
- (entity-id-models))]
- (zero? error-count)))
-
-(defn- drop-entity-id-conditions-for-model [model]
- (case model
- :model/Collection {:id [:not= (collection/trash-collection-id)]}
- {}))
-
-(defn- drop-entity-ids-for-model! [model]
- (log/infof "Dropping Entity IDs for model %s" (name model))
- (try
- (let [update-count (t2/update! model (drop-entity-id-conditions-for-model model) {:entity_id nil})]
- (when (pos? update-count)
- (log/infof "Updated %d %s instance(s) successfully." update-count (name model)))
- {:update-count update-count})
- (catch Throwable e
- (log/errorf e "Error dropping entity ID: %s" (ex-message e))
- {:error-count 1})))
-
-(defn drop-entity-ids!
- "Delete entity IDs for any models that have them. See #34871.
-
- Returns truthy if all entity IDs were removed successfully, and falsey if there were any errors."
- []
- (log/info "Dropping Entity IDs")
- (mdb/setup-db! :create-sample-content? false)
- (let [{:keys [error-count]} (transduce
- (map drop-entity-ids-for-model!)
- (completing (partial merge-with +))
- {:update-count 0, :error-count 0}
- (entity-id-models))]
- (zero? error-count)))
diff --git a/enterprise/backend/src/metabase_enterprise/serialization/v2/extract.clj b/enterprise/backend/src/metabase_enterprise/serialization/v2/extract.clj
index c64db7cc1a0..787058f2b90 100644
--- a/enterprise/backend/src/metabase_enterprise/serialization/v2/extract.clj
+++ b/enterprise/backend/src/metabase_enterprise/serialization/v2/extract.clj
@@ -4,7 +4,6 @@
See the detailed descriptions of the (de)serialization processes in [[metabase.models.serialization]]."
(:require
[clojure.set :as set]
- [metabase-enterprise.serialization.v2.backfill-ids :as serdes.backfill]
[metabase-enterprise.serialization.v2.dependency-validation :as dependency-validation]
[metabase-enterprise.serialization.v2.models :as serdes.models]
[metabase.collections.models.collection :as collection]
@@ -176,7 +175,6 @@
(defn extract
"Returns a reducible stream of entities to serialize"
[opts]
- (serdes.backfill/backfill-ids!)
(extract-subtrees opts))
(comment
diff --git a/enterprise/backend/src/metabase_enterprise/serialization/v2/load.clj b/enterprise/backend/src/metabase_enterprise/serialization/v2/load.clj
index 1045ce00925..bafa40b24a1 100644
--- a/enterprise/backend/src/metabase_enterprise/serialization/v2/load.clj
+++ b/enterprise/backend/src/metabase_enterprise/serialization/v2/load.clj
@@ -4,7 +4,6 @@
(:require
[clojure.string :as str]
[diehard.core :as dh]
- [metabase-enterprise.serialization.v2.backfill-ids :as serdes.backfill]
[metabase-enterprise.serialization.v2.ingest :as serdes.ingest]
[metabase-enterprise.serialization.v2.models :as serdes.models]
[metabase.app-db.core :as mdb]
@@ -136,7 +135,7 @@
[model-name]
(when (valid-model-name-for-load? model-name)
(let [model (t2.model/resolve-model (symbol model-name))]
- (serdes.backfill/has-entity-id? model))))
+ (serdes/has-entity-id? model))))
(defn- load-one!
"Loads a single entity, specified by its `:serdes/meta` abstract path, into the appdb, doing some bookkeeping to
@@ -188,7 +187,7 @@
;; in the yaml file.
;; In all other cases we should expect an :entity_id:
;; - exported entities have a :entity_id for every model that can have one
- ;; - backfill (pre import) guarantees all entities have ids in the appdb
+ ;; - a migration backfilled historical NULLs and the insert hook always generates one
expect-entity-id (some-> rebuilt-path peek :model exported-with-entity-id?)
require-new-entity (and expect-entity-id (nil? (:entity_id ingested)))
ingested (cond-> ingested
@@ -255,43 +254,38 @@
(defn load-metabase!
"Loads in a database export from an ingestion source, which is any Ingestable instance."
- [ingestion & {:keys [backfill? continue-on-error reindex?]
- :or {backfill? true
- continue-on-error false
+ [ingestion & {:keys [continue-on-error reindex?]
+ :or {continue-on-error false
reindex? true}}]
(u/prog1
;; Each entity is loaded in its own transaction (inside load-one!), so a deadlock or transient
;; failure on one entity doesn't abort the entire import. See #74412.
- (do
- (when backfill?
- (t2/with-transaction [_tx]
- (serdes.backfill/backfill-ids!)))
- ;; We proceed in the arbitrary order of ingest-list, deserializing all the files. Their declared
- ;; dependencies guide the import, and make sure all containers are imported before contents, etc.
- (let [contents (serdes.ingest/ingest-list ingestion)
- ingest-errors (serdes.ingest/ingest-errors ingestion)
- ctx (cond-> (new-context ingestion)
- (seq ingest-errors) (update :errors into ingest-errors))]
- (when (and (seq ingest-errors) (not continue-on-error))
- (let [file-names (mapv #(or (:file (ex-data %)) (ex-message %)) ingest-errors)]
- (throw (ex-info (format "Failed to read %d file(s) during ingestion: %s"
- (count ingest-errors)
- (str/join ", " file-names))
- {:ingest-errors ingest-errors
- :files file-names}
- (first ingest-errors)))))
- (log/infof "Starting deserialization, total %s documents" (count contents))
- (reduce (fn [ctx item]
- (try
- (load-one! ctx item)
- (catch Exception e
- (when-not continue-on-error
- (throw e))
- ;; eschew big and scary stacktrace
- (log/warnf (u/strip-error e "Skipping deserialization error"))
- (update ctx :errors conj e))))
- ctx
- contents)))
+ ;; We proceed in the arbitrary order of ingest-list, deserializing all the files. Their declared
+ ;; dependencies guide the import, and make sure all containers are imported before contents, etc.
+ (let [contents (serdes.ingest/ingest-list ingestion)
+ ingest-errors (serdes.ingest/ingest-errors ingestion)
+ ctx (cond-> (new-context ingestion)
+ (seq ingest-errors) (update :errors into ingest-errors))]
+ (when (and (seq ingest-errors) (not continue-on-error))
+ (let [file-names (mapv #(or (:file (ex-data %)) (ex-message %)) ingest-errors)]
+ (throw (ex-info (format "Failed to read %d file(s) during ingestion: %s"
+ (count ingest-errors)
+ (str/join ", " file-names))
+ {:ingest-errors ingest-errors
+ :files file-names}
+ (first ingest-errors)))))
+ (log/infof "Starting deserialization, total %s documents" (count contents))
+ (reduce (fn [ctx item]
+ (try
+ (load-one! ctx item)
+ (catch Exception e
+ (when-not continue-on-error
+ (throw e))
+ ;; eschew big and scary stacktrace
+ (log/warnf (u/strip-error e "Skipping deserialization error"))
+ (update ctx :errors conj e))))
+ ctx
+ contents))
(when reindex?
;; Reindex after all entities are loaded. Individual entity commits may have produced stale
;; search index entries; this ensures the index reflects the final state.
diff --git a/enterprise/backend/src/metabase_enterprise/transforms_python/models/python_library.clj b/enterprise/backend/src/metabase_enterprise/transforms_python/models/python_library.clj
index cfe501725e6..250a048ace6 100644
--- a/enterprise/backend/src/metabase_enterprise/transforms_python/models/python_library.clj
+++ b/enterprise/backend/src/metabase_enterprise/transforms_python/models/python_library.clj
@@ -89,10 +89,6 @@
{:copy [:path :source :entity_id]
:transform {:created_at (serdes/date)}})
-(defmethod serdes/hash-fields :model/PythonLibrary
- [_model]
- [:path])
-
(defmethod serdes/storage-path "PythonLibrary" [entity _ctx]
[{:label "python-libraries"} {:label (:path entity) :key (:entity_id entity)}])
diff --git a/enterprise/backend/test/metabase_enterprise/audit_app/audit_test.clj b/enterprise/backend/test/metabase_enterprise/audit_app/audit_test.clj
index 8d3bb8765c4..2d19cbe9560 100644
--- a/enterprise/backend/test/metabase_enterprise/audit_app/audit_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/audit_app/audit_test.clj
@@ -7,11 +7,9 @@
[metabase-enterprise.audit-app.audit :as ee-audit]
[metabase-enterprise.audit-app.settings :as ee.audit.settings]
[metabase-enterprise.serialization.cmd :as serialization.cmd]
- [metabase-enterprise.serialization.v2.backfill-ids :as serdes.backfill]
[metabase.audit-app.core :as audit]
[metabase.core.core :as mbc]
[metabase.lib.core :as lib]
- [metabase.models.serialization :as serdes]
[metabase.permissions-rest.data-permissions.graph :as data-perms.graph]
[metabase.permissions.models.permissions-group :as perms-group]
[metabase.plugins.core :as plugins]
@@ -142,26 +140,6 @@
(get-audit-db-trigger-keys))
"no sync occurred even when called directly for audit db."))))
-(deftest no-backfill-occurs-when-loading-analytics-content-test
- (mt/with-model-cleanup [:model/Collection]
- (let [c1-instance (t2/insert-returning-instance! :model/Collection
- {:entity_id nil,
- :name "My Duped Collection",
- :location "/"})]
- ;; fill in the entity_id for c1:
- (serdes.backfill/backfill-ids-for! :model/Collection)
- ;; insert c2, which will have the same entity id:
- (let [c2-instance (t2/insert-returning-instance! :model/Collection (dissoc c1-instance :id))]
- (testing "c1 and c2 hash to the same entity id."
- (is (= (u/generate-nano-id (serdes/identity-hash c1-instance))
- (u/generate-nano-id (serdes/identity-hash c2-instance)))))
- (testing "A backfill with 'duplicate' rows (with different ids)."
- (is (thrown? Exception
- (serdes.backfill/backfill-ids-for! :model/Collection))))
- (testing "No exception is thrown when db has 'duplicate' entries."
- (is (= ::ee-audit/no-op
- (ee-audit/ensure-audit-db-installed!))))))))
-
(deftest checksum-not-recorded-when-load-fails-test
(mt/test-drivers #{:postgres :h2 :mysql}
(t2/delete! :model/Database :is_audit true)
diff --git a/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin_test.clj b/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin_test.clj
index 46a9294e6a3..ce33daa9677 100644
--- a/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin_test.clj
@@ -86,11 +86,6 @@
(is (= [{:label "custom_viz_plugins"} {:label "my-viz"}]
(serdes/storage-path entity nil))))))
-(deftest hash-fields-test
- (testing "hash-fields is [:identifier]"
- (is (= [:identifier]
- (serdes/hash-fields :model/CustomVizPlugin)))))
-
(deftest load-find-local-test
(testing "load-find-local finds plugin by identifier"
(mt/with-temp [:model/CustomVizPlugin {id :id} {:identifier "find-local"
diff --git a/enterprise/backend/test/metabase_enterprise/scim/v2/api_test.clj b/enterprise/backend/test/metabase_enterprise/scim/v2/api_test.clj
index 8389ef9d5fe..25c847e72be 100644
--- a/enterprise/backend/test/metabase_enterprise/scim/v2/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/scim/v2/api_test.clj
@@ -26,7 +26,6 @@
temp-unmasked-key (-> (#'scim/refresh-scim-api-key! (mt/user->id :crowberto))
:unmasked_key)]
(try
- (#'scim/backfill-required-entity-ids!)
(binding [*scim-api-key* temp-unmasked-key]
(thunk))
(finally
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/models/entity_id_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/models/entity_id_test.clj
index b70654cffc9..628831eba26 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/models/entity_id_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/models/entity_id_test.clj
@@ -6,9 +6,8 @@
explicitly excluded, or has the :entity_id property."
(:require
[clojure.test :refer :all]
- [metabase-enterprise.serialization.v2.backfill-ids :as serdes.backfill]
- [metabase-enterprise.serialization.v2.entity-ids :as v2.entity-ids]
[metabase-enterprise.serialization.v2.models :as serdes.models]
+ [metabase.models.resolution :as models.resolution]
[metabase.models.serialization :as serdes]))
(set! *warn-on-reflection* true)
@@ -156,7 +155,7 @@
:model/WorkspaceInstance})
(deftest ^:parallel comprehensive-entity-id-test
- (let [entity-id-models (->> (v2.entity-ids/toucan-models)
+ (let [entity-id-models (->> (keys models.resolution/model->namespace)
(remove entities-not-exported)
(remove entities-external-name))]
(testing "All exported models should get entity id except those with other unique property (like name)"
@@ -170,13 +169,4 @@
(testing (format (str "Model %s should either: have the ::mi/entity-id property, or be explicitly listed as having "
"an external name, or explicitly listed as excluded from serialization")
model)
- (is (serdes.backfill/has-entity-id? model))))))
-
-(deftest ^:parallel comprehensive-identity-hash-test
- (doseq [model (->> (v2.entity-ids/toucan-models)
- (remove entities-not-exported))]
- (testing (format "Model %s should implement identity-hash-fields" model)
- (is (some? (try
- (serdes/hash-fields model)
- (catch java.lang.IllegalArgumentException _
- nil)))))))
+ (is (serdes/has-entity-id? model))))))
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/backfill_ids_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/backfill_ids_test.clj
deleted file mode 100644
index 7ddf138659a..00000000000
--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/backfill_ids_test.clj
+++ /dev/null
@@ -1,61 +0,0 @@
-(ns metabase-enterprise.serialization.v2.backfill-ids-test
- (:require
- [clojure.test :refer :all]
- [metabase-enterprise.serialization.test-util :as ts]
- [metabase-enterprise.serialization.v2.backfill-ids :as serdes.backfill]
- [metabase.test :as mt]
- [toucan2.core :as t2]))
-
-(deftest backfill-needed-test
- (mt/with-empty-h2-app-db!
- (ts/with-temp-dpc [:model/Collection {c1-id :id} {:name "some collection"}
- :model/Collection {c2-id :id} {:name "other collection"}
- ;; These two deliberately have the same name!
- :model/Collection {c3-id :id} {:name "child collection"
- :location (str "/" c1-id "/")}
- :model/Collection {c4-id :id} {:name "child collection"
- :location (str "/" c2-id "/")}]
- (let [coll-ids [c1-id c2-id c3-id c4-id]
- all-eids #(t2/select-fn-set :entity_id :model/Collection :id [:in coll-ids])]
- (testing "all collections have entity_ids"
- (is (every? some? (all-eids))))
- (testing "removing the entity_ids"
- (doseq [id coll-ids]
- (t2/update! :model/Collection id {:entity_id nil}))
- (is (every? nil? (all-eids))))
- (testing "backfill now recreates them"
- (serdes.backfill/backfill-ids-for! :model/Collection)
- (is (every? some? (all-eids))))))))
-
-(deftest no-overwrite-test
- (mt/with-empty-h2-app-db!
- (ts/with-temp-dpc [:model/Collection {c1-id :id c1-eid :entity_id} {:name "some collection"}
- :model/Collection {c2-id :id} {:name "other collection"}]
- (testing "deleting the entity_id for one of them"
- (t2/update! :model/Collection c2-id {:entity_id nil})
- (is (= #{c1-eid nil}
- (t2/select-fn-set :entity_id :model/Collection :type nil))))
- (testing "backfill"
- (serdes.backfill/backfill-ids-for! :model/Collection)
- (testing "sets a blank entity_id"
- (is (some? (t2/select-one-fn :entity_id :model/Collection :id c2-id))))
- (testing "does not change the original entity_id"
- (is (= c1-eid (t2/select-one-fn :entity_id :model/Collection :id c1-id))))))))
-
-(deftest repeatable-test
- (mt/with-empty-h2-app-db!
- (ts/with-temp-dpc [:model/Collection {c1-eid :entity_id} {:name "some collection"}
- :model/Collection {c2-id :id} {:name "other collection"}]
- (testing "deleting the entity_id for one of them"
- (t2/update! :model/Collection c2-id {:entity_id nil})
- (is (= #{c1-eid nil}
- (t2/select-fn-set :entity_id :model/Collection :type nil))))
- (testing "backfilling twice"
- (serdes.backfill/backfill-ids-for! :model/Collection)
- (let [first-eid (t2/select-one-fn :entity_id :model/Collection :id c2-id)]
- (t2/update! :model/Collection c2-id {:entity_id nil})
- (is (= #{c1-eid nil}
- (t2/select-fn-set :entity_id :model/Collection :type nil)))
- (serdes.backfill/backfill-ids-for! :model/Collection)
- (testing "produces the same entity_id both times"
- (is (= first-eid (t2/select-one-fn :entity_id :model/Collection :id c2-id)))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/entity_ids_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/entity_ids_test.clj
deleted file mode 100644
index f28a08cae15..00000000000
--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/entity_ids_test.clj
+++ /dev/null
@@ -1,103 +0,0 @@
-(ns metabase-enterprise.serialization.v2.entity-ids-test
- (:require
- [clojure.string :as str]
- [clojure.test :refer :all]
- [metabase-enterprise.serialization.v2.backfill-ids :as serdes.backfill]
- [metabase-enterprise.serialization.v2.entity-ids :as v2.entity-ids]
- [metabase.app-db.core :as mdb]
- [metabase.test :as mt]
- [metabase.util :as u]
- [toucan2.core :as t2])
- (:import
- (java.sql DatabaseMetaData)
- (java.time LocalDateTime)))
-
-(set! *warn-on-reflection* true)
-
-(deftest seed-entity-ids-test
- (testing "Sanity check: should succeed before we go around testing specific situations"
- (is (true? (v2.entity-ids/seed-entity-ids!))))
- (testing "With a temp Collection with no entity ID"
- (let [now (LocalDateTime/of 2022 9 1 12 34 56)]
- (mt/test-helpers-set-global-values!
- (mt/with-temp [:model/Collection c {:name "No Entity ID Collection"
- :slug "no_entity_id_collection"
- :created_at now}]
- (t2/update! :model/Collection (:id c) {:entity_id nil})
- (letfn [(entity-id []
- (some-> (t2/select-one-fn :entity_id :model/Collection :id (:id c)) str/trim))]
- (is (= nil
- (entity-id)))
- (testing "Should return truthy on success"
- (is (true? (v2.entity-ids/seed-entity-ids!))))
- (is (= "998b109c"
- (entity-id))))
- (testing "Error: duplicate entity IDs"
- (mt/test-helpers-set-global-values!
- (mt/with-temp [:model/Collection c2 {:name "No Entity ID Collection"
- :slug "no_entity_id_collection"
- :created_at now}]
- (t2/update! :model/Collection (:id c2) {:entity_id nil})
- (letfn [(entity-id []
- (some-> (t2/select-one-fn :entity_id :model/Collection :id (:id c2)) str/trim))]
- (is (= nil
- (entity-id)))
- (testing "Should return falsey on error"
- (is (= false
- (v2.entity-ids/seed-entity-ids!))))
- (is (= nil
- (entity-id)))))))
- (testing "Cannot create entity ID error"
- (mt/with-temp [:model/Collection c3 {:name "error collection"
- :entity_id nil}]
- ;; update table directly so checks for collection existence don't trigger
- (t2/update! :collection (:id c3) {:location "/13371338/"})
- (mt/with-log-messages-for-level [messages [metabase-enterprise :error]]
- (is (= false
- (v2.entity-ids/seed-entity-ids!)))
- (is (=? [{:level :error, :e Throwable, :message #"Error updating entity ID for \w+ \d+:.*is an orphan.*\{:parent-id \d+\}"}]
- (messages)))))))))))
-
-(deftest drop-entity-ids-test
- (mt/with-empty-h2-app-db!
- (testing "With a temp Collection with an entity ID"
- (let [now (LocalDateTime/of 2022 9 1 12 34 56)]
- (mt/test-helpers-set-global-values!
- (mt/with-temp [:model/Collection c {:name "No Entity ID Collection"
- :slug "no_entity_id_collection"
- :created_at now}]
- (letfn [(entity-id []
- (some-> (t2/select-one-fn :entity_id :model/Collection :id (:id c)) str/trim))]
- (is (some? (entity-id)))
- (testing "Should return truthy on success"
- (is (true?
- (v2.entity-ids/drop-entity-ids!))))
- (is (nil? (entity-id))))))))
- (testing "empty table"
- (testing "has no entity ids"
- (mt/test-helpers-set-global-values!
- (mt/with-temp [:model/Collection _ {:name "No Entity ID Collection"
- :slug "no_entity_id_collection"}]
- (is (nil? (t2/select-fn-set :entity-id :model/Dashboard)))
- (testing "but doesn't crash drop-entity-ids"
- (is (true?
- (v2.entity-ids/drop-entity-ids!)))
- (is (nil? (t2/select-fn-set :entity-id :model/Dashboard))))))))))
-
-(deftest entity-ids-are-nullable
- (testing "entity_id field should be nullable for model so that drop-entity-ids work (#36365)"
- (t2/with-connection [^java.sql.Connection conn]
- (doseq [m (v2.entity-ids/toucan-models)
- :when (serdes.backfill/has-entity-id? m)
- :let [table-name (cond-> (name (t2/table-name m))
- (= :h2 (mdb/db-type)) u/upper-case-en)
- column-name (if (= :h2 (mdb/db-type))
- "ENTITY_ID"
- "entity_id")
- rs (-> (.getMetaData conn)
- (.getColumns nil nil table-name column-name))]]
- (testing m
- (if (.next rs)
- (is (= DatabaseMetaData/columnNullable
- (.getInt rs "NULLABLE")))
- (is false "cannot get column information")))))))
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/load_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/load_test.clj
index ca489d8b5e9..05d79687413 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/load_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/v2/load_test.clj
@@ -1959,45 +1959,6 @@
(is (= nil
(t2/select-one :model/Dimension :entity_id (:entity_id d2)))))))))))
-(deftest nested-identity-hashes-test ;; tests serdes/nested behavior for identity hashes
- (let [ids (atom {})]
- (ts/with-dbs [source-db dest-db]
- (ts/with-db source-db
- (mt/with-temp [:model/Collection coll {:name "Coll"}
- :model/Dashboard dash {:name "Dash"}
- :model/Card c1 {:name "Card 1"}
- :model/DashboardCard dc1 {:dashboard_id (:id dash)
- :card_id (:id c1)}]
- (testing "Store deserialized data ids in preparation for test"
- (let [ser1 (vec (serdes.extract/extract {:no-settings true}))]
- (ts/with-db dest-db
- (serdes.load/load-metabase! (ingestion-in-memory ser1))
- (reset! ids
- (vec
- (for [[_name e] {:coll coll :dash dash :c1 c1 :dc1 dc1}]
- [(t2/model e) (:id (t2/select-one (t2/model e) :entity_id (:entity_id e)))]))))))
- (testing "Convert everything to using identity hashes"
- (t2/update! :model/Collection :id (:id coll) {:entity_id (serdes/identity-hash coll)})
- (t2/update! :model/Dashboard :id (:id dash) {:entity_id (serdes/identity-hash dash)})
- (t2/update! :model/Card :id (:id c1) {:entity_id (serdes/identity-hash c1)})
- (t2/update! :model/DashboardCard :id (:id dc1) {:entity_id (serdes/identity-hash dc1)}))
- (is (= 8 (count (serdes/entity-id "Card"
- (t2/select-one [:model/Card :entity_id] :id (:id c1))))))
- (testing "Identity hashes end up in target db in place of entity ids"
- (let [ser2 (vec (serdes.extract/extract {:no-settings true :no-data-model true :no-transforms true}))]
- (testing "\nWe exported identity hashes"
- (doseq [e ser2
- :when (:entity_id e)]
- (is (= 8 (count (-> e :entity_id str/trim))))))
- (ts/with-db dest-db
- (serdes.load/load-metabase! (ingestion-in-memory ser2))
- (testing "\nAll entities (including nested dashcards) were updated"
- (doseq [[model id] @ids
- :let [e (t2/select-one model :id id)]]
- (testing (format "%s has identity hash in the db" model)
- (is (= (serdes/identity-hash e)
- (serdes/entity-id (name model) e))))))))))))))
-
(deftest identically-named-fields-test
(mt/with-empty-h2-app-db!
(let [db (ts/create! :model/Database :name "mydb")
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/models_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/models_test.clj
index c79140844ad..128337d7eb9 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/models_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/v2/models_test.clj
@@ -3,10 +3,9 @@
[clojure.set :as set]
[clojure.test :refer :all]
[metabase-enterprise.impersonation.models]
- [metabase-enterprise.serialization.v2.backfill-ids :as serdes.backfill]
- [metabase-enterprise.serialization.v2.entity-ids :as v2.entity-ids]
[metabase-enterprise.serialization.v2.models :as serdes.models]
[metabase.app-db.core :as mdb]
+ [metabase.models.resolution :as models.resolution]
[metabase.models.serialization :as serdes]
[metabase.test :as mt]
[metabase.util :as u]
@@ -37,31 +36,7 @@
serdes.models/inlined-models
serdes.models/excluded-models))]
(is (= (set known-models)
- (set (map name (v2.entity-ids/toucan-models)))))))))
-
-(deftest ^:parallel every-model-is-supported-test-2
- (testing "Serialization support\n"
- (let [should-have-entity-id (set (concat serdes.models/data-model serdes.models/content))
- excluded (set serdes.models/excluded-models)]
- (doseq [model (v2.entity-ids/toucan-models)]
- (let [custom-entity-id? (not= (get-method serdes/entity-id (name model))
- (get-method serdes/entity-id :default))
- custom-hash-fields? (not= (get-method serdes/hash-fields model)
- (get-method serdes/hash-fields :default))
- random-entity-id? (and custom-hash-fields?
- (serdes.backfill/has-entity-id? model))]
- ;; we're not checking inline-models for anything here, since some of them have (and use) entity_id, like
- ;; dashcards, and some (ParameterCard) do not
- (when (contains? should-have-entity-id (name model))
- (testing (str "Model should either have entity_id or a hash key: " (name model))
- ;; `not=` is effectively `xor`
- (is (not= custom-entity-id? random-entity-id?))))
- (when (contains? excluded (name model))
- (testing (str "Model shouldn't have entity_id defined: " (name model))
- (is (not custom-entity-id?))
- ;; TODO: strip serialization stuff off Pulse*
- (when-not (#{"Pulse" "PulseChannel" "PulseCard" "User" "PermissionsGroup"} (name model))
- (is (not random-entity-id?))))))))))
+ (set (map name (keys models.resolution/model->namespace)))))))))
(deftest serialization-complete-spec-test
(mt/with-empty-h2-app-db!
diff --git a/resources/migrations/064/20260723_backfill_entity_ids.yaml b/resources/migrations/064/20260723_backfill_entity_ids.yaml
new file mode 100644
index 00000000000..14fc9e47288
--- /dev/null
+++ b/resources/migrations/064/20260723_backfill_entity_ids.yaml
@@ -0,0 +1,377 @@
+## Backfill NULL entity_id values with random identifiers so the column can be treated as always
+## present: the insert hook now generates one in every case (including deserialization), and the
+## export/import-time app-level backfills are gone. The generated values are 21 hex characters (a
+## subset of the NanoID alphabet) from a per-row UUID, so they satisfy the entity_id uniques —
+## uuid generation rather than md5() because md5 is unavailable on FIPS-configured servers. With the
+## blanks gone (and the insert hook generating ids in every remaining case), the column becomes
+## NOT NULL everywhere it exists. All three dialect variants live in one changeset so every
+## database executes (and records) it — a changeset whose only change is dbms-filtered away never
+## reaches the changelog, which breaks consolidation.
+
+databaseChangeLog:
+ - changeSet:
+ id: v64.2026-07-23T12:00:00
+ author: ranquild
+ comment: Backfill NULL entity_id values
+ changes:
+ - sql:
+ dbms: postgresql
+ sql: |
+ UPDATE action SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE collection SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE core_user SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE dashboard_tab SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE dimension SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE document SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE embedding_theme SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE measure SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE metabot SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE metabot_prompt SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE metric SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE native_query_snippet SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE permissions_group SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE pulse SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE pulse_card SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE pulse_channel SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE python_library SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE report_card SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE report_dashboard SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE report_dashboardcard SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE segment SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE timeline SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform_job SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform_job_transform_tag SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform_tag SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform_transform_tag SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
+ - sql:
+ dbms: mysql,mariadb
+ sql: |
+ UPDATE action SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE collection SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE core_user SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE dashboard_tab SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE dimension SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE document SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE embedding_theme SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE measure SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE metabot SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE metabot_prompt SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE metric SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE native_query_snippet SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE permissions_group SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE pulse SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE pulse_card SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE pulse_channel SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE python_library SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE report_card SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE report_dashboard SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE report_dashboardcard SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE segment SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE timeline SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform_job SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform_job_transform_tag SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform_tag SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform_transform_tag SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ - sql:
+ dbms: h2
+ sql: |
+ UPDATE action SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE collection SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE core_user SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE dashboard_tab SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE dimension SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE document SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE embedding_theme SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE measure SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE metabot SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE metabot_prompt SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE metric SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE native_query_snippet SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE permissions_group SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE pulse SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE pulse_card SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE pulse_channel SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE python_library SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE report_card SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE report_dashboard SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE report_dashboardcard SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE segment SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE timeline SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform_job SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform_job_transform_tag SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform_tag SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ UPDATE transform_transform_tag SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
+ rollback: []
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:03
+ author: ranquild
+ comment: entity_id is NOT NULL on action
+ changes:
+ - addNotNullConstraint:
+ tableName: action
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:04
+ author: ranquild
+ comment: entity_id is NOT NULL on collection
+ changes:
+ - addNotNullConstraint:
+ tableName: collection
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:05
+ author: ranquild
+ comment: entity_id is NOT NULL on core_user
+ changes:
+ - addNotNullConstraint:
+ tableName: core_user
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:06
+ author: ranquild
+ comment: entity_id is NOT NULL on dashboard_tab
+ changes:
+ - addNotNullConstraint:
+ tableName: dashboard_tab
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:07
+ author: ranquild
+ comment: entity_id is NOT NULL on dimension
+ changes:
+ - addNotNullConstraint:
+ tableName: dimension
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:08
+ author: ranquild
+ comment: entity_id is NOT NULL on document
+ changes:
+ - addNotNullConstraint:
+ tableName: document
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:09
+ author: ranquild
+ comment: entity_id is NOT NULL on embedding_theme
+ changes:
+ - addNotNullConstraint:
+ tableName: embedding_theme
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:10
+ author: ranquild
+ comment: entity_id is NOT NULL on measure
+ changes:
+ - addNotNullConstraint:
+ tableName: measure
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:11
+ author: ranquild
+ comment: entity_id is NOT NULL on metabot
+ changes:
+ - addNotNullConstraint:
+ tableName: metabot
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:12
+ author: ranquild
+ comment: entity_id is NOT NULL on metabot_prompt
+ changes:
+ - addNotNullConstraint:
+ tableName: metabot_prompt
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:13
+ author: ranquild
+ comment: entity_id is NOT NULL on metric
+ changes:
+ - addNotNullConstraint:
+ tableName: metric
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:14
+ author: ranquild
+ comment: entity_id is NOT NULL on native_query_snippet
+ changes:
+ - addNotNullConstraint:
+ tableName: native_query_snippet
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:15
+ author: ranquild
+ comment: entity_id is NOT NULL on permissions_group
+ changes:
+ - addNotNullConstraint:
+ tableName: permissions_group
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:16
+ author: ranquild
+ comment: entity_id is NOT NULL on pulse
+ changes:
+ - addNotNullConstraint:
+ tableName: pulse
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:17
+ author: ranquild
+ comment: entity_id is NOT NULL on pulse_card
+ changes:
+ - addNotNullConstraint:
+ tableName: pulse_card
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:18
+ author: ranquild
+ comment: entity_id is NOT NULL on pulse_channel
+ changes:
+ - addNotNullConstraint:
+ tableName: pulse_channel
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:19
+ author: ranquild
+ comment: entity_id is NOT NULL on python_library
+ changes:
+ - addNotNullConstraint:
+ tableName: python_library
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:20
+ author: ranquild
+ comment: entity_id is NOT NULL on report_card
+ changes:
+ - addNotNullConstraint:
+ tableName: report_card
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:21
+ author: ranquild
+ comment: entity_id is NOT NULL on report_dashboard
+ changes:
+ - addNotNullConstraint:
+ tableName: report_dashboard
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:22
+ author: ranquild
+ comment: entity_id is NOT NULL on report_dashboardcard
+ changes:
+ - addNotNullConstraint:
+ tableName: report_dashboardcard
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:23
+ author: ranquild
+ comment: entity_id is NOT NULL on segment
+ changes:
+ - addNotNullConstraint:
+ tableName: segment
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:24
+ author: ranquild
+ comment: entity_id is NOT NULL on timeline
+ changes:
+ - addNotNullConstraint:
+ tableName: timeline
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:25
+ author: ranquild
+ comment: entity_id is NOT NULL on transform
+ changes:
+ - addNotNullConstraint:
+ tableName: transform
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:26
+ author: ranquild
+ comment: entity_id is NOT NULL on transform_job
+ changes:
+ - addNotNullConstraint:
+ tableName: transform_job
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:27
+ author: ranquild
+ comment: entity_id is NOT NULL on transform_job_transform_tag
+ changes:
+ - addNotNullConstraint:
+ tableName: transform_job_transform_tag
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:28
+ author: ranquild
+ comment: entity_id is NOT NULL on transform_tag
+ changes:
+ - addNotNullConstraint:
+ tableName: transform_tag
+ columnName: entity_id
+ columnDataType: char(21)
+
+ - changeSet:
+ id: v64.2026-07-23T12:00:29
+ author: ranquild
+ comment: entity_id is NOT NULL on transform_transform_tag
+ changes:
+ - addNotNullConstraint:
+ tableName: transform_transform_tag
+ columnName: entity_id
+ columnDataType: char(21)
diff --git a/src/metabase/actions/models.clj b/src/metabase/actions/models.clj
index bfc1f0a87b6..ca2caac92d6 100644
--- a/src/metabase/actions/models.clj
+++ b/src/metabase/actions/models.clj
@@ -417,9 +417,6 @@
;;; ------------------------------------------------ Serialization ---------------------------------------------------
-(defmethod serdes/hash-fields :model/Action [_action]
- [:name (serdes/hydrated-hash :model) :created_at])
-
(defmethod serdes/generate-path "QueryAction" [_ _] nil)
(defmethod serdes/make-spec "QueryAction" [_model-name _opts]
{:copy []
diff --git a/src/metabase/auth_identity/models/auth_identity.clj b/src/metabase/auth_identity/models/auth_identity.clj
index 85222354724..b684a5f10f3 100644
--- a/src/metabase/auth_identity/models/auth_identity.clj
+++ b/src/metabase/auth_identity/models/auth_identity.clj
@@ -5,7 +5,6 @@
[java-time.api :as t]
[metabase.auth-identity.provider :as provider]
[metabase.models.interface :as mi]
- [metabase.models.serialization :as serdes]
[metabase.util :as u]
[metabase.util.log :as log]
[metabase.util.password :as u.password]
@@ -45,10 +44,6 @@
:out (comp parse-credentials-timestamps-out mi/encrypted-json-out)}
:metadata mi/transform-json})
-(defmethod serdes/hash-fields :model/AuthIdentity
- [_auth-identity]
- [:user_id :provider :created_at])
-
;;; ------------------------------------------------ Password Hashing ------------------------------------------------
(defn hash-password-credentials
diff --git a/src/metabase/channel/models/channel.clj b/src/metabase/channel/models/channel.clj
index 82d7e0f58f6..827dd66a3af 100644
--- a/src/metabase/channel/models/channel.clj
+++ b/src/metabase/channel/models/channel.clj
@@ -70,8 +70,6 @@
(defmethod serdes/entity-id "Channel" [_ {:keys [name]}] name)
-(defmethod serdes/hash-fields :model/Channel [_instance] [:name :type])
-
(defmethod serdes/load-find-local "Channel"
[path]
(t2/select-one :model/Channel :name (:id (last path))))
diff --git a/src/metabase/cmd/core.clj b/src/metabase/cmd/core.clj
index 2f84bc5b80b..6ba4504459f 100644
--- a/src/metabase/cmd/core.clj
+++ b/src/metabase/cmd/core.clj
@@ -208,19 +208,6 @@
[path & options]
(call-enterprise 'metabase-enterprise.serialization.cmd/v2-dump! path (get-parsed-options #'export options)))
-(defn ^:command seed-entity-ids
- "Add entity IDs for instances of serializable models that don't already have them."
- []
- (when-not (call-enterprise 'metabase-enterprise.serialization.cmd/seed-entity-ids!)
- (throw (Exception. "Error encountered while seeding entity IDs"))))
-
-(defn ^:command drop-entity-ids
- "Drop entity IDs for instances of serializable models. Useful for migrating from v1 serialization (x.46 and earlier)
- to v2 (x.47+)."
- []
- (when-not (call-enterprise 'metabase-enterprise.serialization.cmd/drop-entity-ids!)
- (throw (Exception. "Error encountered while dropping entity IDs"))))
-
(defn ^:command rotate-encryption-key
"Rotate the encryption key of a metabase database. The MB_ENCRYPTION_SECRET_KEY environment variable has to be set to
the current key, and the parameter `new-key` has to be the new key. `new-key` has to be at least 16 chars."
diff --git a/src/metabase/collections/models/collection.clj b/src/metabase/collections/models/collection.clj
index c466beafbb8..a1f3c19f425 100644
--- a/src/metabase/collections/models/collection.clj
+++ b/src/metabase/collections/models/collection.clj
@@ -2067,20 +2067,6 @@
[:not= (maybe-alias :namespace) [:inline "analytics"]]]
[:not (maybe-alias :is_sample)]]))
-(defn- parent-identity-hash [coll]
- (let [parent-id (-> coll
- (t2/hydrate :parent_id)
- :parent_id)
- parent (when parent-id (t2/select-one :model/Collection :id parent-id))]
- (cond
- (not parent-id) "ROOT"
- (not parent) (throw (ex-info (format "Collection %s is an orphan" (:id coll)) {:parent-id parent-id}))
- :else (serdes/identity-hash parent))))
-
-(defmethod serdes/hash-fields :model/Collection
- [_collection]
- [:name :namespace parent-identity-hash :created_at])
-
(defmethod serdes/extract-query "Collection" [_model {:keys [collection-set where skip-archived]}]
(let [not-trash-clause [:or
[:= :type nil]
diff --git a/src/metabase/dashboards/models/dashboard.clj b/src/metabase/dashboards/models/dashboard.clj
index d9f59cf1c1f..d7f10849b13 100644
--- a/src/metabase/dashboards/models/dashboard.clj
+++ b/src/metabase/dashboards/models/dashboard.clj
@@ -133,10 +133,6 @@
migrate-parameters-list
public-sharing/remove-public-uuid-if-public-sharing-is-disabled))
-(defmethod serdes/hash-fields :model/Dashboard
- [_dashboard]
- [:name (serdes/hydrated-hash :collection) :created_at])
-
;;; --------------------------------------------------- Hydration ----------------------------------------------------
(methodical/defmethod t2/batched-hydrate [:default :tabs]
diff --git a/src/metabase/dashboards/models/dashboard_card.clj b/src/metabase/dashboards/models/dashboard_card.clj
index 94ee27b1781..c627adc0448 100644
--- a/src/metabase/dashboards/models/dashboard_card.clj
+++ b/src/metabase/dashboards/models/dashboard_card.clj
@@ -91,16 +91,6 @@
;; headings render without a card background, matching the frontend default
(= display "heading") (assoc :dashcard.background false)))
-(defmethod serdes/hash-fields :model/DashboardCard
- [_dashboard-card]
- [(serdes/hydrated-hash :card) ; :card is optional, eg. text cards
- (comp serdes/identity-hash
- #(t2/select-one 'Dashboard :id %)
- :dashboard_id)
- :visualization_settings
- :row :col
- :created_at])
-
;;; --------------------------------------------------- HYDRATION ----------------------------------------------------
(mi/define-batched-hydration-method series
diff --git a/src/metabase/dashboards/models/dashboard_tab.clj b/src/metabase/dashboards/models/dashboard_tab.clj
index d78806fb635..3305fdbb911 100644
--- a/src/metabase/dashboards/models/dashboard_tab.clj
+++ b/src/metabase/dashboards/models/dashboard_tab.clj
@@ -48,15 +48,6 @@
(mi/perms-objects-set dashboard read-or-write)))
;;; ----------------------------------------------- SERIALIZATION ----------------------------------------------------
-(defmethod serdes/hash-fields :model/DashboardTab
- [_dashboard-tab]
- [:name
- (comp serdes/identity-hash
- #(t2/select-one :model/Dashboard :id %)
- :dashboard_id)
- :position
- :created_at])
-
(defmethod serdes/generate-path "DashboardTab" [_ dashcard]
[(serdes/infer-self-path "Dashboard" (t2/select-one :model/Dashboard :id (:dashboard_id dashcard)))
(serdes/infer-self-path "DashboardTab" dashcard)])
diff --git a/src/metabase/documents/models/document.clj b/src/metabase/documents/models/document.clj
index 25339e87376..78f5480730e 100644
--- a/src/metabase/documents/models/document.clj
+++ b/src/metabase/documents/models/document.clj
@@ -110,10 +110,6 @@
;;; ------------------------------------------------ Serdes Hashing -------------------------------------------------
-(defmethod serdes/hash-fields :model/Document
- [_table]
- [:name (serdes/hydrated-hash :collection) :created-at])
-
;;; ----------------------------------------------- Search ----------------------------------------------------------
(defn- document->search-text
diff --git a/src/metabase/embedding/models/theme.clj b/src/metabase/embedding/models/theme.clj
index 03b089d1a16..60c70dde2a0 100644
--- a/src/metabase/embedding/models/theme.clj
+++ b/src/metabase/embedding/models/theme.clj
@@ -22,10 +22,6 @@
;;;; serialization
-(defmethod serdes/hash-fields :model/EmbeddingTheme
- [_embedding-theme]
- [:name :created_at])
-
(defmethod serdes/make-spec "EmbeddingTheme"
[_model-name _opts]
{:copy [:entity_id :name :settings]
diff --git a/src/metabase/glossary/models/glossary.clj b/src/metabase/glossary/models/glossary.clj
index 04407ea09e6..6254152cb68 100644
--- a/src/metabase/glossary/models/glossary.clj
+++ b/src/metabase/glossary/models/glossary.clj
@@ -38,10 +38,6 @@
[path]
(t2/select-one :model/Glossary :term (:id (first path))))
-(defmethod serdes/hash-fields :model/Glossary
- [_item]
- [:term])
-
(defmethod serdes/make-spec "Glossary" [_model-name _opts]
{:copy [:term :definition]
:transform {:created_at (serdes/date)
diff --git a/src/metabase/measures/models/measure.clj b/src/metabase/measures/models/measure.clj
index 0ad66be8a2d..c1a69b2815a 100644
--- a/src/metabase/measures/models/measure.clj
+++ b/src/metabase/measures/models/measure.clj
@@ -186,10 +186,6 @@
;;; ------------------------------------------------ Serialization ---------------------------------------------------
-(defmethod serdes/hash-fields :model/Measure
- [_measure]
- [:name (serdes/hydrated-hash :table) :created_at])
-
(defmethod serdes/deserialization-dependencies "Measure" [{:keys [definition]}]
(serdes/mbql-deps false definition))
diff --git a/src/metabase/metabot/models/metabot.clj b/src/metabase/metabot/models/metabot.clj
index 5b8b6740fee..a5e0e3f90e9 100644
--- a/src/metabase/metabot/models/metabot.clj
+++ b/src/metabase/metabot/models/metabot.clj
@@ -37,10 +37,6 @@
;;; ------------------------------------------------- Serialization -------------------------------------------------
-(defmethod serdes/hash-fields :model/Metabot
- [_table]
- [:name])
-
(defmethod serdes/deserialization-dependencies "Metabot"
[{:keys [collection_id prompts]}]
(cond-> (set (mapcat serdes/deserialization-dependencies prompts))
diff --git a/src/metabase/metabot/models/metabot_prompt.clj b/src/metabase/metabot/models/metabot_prompt.clj
index f1f780d775a..b64cb3d09cd 100644
--- a/src/metabase/metabot/models/metabot_prompt.clj
+++ b/src/metabase/metabot/models/metabot_prompt.clj
@@ -20,10 +20,6 @@
;;; ------------------------------------------------- Serialization -------------------------------------------------
-(defmethod serdes/hash-fields :model/MetabotPrompt
- [_table]
- [:metabot_id :model :card_id :prompt])
-
(defmethod serdes/generate-path "MetabotPrompt" [_ entity]
(conj (serdes/generate-path "Metabot" (t2/select-one :model/Metabot (:metabot_id entity)))
(serdes/infer-self-path "MetabotPrompt" entity)))
diff --git a/src/metabase/metabot/tools/construct.clj b/src/metabase/metabot/tools/construct.clj
index 5cf4c552b32..5ffda087e00 100644
--- a/src/metabase/metabot/tools/construct.clj
+++ b/src/metabase/metabot/tools/construct.clj
@@ -180,8 +180,7 @@
"ContentStore for agent query construction. Alias for
[[shared.content-store/default-store]] — the chokepoint wrapper applies `api/read-check` to
every lookup whenever `api/*current-user-id*` is bound, symmetrically across all five
- ContentStore methods. The unchecked underlying store gates non-NanoID entity-id values to
- avoid a full-table scan via `find-by-identity-hash`."
+ ContentStore methods. The unchecked underlying store rejects non-NanoID entity-id values."
shared.content-store/default-store)
(defn- check-first-stage-source-table-query-permissions!
diff --git a/src/metabase/models/interface.clj b/src/metabase/models/interface.clj
index f483a45bbd4..50c4dcf9910 100644
--- a/src/metabase/models/interface.clj
+++ b/src/metabase/models/interface.clj
@@ -58,8 +58,8 @@
(def ^:dynamic *deserializing?*
"This is dynamically bound to true when deserializing. A few pieces of the Toucan magic are undesirable for
- deserialization. Most notably, we don't want to generate an `:entity_id`, as that would lead to duplicated entities
- on a future deserialization."
+ deserialization and are skipped based on this var. (Entity ids are not one of them: the insert hook generates an
+ `:entity_id` whenever it is missing, deserializing or not — ingested entities carry their own.)"
false)
(def ^{:arglists '([x & _args])} dispatch-on-model
@@ -565,12 +565,8 @@
add-updated-at-timestamp))
(defn- add-entity-id [obj & _]
- (if (or (contains? obj :entity_id)
- *deserializing?*)
- ;; Don't generate a new entity_id if either: (a) there's already one set; or (b) we're deserializing.
- ;; Generating them at deserialization time can lead to duplicated entities if they're deserialized again.
- obj
- (assoc obj :entity_id (u/generate-nano-id))))
+ (cond-> obj
+ (nil? (:entity_id obj)) (assoc :entity_id (u/generate-nano-id))))
(t2/define-before-insert :hook/entity-id
[instance]
diff --git a/src/metabase/models/serialization.clj b/src/metabase/models/serialization.clj
index cd33bd864b7..1a7e62de51f 100644
--- a/src/metabase/models/serialization.clj
+++ b/src/metabase/models/serialization.clj
@@ -152,6 +152,15 @@
(defmethod entity-id :default [_ instance]
(some-> instance :entity_id str/trim))
+(defn has-entity-id?
+ "Returns true if the model has an `:entity_id` column."
+ [model]
+ (or
+ ;; toucan1 models
+ (isa? model ::mi/entity-id)
+ ;; toucan2 models
+ (isa? model :hook/entity-id)))
+
(defn eid->id
"Given model name and its entity id, returns it database-local id.
@@ -166,125 +175,6 @@
(str/starts-with? eid "eid:") (subs 4))]
(t2/select-one-fn pk [model pk] :entity_id eid)))
-;;; ## Hashing entities
-;;; In the worst case, an entity is already present in two instances linked by serdes, and it doesn't have `entity_id`
-;;; set because it existed before we added the column. If we write a migration to just generate random `entity_id`s on
-;;; both sides, those entities will get duplicated on the next `import`.
-;;;
-;;; So every entity implements [[hash-fields]], which determines the set of fields whose values are used to generate the
-;;; hash. The 32-bit [[identity-hash]] is then used to seed the PRNG and generate a "random" NanoID. Since this is based
-;;; on properties of the entity, it is reproducible on both `export` and `import` sides, so entities are not duplicated.
-;;;
-;;; Before any `export` or `import`, [[metabase-enterprise.serialization.v2.backfill-ids/backfill-ids]] is called. It
-;;; does `SELECT * FROM SomeModel WHERE entity_id IS NULL` and populates all the blanks with this hash-based NanoID.
-;;;
-;;; <h3>Whoops, two kinds of backfill</h3>
-;;; Braden discovered in Nov 2023 that for more than a year, we've had two inconsistent ways to backfill all the
-;;; `entity_id` fields in an instance.
-;;;
-;;; 1. The one described above, [[metabase-enterprise.serialization.v2.backfill-ids/backfill-ids]] which runs before
-;;; any export or import.
-;;; 2. A separate JAR command `seed_entity_ids` which is powered by
-;;; [[metabase-enterprise.serialization.v2.entity-ids/seed-entity-ids!]] and uses the [[identity-hash]] hex strings
-;;; directly rather than seeding a NanoID with them.
-;;;
-;;; Therefore the import machinery has to look out for both kinds of IDs and use them. This is foolish and should be
-;;; simplified. We should write a Clojure-powered migration that finds any short 8-character `entity_id`s and generates
-;;; NanoIDs from them.
-
-(defn raw-hash
- "Hashes a Clojure value into an 8-character hex string, which is used as the identity hash.
-
- Don't call this outside a test, use [[identity-hash]] instead. Exception: [[metabase-enterprise.audit-app.audit]]
- uses this because it needs reproducible `:entity_id`s that differ from the usual [[hash-fields]] ones."
- [target]
- (when (sequential? target)
- (assert (seq target) "target cannot be an empty sequence"))
- (format "%08x" (hash target)))
-
-(defmulti hash-fields
- "Returns a seq of functions which will be transformed into a seq of values for hash calculation by calling each
- function on an entity map."
- {:arglists '([model-or-instance])}
- mi/dispatch-on-model)
-
-(defn- increment-hash-values
- "Potentially adds a new value to the list of input seq based on increment. Used to 'increment' a hash value to avoid duplicates."
- [values increment]
- (if (= increment 0)
- values
- (conj values (str "metabase-increment-" increment))))
-
-(defn identity-hash
- "Returns an identity hash string (8 hex digits) from an `entity` map.
-
- This string is generated by:
- - calling [[hash-fields]] for the model
- - passing the `entity` to each function it returns
- - calling [[hash]] on that list
- - converting to an 8-character hex string"
- ([entity]
- (identity-hash entity 0))
- ([entity increment]
- {:pre [(some? entity)]}
- (-> (for [f (hash-fields entity)]
- (f entity))
- (increment-hash-values increment)
- raw-hash)))
-
-(defn backfill-entity-id
- "Given an entity with a (possibly empty) `:entity_id` field:
- - Return the `:entity_id` if it's set.
- - Compute the backfill `:entity_id` based on the [[identity-hash]]."
- ([entity]
- (backfill-entity-id entity 0))
- ([entity increment]
- (or (:entity_id entity)
- (:entity-id entity)
- (u/generate-nano-id (identity-hash entity increment)))))
-
-(defn identity-hash?
- "Returns true if s is a valid identity hash string."
- [s]
- (resolve/identity-hash? s))
-
-;; ## Memoizing `hydrated-hash`
-;;
-;; Hashing a Field requires its Table; hashing a Table requires its Database.
-;; Letting each of those hit the appdb for every Field lookup (when it lacks an `entity_id`) is too costly,
-;; so we cache any that have to be looked up right here.
-;;
-;; Memory use is not a serious concern here, for two reasons:
-;; 1. This is caching the `hydrated-hash` lookups, so it doesn't cache Fields but only Tables and Databases.
-;; 2. This is called only when [[backfill-entity-id]] needs to generate an `entity_id` by hashing. Once the background
-;; job populates that column everywhere, this will always be empty.
-;;
-;; NOTE: To support Metabase upgrades where the new `entity_id`s might still be blank, this code will have to live on.
-;; But in practice once `entity_id`s are populated this cache will never be needed.
-(def ^:private hydrated-hash-cache
- (atom {}))
-
-(defn hydrated-hash
- "Returns a function which accepts an entity and returns the identity hash of
- the value of the hydrated property under key k.
-
- This is a helper for writing [[hash-fields]] implementations."
- ([k]
- (fn [entity]
- (or
- (some-> entity (t2/hydrate k) (get k) identity-hash)
- "<none>")))
- ([hydration-key cache-key]
- (let [inner-fn (hydrated-hash hydration-key)]
- (fn [entity]
- (let [the-key (cache-key entity)
- cached (swap! hydrated-hash-cache
- (fn [cache]
- (cond-> cache
- (-> cache hydration-key (get the-key) not)
- (assoc-in [hydration-key the-key] (delay (inner-fn entity))))))]
- (-> cached hydration-key (get the-key) deref))))))
-
;;; # Serdes paths and <tt>:serdes/meta</tt>
;;; The Clojure maps from extraction and ingestion always include a special key `:serdes/meta` giving some information
;;; about the serialized entity. The value is always a vector of maps that give a "path" to the entity. This is **not**
@@ -321,11 +211,8 @@
(defn infer-self-path
"Returns `{:model \"ModelName\" :id \"id-string\"}`"
[model-name entity]
- (let [model (t2.model/resolve-model (symbol model-name))
- pk (first (t2/primary-keys model))]
- {:model model-name
- :id (or (entity-id model-name entity)
- (some-> (get entity pk) model identity-hash))}))
+ {:model model-name
+ :id (entity-id model-name entity)})
(defn maybe-labeled
"Common helper for defining [[generate-path]] for an entity that is
@@ -806,8 +693,9 @@
Defaults to a straightforward [[(comp first t2/insert-returning-instances!)]] (returning the created object),
and you probably don't need to implement this.
- Note that any [[t2/insert!]] behavior we don't want to run (like generating an `:entity_id`!) should be skipped based
- on the [[mi/*deserializing?*]] dynamic var.
+ Any [[t2/insert!]] behavior we don't want to run during deserialization can be skipped based on the
+ [[mi/*deserializing?*]] dynamic var (entity ids are an exception: the insert hook always generates
+ one when it is missing, so NULLs are impossible).
Keyed on the model name (the first argument), because the second argument doesn't have its `:serdes/meta` anymore.
@@ -893,32 +781,15 @@
(default-load-one! ingested maybe-local))
(defn entity-id?
- "Checks if the given string is a 21-character NanoID. Useful for telling entity IDs apart from identity hashes."
+ "Checks if the given string is a 21-character NanoID."
[id-str]
(resolve/entity-id? id-str))
-;; TODO: Clean up this [[identity-hash]] infrastructure once the `seed_entity_ids` issue is fixed. See above on the
-;; details of the two hashing schemes.
-(mu/defn- find-by-identity-hash
- "Given a model and a target identity hash, this scans the appdb for any instance of the model corresponding to the
- hash. Does a complete scan, so this should be called sparingly!"
- ;; TODO This should be able to use a cache of identity-hash values from the start of the deserialization process.
- ;; Note that it needs to include either updates (or worst-case, invalidation) at [[load-one!]] time.
- [model :- ::model-keyword-or-symbol id-hash]
- (->> (t2/reducible-select model)
- (into [] (comp (filter #(= id-hash (identity-hash %)))
- (map t2.realize/realize)
- (take 1)))
- first))
-
(mu/defn lookup-by-id
- "Given an ID string, this endeavours to find the matching entity, whether it's an entity ID or identity hash.
- This is useful when writing [[xform-one]] to turn a foreign key from a portable form to an appdb ID.
- Returns a Toucan entity or nil."
+ "Given an entity ID string, finds the matching entity. This is useful when writing [[xform-one]] to
+ turn a foreign key from a portable form to an appdb ID. Returns a Toucan entity or nil."
[model :- ::model-keyword-or-symbol id-str]
- (if (entity-id? id-str)
- (t2/select-one model :entity_id id-str)
- (find-by-identity-hash model id-str)))
+ (t2/select-one model :entity_id id-str))
(defn storage-default-collection-path
"Implements the most common structure for [[storage-path]].
@@ -1016,9 +887,9 @@
"Given an identifier, and the model it represents (symbol, name or IModel), looks up the corresponding
entity and gets its primary key.
- The identifier can be a single entity ID string, a single identity-hash string, or a vector of entity ID and hash
- strings. If the ID is compound, then the last ID is the one that corresponds to the model. This allows for the
- compound IDs needed for nested entities like `DashboardCard`s to get their [[deserialization-dependencies]].
+ The identifier can be a single entity ID string, or a vector of entity ID strings. If the ID is
+ compound, then the last ID is the one that corresponds to the model. This allows for the compound IDs
+ needed for nested entities like `DashboardCard`s to get their [[deserialization-dependencies]].
Throws if the corresponding entity cannot be found.
@@ -1323,11 +1194,10 @@
:else x))))
(defn- portable-id?
- "True if the provided string is either an Entity ID or identity-hash string."
+ "True if the provided string is an Entity ID."
[s]
(and (string? s)
- (or (entity-id? s)
- (identity-hash? s))))
+ (entity-id? s)))
(declare import-mbql*)
@@ -1990,24 +1860,12 @@
(doseq [ingested lst]
(load-one! (enrich ingested) nil)))
- (entity-id? first-eid) ; proper entity id, match by them
+ :else ; match by entity id
(do (t2/delete! model backward-fk parent-id :entity_id [:not-in (map :entity_id lst)])
(doseq [ingested lst
:let [ingested (enrich ingested)
local (lookup-by-id model (entity-id model-name ingested))]]
- (load-one! ingested local)))
-
- :else ; identity hash
- (let [incoming (set (map #(entity-id model-name %) lst))
- local (->> (t2/reducible-select model backward-fk parent-id)
- (into [] (map t2.realize/realize))
- (m/index-by identity-hash))
- to-delete (into [] (comp (filter #(contains? incoming (key %)))
- (map #(:id (val %))))
- local)]
- (t2/delete! model :id [:in (map :id to-delete)])
- (doseq [ingested lst]
- (load-one! (enrich ingested) (get local (entity-id model-name ingested))))))))}))
+ (load-one! ingested local))))))}))
(def parent-ref "Transformer for parent id for nested entities."
(constantly
diff --git a/src/metabase/models/serialization/resolve.clj b/src/metabase/models/serialization/resolve.clj
index 27dbbd04003..1ba769bfdc1 100644
--- a/src/metabase/models/serialization/resolve.clj
+++ b/src/metabase/models/serialization/resolve.clj
@@ -57,17 +57,11 @@
(string? id-str)
(re-matches #"^[A-Za-z0-9_-]{21}$" id-str))))
-(defn identity-hash?
- "Returns true if s is a valid identity hash string."
- [s]
- (boolean (re-matches #"^[0-9a-fA-F]{8}$" s)))
-
(defn- portable-id?
- "True if the provided string is either an Entity ID or identity-hash string."
+ "True if the provided string is an Entity ID."
[s]
(and (string? s)
- (or (entity-id? s)
- (identity-hash? s))))
+ (entity-id? s)))
(defn serialized-query-source-table
"Given a serialized query (with portable references), returns the portable reference of the table it is based
diff --git a/src/metabase/models/serialization/resolve/mp.clj b/src/metabase/models/serialization/resolve/mp.clj
index 693ff05c361..3ad60441629 100644
--- a/src/metabase/models/serialization/resolve/mp.clj
+++ b/src/metabase/models/serialization/resolve/mp.clj
@@ -315,10 +315,9 @@
`serdes/lookup-by-id`. Use this in production code paths that already have an app DB; pass a
different store implementation when running without one (checker, isolated tests).
- Gated on [[resolve/entity-id?]]: `serdes/lookup-by-id` falls through to a full-table scan via
- `find-by-identity-hash` for non-NanoID strings. LLM-authored entity-id values are untrusted,
- so anything that isn't a 21-char NanoID short-circuits to `nil` and the caller surfaces a
- clear `:unknown-…` agent error."
+ Gated on [[resolve/entity-id?]]: LLM-authored entity-id values are untrusted, so anything that
+ isn't a 21-char NanoID short-circuits to `nil` and the caller surfaces a clear `:unknown-…`
+ agent error."
(reify ContentStore
(card-by-entity-id [_ entity-id]
(when (resolve/entity-id? entity-id)
diff --git a/src/metabase/native_query_snippets/models/native_query_snippet.clj b/src/metabase/native_query_snippets/models/native_query_snippet.clj
index 03256bdcb37..84cb6db89a4 100644
--- a/src/metabase/native_query_snippets/models/native_query_snippet.clj
+++ b/src/metabase/native_query_snippets/models/native_query_snippet.clj
@@ -110,10 +110,6 @@
(u/prog1 snippet
(events/publish-event! :event/snippet-delete {:object <> :user-id api/*current-user-id*})))
-(defmethod serdes/hash-fields :model/NativeQuerySnippet
- [_snippet]
- [:name (serdes/hydrated-hash :collection) :created_at])
-
(defmethod mi/can-read? :model/NativeQuerySnippet
[& args]
(apply snippet.perms/can-read? args))
diff --git a/src/metabase/osi/models/osi_ai_context.clj b/src/metabase/osi/models/osi_ai_context.clj
index ca76e0bfbf0..daabb4ebe71 100644
--- a/src/metabase/osi/models/osi_ai_context.clj
+++ b/src/metabase/osi/models/osi_ai_context.clj
@@ -124,10 +124,6 @@
(defmethod serdes/entity-id "OsiAiContext" [_ _] nil)
-(defmethod serdes/hash-fields :model/OsiAiContext
- [_model]
- [:entity_type :entity_local_id])
-
(defmethod serdes/generate-path "OsiAiContext" [_ {:keys [entity_type entity_local_id]}]
(conj (vec (entity-parent-path entity_type entity_local_id))
{:model "OsiAiContext" :id "ai_context"}))
diff --git a/src/metabase/permissions/models/permissions_group.clj b/src/metabase/permissions/models/permissions_group.clj
index 11f5d9e42b9..3aff38aafac 100644
--- a/src/metabase/permissions/models/permissions_group.clj
+++ b/src/metabase/permissions/models/permissions_group.clj
@@ -10,7 +10,6 @@
(:require
[metabase.app-db.core :as mdb]
[metabase.models.interface :as mi]
- [metabase.models.serialization :as serdes]
[metabase.permissions.models.data-permissions :as data-perms]
[metabase.premium-features.core :as premium-features]
[metabase.settings.core :as setting]
@@ -33,10 +32,6 @@
(derive :metabase/model)
(derive :hook/entity-id))
-(defmethod serdes/hash-fields :model/PermissionsGroup
- [_user]
- [:name])
-
;;; -------------------------------------------- Magic Groups Getter Fns ---------------------------------------------
(defn- magic-group [magic-group-type]
diff --git a/src/metabase/queries/models/card.clj b/src/metabase/queries/models/card.clj
index 4579a2feb4e..632d473ad55 100644
--- a/src/metabase/queries/models/card.clj
+++ b/src/metabase/queries/models/card.clj
@@ -902,10 +902,6 @@
:where [:= :card_id id]}]))]
(t2/delete! :model/Notification :id [:in notification-ids])))
-(defmethod serdes/hash-fields :model/Card
- [_card]
- [:name (serdes/hydrated-hash :collection) :created_at])
-
(defmethod mi/exclude-internal-content-hsql :model/Card
[_model & {:keys [table-alias]}]
[:not= (h2x/identifier :field table-alias :creator_id) config/internal-mb-user-id])
diff --git a/src/metabase/segments/models/segment.clj b/src/metabase/segments/models/segment.clj
index 66e34e9282e..5cc642fc77a 100644
--- a/src/metabase/segments/models/segment.clj
+++ b/src/metabase/segments/models/segment.clj
@@ -213,10 +213,6 @@
;;; ------------------------------------------------ Serialization ---------------------------------------------------
-(defmethod serdes/hash-fields :model/Segment
- [_segment]
- [:name (serdes/hydrated-hash :table) :created_at])
-
(defmethod serdes/deserialization-dependencies "Segment" [{:keys [definition]}]
(serdes/mbql-deps false definition))
diff --git a/src/metabase/settings/models/setting.clj b/src/metabase/settings/models/setting.clj
index 6d5367f9031..e0a912a2814 100644
--- a/src/metabase/settings/models/setting.clj
+++ b/src/metabase/settings/models/setting.clj
@@ -84,10 +84,6 @@
(methodical/defmethod t2/primary-keys :model/Setting [_model] [:key])
-(defmethod serdes/hash-fields :model/Setting
- [_setting]
- [:key])
-
(declare export?)
(defmethod serdes/extract-all "Setting" [_model _opts]
diff --git a/src/metabase/timeline/models/timeline.clj b/src/metabase/timeline/models/timeline.clj
index ee67759a71a..ab6f8f4343e 100644
--- a/src/metabase/timeline/models/timeline.clj
+++ b/src/metabase/timeline/models/timeline.clj
@@ -48,10 +48,6 @@
;;;; serialization
-(defmethod serdes/hash-fields :model/Timeline
- [_timeline]
- [:name (serdes/hydrated-hash :collection) :created_at])
-
(defmethod serdes/deserialization-dependencies "Timeline" [{:keys [collection_id]}]
[[{:model "Collection" :id collection_id}]])
diff --git a/src/metabase/timeline/models/timeline_event.clj b/src/metabase/timeline/models/timeline_event.clj
index fdc6ea013da..69725a082f3 100644
--- a/src/metabase/timeline/models/timeline_event.clj
+++ b/src/metabase/timeline/models/timeline_event.clj
@@ -120,10 +120,6 @@
;;;; model
-(defmethod serdes/hash-fields :model/TimelineEvent
- [_timeline-event]
- [:name :timestamp (serdes/hydrated-hash :timeline) :created_at])
-
;;;; serialization
;; nested in Timeline
diff --git a/src/metabase/transforms/models/transform.clj b/src/metabase/transforms/models/transform.clj
index ce07f857443..36c36c99099 100644
--- a/src/metabase/transforms/models/transform.clj
+++ b/src/metabase/transforms/models/transform.clj
@@ -434,10 +434,6 @@
(assoc transform :table
(get id->table (:target_table_id transform))))))
-(defmethod serdes/hash-fields :model/Transform
- [_transform]
- [:name :created_at])
-
(defn- import-maybe-int-database-fk
"Import a database reference back to an ID. Tolerates raw numeric IDs from older exports
where source-tables database_id values were serialized without conversion."
diff --git a/src/metabase/transforms/models/transform_job.clj b/src/metabase/transforms/models/transform_job.clj
index ba544235302..a9835ffa9bb 100644
--- a/src/metabase/transforms/models/transform_job.clj
+++ b/src/metabase/transforms/models/transform_job.clj
@@ -208,10 +208,6 @@
(for [job jobs]
(assoc job :job_tags (get tag-mappings (u/the-id job) []))))))
-(defmethod serdes/hash-fields :model/TransformJob
- [_job]
- [:name :built_in_type])
-
(defmethod serdes/make-spec "TransformJob"
[_model-name opts]
{:copy [:entity_id :built_in_type :schedule :ui_display_type :active]
diff --git a/src/metabase/transforms/models/transform_job_transform_tag.clj b/src/metabase/transforms/models/transform_job_transform_tag.clj
index 0dfc0493490..6246e1fd00d 100644
--- a/src/metabase/transforms/models/transform_job_transform_tag.clj
+++ b/src/metabase/transforms/models/transform_job_transform_tag.clj
@@ -12,10 +12,6 @@
(derive :metabase/model)
(derive :hook/entity-id))
-(defmethod serdes/hash-fields :model/TransformJobTransformTag
- [_job-tag]
- [:job_id :tag_id :position])
-
(defmethod serdes/make-spec "TransformJobTransformTag"
[_model-name _opts]
{:copy [:entity_id :position]
diff --git a/src/metabase/transforms/models/transform_tag.clj b/src/metabase/transforms/models/transform_tag.clj
index a6ae9ebdf12..0277204115b 100644
--- a/src/metabase/transforms/models/transform_tag.clj
+++ b/src/metabase/transforms/models/transform_tag.clj
@@ -111,10 +111,6 @@
tag-id->transform-ids)]
(mapv #(assoc % :can_run (get tag-id->can-run (:id %) true)) tags))))
-(defmethod serdes/hash-fields :model/TransformTag
- [_tt]
- [:name :built_in_type])
-
(defmethod serdes/make-spec "TransformTag"
[_model-name _opts]
{:copy [:entity_id :built_in_type]
diff --git a/src/metabase/transforms/models/transform_transform_tag.clj b/src/metabase/transforms/models/transform_transform_tag.clj
index 61e93412c75..6e4d1a9a1d9 100644
--- a/src/metabase/transforms/models/transform_transform_tag.clj
+++ b/src/metabase/transforms/models/transform_transform_tag.clj
@@ -12,10 +12,6 @@
(derive :metabase/model)
(derive :hook/entity-id))
-(defmethod serdes/hash-fields :model/TransformTransformTag
- [_transform-transform-tag]
- [:transform_id :tag_id :position])
-
(defmethod serdes/make-spec "TransformTransformTag"
[_model-name _opts]
{:copy [:entity_id :position]
diff --git a/src/metabase/users/models/user.clj b/src/metabase/users/models/user.clj
index 75117353f3a..3ffdadfc4bd 100644
--- a/src/metabase/users/models/user.clj
+++ b/src/metabase/users/models/user.clj
@@ -8,7 +8,6 @@
[metabase.config.core :as config]
[metabase.events.core :as events]
[metabase.models.interface :as mi]
- [metabase.models.serialization :as serdes]
[metabase.permissions.core :as perms]
[metabase.premium-features.core :as premium-features]
[metabase.settings.core :as setting]
@@ -366,10 +365,6 @@
(t2.default-fields/define-default-fields :model/User default-user-columns)
-(defmethod serdes/hash-fields :model/User
- [_user]
- [:email])
-
(defn group-ids
"Fetch set of IDs of PermissionsGroup a User belongs to."
[user-or-id]
diff --git a/src/metabase/warehouse_schema/models/dimension.clj b/src/metabase/warehouse_schema/models/dimension.clj
index 832053df4cb..e2bc4a3b81a 100644
--- a/src/metabase/warehouse_schema/models/dimension.clj
+++ b/src/metabase/warehouse_schema/models/dimension.clj
@@ -23,12 +23,6 @@
(t2/deftransforms :model/Dimension
{:type mi/transform-keyword})
-(defmethod serdes/hash-fields :model/Dimension
- [_dimension]
- [(serdes/hydrated-hash :field)
- (serdes/hydrated-hash :human_readable_field)
- :created_at])
-
(defmethod serdes/make-spec "Dimension" [_model-name _opts]
{:copy [:name :type :entity_id]
:skip []
diff --git a/src/metabase/warehouse_schema/models/field.clj b/src/metabase/warehouse_schema/models/field.clj
index c4b9379aee6..d7d4cb9879a 100644
--- a/src/metabase/warehouse_schema/models/field.clj
+++ b/src/metabase/warehouse_schema/models/field.clj
@@ -269,10 +269,6 @@
:id
{:default false})))
-(defmethod serdes/hash-fields :model/Field
- [_field]
- [:name (serdes/hydrated-hash :table :table_id) (serdes/hydrated-hash :parent :parent_id)])
-
;;; ---------------------------------------------- Hydration / Util Fns ----------------------------------------------
(defn values
diff --git a/src/metabase/warehouse_schema/models/field_user_settings.clj b/src/metabase/warehouse_schema/models/field_user_settings.clj
index 48068517f31..c1d7c7533ae 100644
--- a/src/metabase/warehouse_schema/models/field_user_settings.clj
+++ b/src/metabase/warehouse_schema/models/field_user_settings.clj
@@ -34,10 +34,6 @@
(t2/insert! :model/FieldUserSettings {:field_id id}))
(t2/update! :model/FieldUserSettings id filtered-settings)))
-(defmethod serdes/hash-fields :model/FieldUserSettings
- [_field-values]
- [(serdes/hydrated-hash :field)])
-
(defmethod serdes/entity-id "FieldUserSettings" [_ _] nil)
(defmethod serdes/generate-path "FieldUserSettings" [_ {:keys [field_id]}]
diff --git a/src/metabase/warehouse_schema/models/field_values.clj b/src/metabase/warehouse_schema/models/field_values.clj
index 85827de54c7..a31d8f203f2 100644
--- a/src/metabase/warehouse_schema/models/field_values.clj
+++ b/src/metabase/warehouse_schema/models/field_values.clj
@@ -223,10 +223,6 @@
:else
[])))))
-(defmethod serdes/hash-fields :model/FieldValues
- [_field-values]
- [(serdes/hydrated-hash :field)])
-
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | Utils fns |
;;; +----------------------------------------------------------------------------------------------------------------+
diff --git a/src/metabase/warehouse_schema/models/table.clj b/src/metabase/warehouse_schema/models/table.clj
index 93625f58725..d2850cbd4c7 100644
--- a/src/metabase/warehouse_schema/models/table.clj
+++ b/src/metabase/warehouse_schema/models/table.clj
@@ -423,10 +423,6 @@
;;; ------------------------------------------------ Serdes Hashing -------------------------------------------------
-(defmethod serdes/hash-fields :model/Table
- [_table]
- [:schema :name (serdes/hydrated-hash :db :db_id)])
-
;;; ------------------------------------------------ Field ordering -------------------------------------------------
(def field-order-rule
diff --git a/src/metabase/warehouses/models/database.clj b/src/metabase/warehouses/models/database.clj
index b4f805dc07e..b28eb248f95 100644
--- a/src/metabase/warehouses/models/database.clj
+++ b/src/metabase/warehouses/models/database.clj
@@ -555,10 +555,6 @@
maybe-disable-uploads-for-all-dbs!
infer-db-schedules))
-(defmethod serdes/hash-fields :model/Database
- [_database]
- [:name :engine])
-
(defmethod mi/exclude-internal-content-hsql :model/Database
[_model & {:keys [table-alias]}]
(let [maybe-alias #(h2x/identifier :field table-alias %)]
diff --git a/test/metabase/app_db/custom_migrations/pulse_to_notification_test.clj b/test/metabase/app_db/custom_migrations/pulse_to_notification_test.clj
index 1ad6eae89de..f8a4bab01e9 100644
--- a/test/metabase/app_db/custom_migrations/pulse_to_notification_test.clj
+++ b/test/metabase/app_db/custom_migrations/pulse_to_notification_test.clj
@@ -7,6 +7,7 @@
[metabase.pulse.task.send-pulses :as task.send-pulses]
[metabase.task.core :as task]
[metabase.test :as mt]
+ [metabase.util :as u]
[metabase.util.json :as json]
[toucan2.core :as t2]))
@@ -48,8 +49,8 @@
(defn- create-pulse!
[pulse pulse-cards pcs+recipients]
- (let [pulse-id (t2/insert-returning-pk! :pulse (add-timestamp pulse))]
- (t2/insert! :pulse_card (map #(assoc % :pulse_id pulse-id) pulse-cards))
+ (let [pulse-id (t2/insert-returning-pk! :pulse (assoc (add-timestamp pulse) :entity_id (u/generate-nano-id)))]
+ (t2/insert! :pulse_card (map #(assoc % :pulse_id pulse-id :entity_id (u/generate-nano-id)) pulse-cards))
(doseq [pcr pcs+recipients]
(let [pc-id (t2/insert-returning-pk! :model/PulseChannel (-> pcr (assoc :pulse_id pulse-id) (dissoc :recipients) add-timestamp))]
(when (seq (:recipients pcr))
diff --git a/test/metabase/cmd/core_test.clj b/test/metabase/cmd/core_test.clj
index 3f451aa47de..bc5beae2333 100644
--- a/test/metabase/cmd/core_test.clj
+++ b/test/metabase/cmd/core_test.clj
@@ -9,7 +9,7 @@
(deftest ^:parallel error-message-test
(is (=? ["Unrecognized command: 'a-command-that-does-not-exist'"
- #"\QValid commands: version, help, drop-entity-ids, import,\E.*"]
+ #"\QValid commands: version, help, import,\E.*"]
(#'cmd/validate "a-command-that-does-not-exist" [])))
(is (= ["The 'rotate-encryption-key' command requires the following arguments: [new-key], but received: []."]
(#'cmd/validate "rotate-encryption-key" [])))
diff --git a/test/metabase/collections/models/collection_test.clj b/test/metabase/collections/models/collection_test.clj
index 2cc05e4ccb5..90adaf34e62 100644
--- a/test/metabase/collections/models/collection_test.clj
+++ b/test/metabase/collections/models/collection_test.clj
@@ -1670,34 +1670,6 @@
(clean (collection/collections->tree {:card #{1 5} :dataset #{3 4}}
collections))))))
-(deftest identity-hash-test
- (testing "Collection hashes are composed of the name, namespace, and parent collection's hash"
- (let [now #t "2022-09-01T12:34:56Z"]
- (mt/with-temp [:model/Collection c1 {:name "top level"
- :created_at now
- :namespace "yolocorp"
- :location "/"}
- :model/Collection c2 {:name "nested"
- :created_at now
- :namespace "yolocorp"
- :location (format "/%s/" (:id c1))}
- :model/Collection c3 {:name "grandchild"
- :created_at now
- :namespace "yolocorp"
- :location (format "/%s/%s/" (:id c1) (:id c2))}]
- (let [c1-hash (serdes/identity-hash c1)
- c2-hash (serdes/identity-hash c2)]
- (is (= "f2620cc6"
- (serdes/raw-hash ["top level" :yolocorp "ROOT" (:created_at c1)])
- c1-hash)
- "Top-level collections should use a parent hash of 'ROOT'")
- (is (= "a27aef0f"
- (serdes/raw-hash ["nested" :yolocorp c1-hash (:created_at c2)])
- c2-hash))
- (is (= "e816af2d"
- (serdes/raw-hash ["grandchild" :yolocorp c2-hash (:created_at c3)])
- (serdes/identity-hash c3))))))))
-
;;; TODO -- does this belong here, or in the `audit-app` module?
(deftest instance-analytics-collections-test
(testing "Instance analytics and it's contents isn't writable, even for admins."
diff --git a/test/metabase/dashboards/models/dashboard_card_test.clj b/test/metabase/dashboards/models/dashboard_card_test.clj
index c12a131e1ab..1154a1b4c26 100644
--- a/test/metabase/dashboards/models/dashboard_card_test.clj
+++ b/test/metabase/dashboards/models/dashboard_card_test.clj
@@ -3,7 +3,6 @@
[clojure.test :refer :all]
[metabase.dashboards.models.dashboard :as dashboard]
[metabase.dashboards.models.dashboard-card :as dashboard-card]
- [metabase.models.serialization :as serdes]
[metabase.queries.models.card-test :as card-test]
[metabase.test :as mt]
[metabase.util :as u]
@@ -284,22 +283,6 @@
(is (= expected
(t2/select-one-fn :visualization_settings :model/DashboardCard :id (u/the-id dashcard))))))))))
-(deftest ^:parallel identity-hash-test
- (testing "Dashboard card hashes are composed of the card hash, dashboard hash, and visualization settings"
- (let [now #t "2022-09-01T12:34:56Z"]
- (mt/with-temp [:model/Collection c1 {:name "top level" :location "/" :created_at now}
- :model/Dashboard dash {:name "my dashboard" :collection_id (:id c1) :created_at now}
- :model/Card card {:name "some question" :collection_id (:id c1) :created_at now}
- :model/DashboardCard dashcard {:card_id (:id card)
- :dashboard_id (:id dash)
- :visualization_settings {}
- :row 6
- :col 3
- :created_at now}]
- (is (= "1311d6dc"
- (serdes/raw-hash [(serdes/identity-hash card) (serdes/identity-hash dash) {} 6 3 (:created_at dashcard)])
- (serdes/identity-hash dashcard)))))))
-
(deftest ^:parallel from-decoded-json-test
(testing "Dashboard Cards should remain the same if they are serialized to JSON,
deserialized, and finally transformed with `from-parsed-json`."
diff --git a/test/metabase/dashboards/models/dashboard_test.clj b/test/metabase/dashboards/models/dashboard_test.clj
index e76d3d2a9ac..e61421a09da 100644
--- a/test/metabase/dashboards/models/dashboard_test.clj
+++ b/test/metabase/dashboards/models/dashboard_test.clj
@@ -296,15 +296,6 @@
:values_source_config {:card_id card-id, :value_field [:field 2 nil]}}]
(t2/select-one-fn :parameters :model/Dashboard :id dashboard-id))))))
-(deftest ^:parallel identity-hash-test
- (testing "Dashboard hashes are composed of the name and parent collection's hash"
- (let [now #t "2022-09-01T12:34:56Z"]
- (mt/with-temp [:model/Collection c1 {:name "top level" :location "/" :created_at now}
- :model/Dashboard dash {:name "my dashboard" :collection_id (:id c1) :created_at now}]
- (is (= "8cbf93b7"
- (serdes/raw-hash ["my dashboard" (serdes/identity-hash c1) (:created_at dash)])
- (serdes/identity-hash dash)))))))
-
(deftest ^:parallel descendants-test
(testing "dashboard which have parameter's source is another card"
(mt/with-temp
diff --git a/test/metabase/health_inspector/core_test.clj b/test/metabase/health_inspector/core_test.clj
index 3584ec145ae..fe2fd0208da 100644
--- a/test/metabase/health_inspector/core_test.clj
+++ b/test/metabase/health_inspector/core_test.clj
@@ -2,7 +2,9 @@
(:require
[clojure.test :refer :all]
[metabase.health-inspector.core :as hi]
+ [metabase.lib.core :as lib]
[metabase.test :as mt]
+ [metabase.util :as u]
[metabase.util.json :as json]
[toucan2.core :as t2]))
@@ -21,19 +23,22 @@
(is (= 100 (-> report :validate-queries :health))))))
(deftest validate-queries*-works
- (let [bad-query {"database" 1
- "query" {"expressions" "extremely invalid"
- "source-table" 2}
- "type" "query"}
- bad-card (assoc (dissoc (t2/select-one :report_card) :id :entity_id)
- :dataset_query (json/encode bad-query)
- :description "bad query")
- bad (t2/insert! :report_card bad-card)]
- (try
- (let [{:keys [health message]} (hi/validate-queries)]
- (is (< 0 health 100))
- (is (= "Some queries are invalid." message)))
- (finally (t2/delete! :report_card bad)))))
+ ;; the raw :report_card copy below clones this template, so the test works in isolation
+ (mt/with-temp [:model/Card template {:dataset_query (lib/native-query (mt/metadata-provider) "SELECT 1")}]
+ (let [bad-query {"database" 1
+ "query" {"expressions" "extremely invalid"
+ "source-table" 2}
+ "type" "query"}
+ bad-card (assoc (dissoc (t2/select-one :report_card :id (:id template)) :id)
+ :entity_id (u/generate-nano-id)
+ :dataset_query (json/encode bad-query)
+ :description "bad query")
+ bad (t2/insert! :report_card bad-card)]
+ (try
+ (let [{:keys [health message]} (hi/validate-queries)]
+ (is (< 0 health 100))
+ (is (= "Some queries are invalid." message)))
+ (finally (t2/delete! :report_card bad))))))
(deftest report-db-test
(t2/delete! :health_inspector_runs)
diff --git a/test/metabase/measures/models/measure_test.clj b/test/metabase/measures/models/measure_test.clj
index 548cb03c11e..a26891be8a8 100644
--- a/test/metabase/measures/models/measure_test.clj
+++ b/test/metabase/measures/models/measure_test.clj
@@ -4,7 +4,6 @@
[metabase.lib.core :as lib]
[metabase.lib.metadata :as lib.metadata]
[metabase.models.interface :as mi]
- [metabase.models.serialization :as serdes]
[metabase.permissions.core :as perms]
[metabase.permissions.models.data-permissions :as data-perms]
[metabase.request.session :as session]
@@ -41,15 +40,6 @@
[referenced-measure-id]
(measure-definition [:measure {:lib/uuid (str (random-uuid))} referenced-measure-id]))
-(deftest identity-hash-test
- (testing "Measure hashes are composed of the measure name and table identity-hash"
- (let [now #t "2022-09-01T12:34:56Z"
- table (t2/select-one :model/Table (mt/id :venues))]
- (mt/with-temp [:model/Measure measure {:name "total sales" :table_id (:id table) :created_at now
- :definition (measure-definition (lib/count))}]
- (is (= (serdes/raw-hash ["total sales" (serdes/identity-hash table) (:created_at measure)])
- (serdes/identity-hash measure)))))))
-
(deftest update-measure-cycle-detection-test
(testing "Updating a measure to reference a non-existent measure should fail"
(mt/with-temp [:model/Measure {measure-id :id} {:name "Measure"
diff --git a/test/metabase/native_query_snippets/models/native_query_snippet_test.clj b/test/metabase/native_query_snippets/models/native_query_snippet_test.clj
index 4c3cdbf1d1b..b7bb32635a2 100644
--- a/test/metabase/native_query_snippets/models/native_query_snippet_test.clj
+++ b/test/metabase/native_query_snippets/models/native_query_snippet_test.clj
@@ -57,15 +57,6 @@
#"A NativeQuerySnippet can only go in Collections in the :snippets namespace"
(t2/update! :model/NativeQuerySnippet snippet-id {:collection_id dest-collection-id})))))))
-(deftest identity-hash-test
- (testing "Native query snippet hashes are composed of the name and the collection's hash"
- (let [now #t "2022-09-01T12:34:56Z"]
- (mt/with-temp [:model/Collection coll {:name "field-db" :namespace :snippets :location "/" :created_at now}
- :model/NativeQuerySnippet snippet {:name "my snippet" :collection_id (:id coll) :created_at now}]
- (is (= "7ac51ad0"
- (serdes/raw-hash ["my snippet" (serdes/identity-hash coll) (:created_at snippet)])
- (serdes/identity-hash snippet)))))))
-
(deftest basic-param-finding-test
(testing "Can find params in a snippet"
(mt/with-temp [:model/NativeQuerySnippet {snippet-id :id} {:name "my snippet" :content "{{id}}"}]
diff --git a/test/metabase/queries/models/card_test.clj b/test/metabase/queries/models/card_test.clj
index ab54ee7d91b..0fe398b7cbe 100644
--- a/test/metabase/queries/models/card_test.clj
+++ b/test/metabase/queries/models/card_test.clj
@@ -539,15 +539,6 @@
:target [:dimension [:field 1 nil]]}]
(t2/select-one-fn :parameter_mappings :model/Card :id card-id))))))
-(deftest ^:parallel identity-hash-test
- (testing "Card hashes are composed of the name and the collection's hash"
- (let [now #t "2022-09-01T12:34:56Z"]
- (mt/with-temp [:model/Collection coll {:name "field-db" :location "/" :created_at now}
- :model/Card card {:name "the card" :collection_id (:id coll) :created_at now}]
- (is (= "5199edf0"
- (serdes/raw-hash ["the card" (serdes/identity-hash coll) (:created_at card)])
- (serdes/identity-hash card)))))))
-
(deftest parameter-card-test
(let [default-params {:name "Category Name"
:slug "category_name"
diff --git a/test/metabase/segments/models/segment_test.clj b/test/metabase/segments/models/segment_test.clj
index 520427be8f7..588187ddbab 100644
--- a/test/metabase/segments/models/segment_test.clj
+++ b/test/metabase/segments/models/segment_test.clj
@@ -3,7 +3,6 @@
(:require
[clojure.test :refer :all]
[metabase.models.interface :as mi]
- [metabase.models.serialization :as serdes]
[metabase.permissions.core :as perms]
[metabase.permissions.models.data-permissions :as data-perms]
[metabase.request.session :as session]
@@ -81,17 +80,6 @@
(is (= 0
(t2/update! :model/Segment id {:creator_id (mt/user->id :rasta)})))))))
-(deftest identity-hash-test
- (testing "Segment hashes are composed of the segment name and table identity-hash"
- (let [now #t "2022-09-01T12:34:56Z"]
- (mt/with-temp [:model/Database db {:name "field-db" :engine :h2}
- :model/Table table {:schema "PUBLIC" :name "widget" :db_id (:id db)}
- :model/Segment segment {:name "big customers" :table_id (:id table) :created_at now
- :definition {:filter 1000}}]
- (is (= "be199b7c"
- (serdes/raw-hash ["big customers" (serdes/identity-hash table) (:created_at segment)])
- (serdes/identity-hash segment)))))))
-
(deftest definition-description-missing-definition-test
(testing "Do not hydrate definition description if definition is nil"
(mt/with-temp [:model/Segment {id :id} {:name "Segment"
diff --git a/test/metabase/settings/models/setting_test.clj b/test/metabase/settings/models/setting_test.clj
index 3127bbc1e12..94945cb9fad 100644
--- a/test/metabase/settings/models/setting_test.clj
+++ b/test/metabase/settings/models/setting_test.clj
@@ -8,7 +8,6 @@
[metabase.app-db.connection :as mdb.connection]
[metabase.app-db.core :as mdb]
[metabase.config.core :as config]
- [metabase.models.serialization :as serdes]
[metabase.settings.models.setting :as setting :refer [defsetting]]
[metabase.settings.models.setting.cache :as setting.cache]
[metabase.test :as mt]
@@ -1168,14 +1167,6 @@
#"Setting test-warn-vs-error-setting is not enabled for this database"
(setting/validate-settable-for-db! :test-warn-vs-error-setting db-with-error every-feature)))))))
-(deftest identity-hash-test
- (testing "Settings are hashed based on the key"
- (mt/with-temporary-setting-values [test-setting-1 "123"
- test-setting-2 "123"]
- (is (= "5f7f150c"
- (serdes/raw-hash ["test-setting-1"])
- (serdes/identity-hash (t2/select-one :model/Setting :key "test-setting-1")))))))
-
(deftest enabled?-test
(testing "Settings can be disabled"
(testing "With no default returns nil"
diff --git a/test/metabase/test/util.clj b/test/metabase/test/util.clj
index 4d517b55990..f7c8b92e004 100644
--- a/test/metabase/test/util.clj
+++ b/test/metabase/test/util.clj
@@ -124,10 +124,12 @@
:visualization_settings {}}))
:model/Collection
- (fn [_] (default-created-at-timestamped {:name (u.random/random-name)}))
+ (fn [_] (default-created-at-timestamped {:entity_id (u/generate-nano-id)
+ :name (u.random/random-name)}))
:model/Action
- (fn [_] {:creator_id (rasta-id)})
+ (fn [_] {:creator_id (rasta-id)
+ :entity_id (u/generate-nano-id)})
:model/Channel
(fn [_] (default-timestamped
@@ -149,12 +151,14 @@
:model/Dashboard
(fn [_] (default-timestamped
{:creator_id (rasta-id)
+ :entity_id (u/generate-nano-id)
:name (u.random/random-name)}))
:model/DashboardCard
(fn [_] (default-timestamped
{:row 0
:col 0
+ :entity_id (u/generate-nano-id)
:size_x 4
:size_y 4}))
@@ -164,7 +168,8 @@
:model/DashboardTab
(fn [_]
(default-timestamped
- {:name (u.random/random-name)
+ {:entity_id (u/generate-nano-id)
+ :name (u.random/random-name)
:position 0}))
:model/Database
@@ -179,12 +184,14 @@
:model/Dimension
(fn [_] (default-timestamped
- {:name (u.random/random-name)
+ {:entity_id (u/generate-nano-id)
+ :name (u.random/random-name)
:type "internal"}))
:model/Document
(fn [_] (default-timestamped
- {:name (u.random/random-name)
+ {:entity_id (u/generate-nano-id)
+ :name (u.random/random-name)
:document {:type "doc"
:content [{:attrs {:_id (str (random-uuid))}
:type "paragraph"
@@ -215,6 +222,7 @@
(fn [_] (default-timestamped
{:creator_id (rasta-id)
:definition {}
+ :entity_id (u/generate-nano-id)
:name "Mock Measure"
:table_id (data/id :checkins)}))
@@ -240,6 +248,7 @@
:model/NativeQuerySnippet
(fn [_] (default-timestamped
{:creator_id (user-id :crowberto)
+ :entity_id (u/generate-nano-id)
:name (u.random/random-name)
:content "1 = 1"}))
@@ -281,7 +290,8 @@
:creator_id (rasta-id)})
:model/PermissionsGroup
- (fn [_] {:name (u.random/random-name)})
+ (fn [_] {:entity_id (u/generate-nano-id)
+ :name (u.random/random-name)})
:model/PermissionsGroupMembership
(fn [_] {:__test-only-sigil-allowing-direct-insertion-of-permissions-group-memberships true})
@@ -289,10 +299,12 @@
:model/Pulse
(fn [_] (default-timestamped
{:creator_id (rasta-id)
+ :entity_id (u/generate-nano-id)
:name (u.random/random-name)}))
:model/PulseCard
(fn [_] {:position 0
+ :entity_id (u/generate-nano-id)
:include_csv false
:include_xls false})
@@ -300,6 +312,7 @@
(fn [_] (default-timestamped
{:channel_type :email
:details {}
+ :entity_id (u/generate-nano-id)
:schedule_type :daily
:schedule_hour 15}))
@@ -314,6 +327,7 @@
{:creator_id (rasta-id)
:definition {}
:description "Lookin' for a blueberry"
+ :entity_id (u/generate-nano-id)
:name "Toucans in the rainforest"
:table_id (data/id :checkins)}))
@@ -340,7 +354,8 @@
:model/Timeline
(fn [_]
(default-timestamped
- {:name "Timeline of bird squawks"
+ {:entity_id (u/generate-nano-id)
+ :name "Timeline of bird squawks"
:default false
:icon timeline-event/default-icon
:creator_id (rasta-id)}))
@@ -357,7 +372,8 @@
:model/Transform
(fn [_]
- {:name (str "Test Transform " (u/generate-nano-id))
+ {:entity_id (u/generate-nano-id)
+ :name (str "Test Transform " (u/generate-nano-id))
:source {:type "query"
:query (lib/native-query (data/metadata-provider) "SELECT 1 as num")}
:target {:type "table"
@@ -367,7 +383,8 @@
:model/TransformJob
(fn [_]
(default-timestamped
- {:name (str "Test Transform Job " (u/generate-nano-id))
+ {:entity_id (u/generate-nano-id)
+ :name (str "Test Transform Job " (u/generate-nano-id))
:schedule "0 0 * * * ?"
:ui_display_type :cron/raw}))
@@ -381,7 +398,8 @@
:model/TransformTag
(fn [_]
(default-timestamped
- {:name (str "test-tag-" (u/generate-nano-id))}))
+ {:entity_id (u/generate-nano-id)
+ :name (str "test-tag-" (u/generate-nano-id))}))
:model/Tenant
(fn [_]
@@ -392,6 +410,7 @@
(fn [_] {:first_name (u.random/random-name)
:last_name (u.random/random-name)
:email (u.random/random-email)
+ :entity_id (u/generate-nano-id)
:password (u.random/random-name)
:date_joined (t/zoned-date-time)
:updated_at (t/zoned-date-time)})
diff --git a/test/metabase/users/models/user_test.clj b/test/metabase/users/models/user_test.clj
index a5a5fc104e3..502c8e3a9ad 100644
--- a/test/metabase/users/models/user_test.clj
+++ b/test/metabase/users/models/user_test.clj
@@ -5,7 +5,6 @@
[metabase.app-db.core :as mdb]
[metabase.app-db.schema-migrations-test.impl :as schema-migrations-test.impl]
[metabase.config.core :as config]
- [metabase.models.serialization :as serdes]
[metabase.notification.test-util :as notification.tu]
[metabase.permissions.core :as perms]
[metabase.permissions.models.permissions-group :as perms-group]
@@ -427,13 +426,6 @@
(testing "subscription should no longer exist"
(is (not (subscription-exists?))))))))
-(deftest identity-hash-test
- (testing "User hashes are based on the email address"
- (mt/with-temp [:model/User user {:email "[email protected]"}]
- (is (= "e8d63472"
- (serdes/raw-hash ["[email protected]"])
- (serdes/identity-hash user))))))
-
(deftest hash-password-on-update-test
(testing "Setting `:password` with [[t2/update!]] should hash the password, just like [[t2/insert!]]"
(let [plaintext-password "password-1234"]
diff --git a/test/metabase/warehouse_schema/models/dimension_test.clj b/test/metabase/warehouse_schema/models/dimension_test.clj
deleted file mode 100644
index a76167b3198..00000000000
--- a/test/metabase/warehouse_schema/models/dimension_test.clj
+++ /dev/null
@@ -1,21 +0,0 @@
-(ns metabase.warehouse-schema.models.dimension-test
- (:require
- [clojure.test :refer :all]
- [metabase.models.serialization :as serdes]
- [metabase.test :as mt]))
-
-(set! *warn-on-reflection* true)
-
-(deftest ^:parallel identity-hash-test
- (testing "Dimension hashes are composed of the proper field hash, and the human-readable field hash"
- (let [now #t "2022-09-01T12:34:56Z"]
- (mt/with-temp [:model/Database db {:name "field-db" :engine :h2}
- :model/Table table {:schema "PUBLIC" :name "widget" :db_id (:id db)}
- :model/Field field1 {:name "sku" :table_id (:id table)}
- :model/Field field2 {:name "human" :table_id (:id table)}
- :model/Dimension dim {:field_id (:id field1)
- :human_readable_field_id (:id field2)
- :created_at now}]
- (is (= "0f5162d3"
- (serdes/raw-hash [(serdes/identity-hash field1) (serdes/identity-hash field2) (:created_at dim)])
- (serdes/identity-hash dim)))))))
diff --git a/test/metabase/warehouse_schema/models/field_test.clj b/test/metabase/warehouse_schema/models/field_test.clj
index d04914c5738..fae02d25f76 100644
--- a/test/metabase/warehouse_schema/models/field_test.clj
+++ b/test/metabase/warehouse_schema/models/field_test.clj
@@ -3,7 +3,6 @@
(:require
[clojure.test :refer :all]
[metabase.models.interface :as mi]
- [metabase.models.serialization :as serdes]
[metabase.permissions.core :as perms]
[metabase.permissions.models.data-permissions :as data-perms]
[metabase.test :as mt]
@@ -40,16 +39,6 @@
(mt/with-temp [:model/Field field {column unknown-type}]
field))))))
-(deftest identity-hash-test
- (testing "Field hashes are composed of the name, the table's identity-hash, and the parent's identity-hash"
- (mt/with-temp [:model/Database db {:name "field-db" :engine :h2}
- :model/Table table {:schema "PUBLIC" :name "widget" :db_id (:id db)}
- :model/Field field {:name "sku" :table_id (:id table)}]
- (let [table-hash (serdes/identity-hash table)]
- (is (= "edc06d97"
- (serdes/raw-hash ["sku" table-hash "<none>"])
- (serdes/identity-hash field)))))))
-
(deftest nested-field-names->field-id-test
(mt/with-temp
[:model/Database {db-id :id} {}
@@ -68,37 +57,6 @@
(is (= nil
(field/nested-field-names->field-id table-id ["top" "nested" "not-exists"]))))))
-(deftest nested-fields-with-duplicate-names-test
- (mt/with-temp
- [:model/Database {db-id :id} {:name "field-db", :engine :h2}
- :model/Table table {:schema "PUBLIC"
- :name "widget"
- :db_id db-id}
- :model/Field parent1 {:name "parent1"
- :table_id (:id table)}
- :model/Field parent2 {:name "parent2"
- :table_id (:id table)}
- ;; These two have the same name but different parents.
- :model/Field child1 {:name "child"
- :table_id (:id table)
- :parent_id (:id parent1)}
- :model/Field child2 {:name "child"
- :table_id (:id table)
- :parent_id (:id parent2)}]
- (testing "nested fields with the same name and different parents have unique identity-hashes"
- (is (= "204a7209"
- (serdes/raw-hash ["parent1" (serdes/identity-hash table) "<none>"])
- (serdes/identity-hash parent1)))
- (is (= "be1bb68e"
- (serdes/raw-hash ["parent2" (serdes/identity-hash table) "<none>"])
- (serdes/identity-hash parent2)))
- (is (= "7f203b41"
- (serdes/raw-hash ["child" (serdes/identity-hash table) (serdes/identity-hash parent1)])
- (serdes/identity-hash child1)))
- (is (= "913269d5"
- (serdes/raw-hash ["child" (serdes/identity-hash table) (serdes/identity-hash parent2)])
- (serdes/identity-hash child2))))))
-
;;; ---------------------------------------- Field permission delegation tests ----------------------------------------
(deftest field-can-read?-delegates-to-parent-table-denied-test
diff --git a/test/metabase/warehouse_schema/models/field_values_test.clj b/test/metabase/warehouse_schema/models/field_values_test.clj
index 419f0aa04d5..eb7f4613e5c 100644
--- a/test/metabase/warehouse_schema/models/field_values_test.clj
+++ b/test/metabase/warehouse_schema/models/field_values_test.clj
@@ -7,7 +7,6 @@
[java-time.api :as t]
[metabase.driver :as driver]
[metabase.driver.sql-jdbc.execute :as sql-jdbc.execute]
- [metabase.models.serialization :as serdes]
[metabase.sync.core :as sync]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
@@ -441,16 +440,6 @@
(t2/update! :model/FieldValues (:id fv) {:updated_at (t/zoned-date-time)})
(is (t2/exists? :model/FieldValues :id (:id sandbox-fv)))))
-(deftest identity-hash-test
- (testing "Field hashes are composed of the name and the table's identity-hash"
- (mt/with-temp [:model/Database db {:name "field-db" :engine :h2}
- :model/Table table {:schema "PUBLIC" :name "widget" :db_id (:id db)}
- :model/Field field {:name "sku" :table_id (:id table)}
- :model/FieldValues fv {:field_id (:id field)}]
- (is (= "cb0ff8ea"
- (serdes/raw-hash [(serdes/identity-hash field)])
- (serdes/identity-hash fv))))))
-
(deftest select-coherence-test
(testing "We cannot perform queries with invalid mixes of type and hash_key, which would return nothing"
(let [field-id (mt/id :venues :id)]
diff --git a/test/metabase/warehouse_schema/models/table_test.clj b/test/metabase/warehouse_schema/models/table_test.clj
index 1d81f1fbeee..ac3e92fc124 100644
--- a/test/metabase/warehouse_schema/models/table_test.clj
+++ b/test/metabase/warehouse_schema/models/table_test.clj
@@ -79,15 +79,6 @@
(is (= schema-name
(t2/select-one-fn :schema :model/Table :id table-id))))))))
-(deftest identity-hash-test
- (testing "Table hashes are composed of the schema name, table name and the database's identity-hash"
- (mt/with-temp [:model/Database db {:name "field-db" :engine :h2}
- :model/Table table {:schema "PUBLIC" :name "widget" :db_id (:id db)}]
- (let [db-hash (serdes/identity-hash db)]
- (is (= "0395fe49"
- (serdes/raw-hash ["PUBLIC" "widget" db-hash])
- (serdes/identity-hash table)))))))
-
(deftest set-new-table-permissions!-test
(testing "New permissions are set appropriately for a new table, for all groups"
(mt/with-full-data-perms-for-all-users!
diff --git a/test/metabase/warehouses/models/database_test.clj b/test/metabase/warehouses/models/database_test.clj
index c94ed630d8b..450e1cd9261 100644
--- a/test/metabase/warehouses/models/database_test.clj
+++ b/test/metabase/warehouses/models/database_test.clj
@@ -715,14 +715,6 @@
(is (= ::test
(t2/select-one-fn :engine :model/Database :id db-id))))))
-(deftest identity-hash-test
- (testing "Database hashes are composed of the name and engine"
- (mt/with-temp [:model/Database db {:engine :mysql :name "hashmysql"}]
- (is (= (Integer/toHexString (hash ["hashmysql" :mysql]))
- (serdes/identity-hash db)))
- (is (= "b6f1a9e8"
- (serdes/identity-hash db))))))
-
(deftest ^:parallel serdes-extract-is-stub-test
(testing "serdes/extract-one preserves :is_stub true and elides it when false"
(mt/with-temp [:model/Database stub {:engine :h2 :name "stub" :is_stub true}