From 7f2e819789ff3f93359c3c4a30d98031b5177b5c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 25 Jun 2025 13:20:12 +0200 Subject: [PATCH] :bug: Fix migration persistence ordering issue When migrations are applied to old files --- common/src/app/common/files/migrations.cljc | 43 +++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index aa56dbe65d..02b43cbd14 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -94,22 +94,33 @@ (defn migrate-file [file libs] (binding [cfeat/*new* (atom #{})] - (let [version (or (:version file) - (-> file :data :version))] - (-> file - (assoc :version cfd/version) - (update :migrations - (fn [migrations] - (if (nil? migrations) - (generate-migrations-from-version version) - migrations))) - ;; NOTE: in some future we can consider to apply - ;; a migration to the whole database and remove - ;; this code from this function that executes on - ;; each file migration operation - (update :features cfeat/migrate-legacy-features) - (migrate libs) - (update :features (fnil into #{}) (deref cfeat/*new*)))))) + (let [version + (or (:version file) (-> file :data :version)) + + migrations + (not-empty (get file :migrations)) + + file + (-> file + (assoc :version cfd/version) + (assoc :migrations + (if migrations + migrations + (generate-migrations-from-version version))) + ;; NOTE: in some future we can consider to apply a + ;; migration to the whole database and remove this code + ;; from this function that executes on each file + ;; migration operation + (update :features cfeat/migrate-legacy-features) + (migrate libs) + (update :features (fnil into #{}) (deref cfeat/*new*)))] + + ;; NOTE: When we have no previous migrations, we report all + ;; migrations as migrated in order to correctly persist them all + ;; and not only the really applied migrations + (if (not migrations) + (vary-meta file assoc ::migrated (:migrations file)) + file)))) (defn migrated? [file]