Improve schema validation handling

And properly honor the file-validation flag
This commit is contained in:
Andrey Antukh 2023-11-20 15:38:07 +01:00 committed by Andrés Moya
parent 3eb987897a
commit ec8b68721b
6 changed files with 54 additions and 42 deletions

View file

@ -630,10 +630,12 @@
(pu/with-open [input (zstd-input-stream input)
input (io/data-input-stream input)]
(binding [*state* (volatile! {:media [] :index {}})]
(let [team (teams/get-team options
(let [team (teams/get-team options
:profile-id profile-id
:project-id project-id)
features (cfeat/get-team-enabled-features cf/flags team)]
validate? (contains? cf/flags :file-validation)
features (cfeat/get-team-enabled-features cf/flags team)]
;; Process all sections
(run! (fn [section]
@ -651,13 +653,13 @@
(doseq [[feature file-id] (-> *state* deref :pending-to-migrate)]
(case feature
"components/v2"
(features.components-v2/migrate-file! options file-id)
(features.components-v2/migrate-file! options file-id
:validate? validate?
:throw-on-validate? true)
"fdata/shape-data-type"
nil
;; "fdata/shape-data-type"
;; (features.fdata/enable-objects-map
(ex/raise :type :internal
:code :no-migration-defined
:hint (str/ffmt "no migation for feature '%' on file importation" feature)
@ -774,17 +776,16 @@
;; environments messed up with the version
;; numbers When this problem is fixed delete
;; the following line
(assoc :version 0)
(assoc :version 22)
(update :pages-index relink-shapes)
(update :components relink-shapes)
(update :media relink-media)
(pmg/migrate-data)
(d/without-nils))))
;; Without providing all libs, here we just
;; peform a structural file data validation,
;; full referential check is omited.
(fval/validate-file!)
(cond-> (contains? cf/flags :file-validation)
(fval/validate-file-schema!))
(postprocess-file)
(update :features #(db/create-array conn "text" %))
(update :data blob/encode))]

View file

@ -266,6 +266,7 @@
;; Retrieve and return lagged data
(get-lagged-changes conn params))))
(defn- update-file-data
[conn file changes skip-validate]
(let [file (update file :data (fn [data]
@ -278,7 +279,6 @@
;; some other way to do general validation
libs (when (and (contains? cf/flags :file-validation)
(not skip-validate))
;; FIXME: we need properly handle pointer-map here ????
(->> (files/get-file-libraries conn (:id file))
(into [file] (map (fn [{:keys [id]}]
(binding [pmap/*load-fn* (partial files/load-pointer conn id)]
@ -293,7 +293,10 @@
(update :data cpc/process-changes changes)
;; If `libs` is defined, then full validation is performed
(val/validate-file! libs)
(cond-> (and (contains? cf/flags :file-validation)
(not skip-validate))
(-> (val/validate-file! libs)
(val/validate-file-schema!)))
(cond-> (and (contains? cfeat/*current* "fdata/objects-map")
(not (contains? cfeat/*previous* "fdata/objects-map")))

View file

@ -238,7 +238,7 @@
(migrate-team [team-id]
(try
(-> (assoc system ::db/rollback rollback?)
(feat/migrate-team! team-id :validate? validate?))
(feat/migrate-team! team-id :validate? validate? :throw-on-validate? (not skip-on-error)))
(catch Throwable cause
(l/err :hint "unexpected error on processing team" :team-id (dm/str team-id) :cause cause))))