diff --git a/backend/src/app/features/fdata.clj b/backend/src/app/features/fdata.clj index 8d81199fd8..cb963262b6 100644 --- a/backend/src/app/features/fdata.clj +++ b/backend/src/app/features/fdata.clj @@ -209,7 +209,6 @@ ;; STORAGE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - (defmulti resolve-file-data (fn [_cfg file] (or (get file :backend) "db"))) @@ -381,3 +380,63 @@ (-> (db/delete! cfg :file-data params) (db/get-update-count) (pos?)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; SCRIPTS +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def sql:get-unmigrated-files + "SELECT f.id, f.data, + row_number() OVER w AS index + FROM file AS f + WHERE f.data IS NOT NULL + WINDOW w AS (order by f.modified_at ASC) + ORDER BY f.modified_at ASC + LIMIT 100") + +(defn migrate-to-storage + "Migrate the current existing files to store data in new storage + tables." + [system] + (let [timestamp (ct/now)] + (db/tx-run! system + (fn [{:keys [::db/conn]}] + (run! (fn [{:keys [id data index]}] + (l/dbg :hint "migrating file" :file-id (str id) :index index) + (db/update! conn :file {:data nil} {:id id} ::db/return-keys false) + (db/insert! conn :file-data + {:backend "db" + :metadata nil + :type "main" + :data data + :created-at timestamp + :modified-at timestamp + :file-id id + :id id} + {::db/return-keys false})) + (db/plan conn [sql:get-unmigrated-files])))))) + + +(def sql:get-migrated-files + "SELECT f.id, f.data, + row_number() OVER w AS index + FROM file_data AS f + WHERE f.data IS NOT NULL + AND f.id = f.file_id + WINDOW w AS (order by f.id ASC) + ORDER BY f.id ASC") + +(defn rollback-from-storage + "Migrate back to the file table storage." + [system] + (db/tx-run! system + (fn [{:keys [::db/conn]}] + (run! (fn [{:keys [id data index]}] + (l/dbg :hint "rollback file" :file-id (str id) :index index) + (db/update! conn :file {:data data} {:id id} ::db/return-keys false) + (db/delete! conn :file-data {:id id} ::db/return-keys false)) + (db/plan conn [sql:get-migrated-files]))))) + + + + diff --git a/backend/src/app/rpc/commands/files.clj b/backend/src/app/rpc/commands/files.clj index a699894000..84a12ad50d 100644 --- a/backend/src/app/rpc/commands/files.clj +++ b/backend/src/app/rpc/commands/files.clj @@ -252,8 +252,6 @@ (assoc :permissions perms) (check-version!))] - ;; (app.common.pprint/pprint file) - (-> (cfeat/get-team-enabled-features cf/flags team) (cfeat/check-client-features! (:features params)) (cfeat/check-file-features! (:features file)))