From 95df07a3649fca526cdd2ae88d6bde83b1a24730 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 13 Oct 2025 16:43:57 +0200 Subject: [PATCH] :sparkles: Add strong file schema validation after file data migration --- common/src/app/common/files/migrations.cljc | 4 +++- common/src/app/common/types/file.cljc | 4 ++-- common/test/common_tests/files_migrations_test.cljc | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 91f5793e99..10425d4e49 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -75,7 +75,9 @@ data (-> data (assoc :id id) - (dissoc :version :libs))] + (dissoc :version) + (dissoc :libs) + (ctf/check-file-data))] (-> file (assoc :data data) diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index b037831626..87e6ee739b 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -114,10 +114,10 @@ (sm/register! ::typographies schema:typographies) (def check-file - (sm/check-fn schema:file :hint "check error on validating file")) + (sm/check-fn schema:file :hint "invalid file")) (def check-file-data - (sm/check-fn schema:data)) + (sm/check-fn schema:data :hint "invalid file data")) (def check-file-media (sm/check-fn schema:media)) diff --git a/common/test/common_tests/files_migrations_test.cljc b/common/test/common_tests/files_migrations_test.cljc index f5fe884ba8..d9de5e84f2 100644 --- a/common/test/common_tests/files_migrations_test.cljc +++ b/common/test/common_tests/files_migrations_test.cljc @@ -9,6 +9,7 @@ [app.common.data :as d] [app.common.files.migrations :as cfm] [app.common.pprint :as pp] + [app.common.types.file :as ctf] [clojure.test :as t])) (defmethod cfm/migrate-data "test/1" [data _] (update data :sum inc)) @@ -17,7 +18,8 @@ (t/deftest generic-migration-subsystem-1 (let [migrations (into (d/ordered-set) ["test/1" "test/2" "test/3"])] - (with-redefs [cfm/available-migrations migrations] + (with-redefs [cfm/available-migrations migrations + ctf/check-file-data identity] (let [file {:data {:sum 1} :id 1 :migrations (d/ordered-set "test/1")}