(ns metabase.models.json-migration) | |
Set the updated version if the column-value has data. Doesn't do anything if it's empty since empty values are assumed to result in version-appropriate default behavior and don't need an explicit version key. | (defn update-version
[column-value desired-version]
(if (seq column-value)
(assoc column-value :version desired-version)
column-value)) |
Create a multi-method with the given name that will perform JSON migrations. Individual cases (with appropriate
logic!) must be defined by the user. The resulting multi-method accepts two arguments: the value of the column and
the desired version. Versioning is assumed to start at 1 and be stored in the JSON blob under the For example, imagine a User model with a JSON column called
| (defmacro def-json-migration
[name]
(let [name* name]
`(do
(defmulti ^:private ~name*
"Migrate the column value to the appropriate version."
{:arglists '([~'column-value ~'desired-version])}
(fn [~'column-value ~'desired-version]
(let [~'current-version (or (get ~'column-value :version) 1)]
(if (= ~'current-version ~'desired-version)
::identity
[~'current-version ~'desired-version]))))
(defmethod ^:private ~name* ::identity [~'column-value ~'_]
~'column-value)))) |