From ee88ee63a2a6b79cf05e8d2ce084ca709ce51a8d Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 5 Feb 2026 18:08:28 +0100 Subject: [PATCH] :sparkles: Add data migration for fix plugins data on profiles --- backend/src/app/migrations.clj | 7 +- .../src/app/migrations/clj/migration_0145.clj | 82 +++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 backend/src/app/migrations/clj/migration_0145.clj diff --git a/backend/src/app/migrations.clj b/backend/src/app/migrations.clj index ced89c9160..2a9d9eba0b 100644 --- a/backend/src/app/migrations.clj +++ b/backend/src/app/migrations.clj @@ -10,6 +10,7 @@ [app.common.logging :as l] [app.db :as db] [app.migrations.clj.migration-0023 :as mg0023] + [app.migrations.clj.migration-0145 :as mg0145] [app.util.migrations :as mg] [integrant.core :as ig])) @@ -459,7 +460,11 @@ :fn (mg/resource "app/migrations/sql/0143-add-http-session-v2-table.sql")} {:name "0144-mod-server-error-report-table" - :fn (mg/resource "app/migrations/sql/0144-mod-server-error-report-table.sql")}]) + :fn (mg/resource "app/migrations/sql/0144-mod-server-error-report-table.sql")} + + {:name "0145-fix-plugins-uri-on-profile" + :fn mg0145/migrate}]) + (defn apply-migrations! [pool name migrations] diff --git a/backend/src/app/migrations/clj/migration_0145.clj b/backend/src/app/migrations/clj/migration_0145.clj new file mode 100644 index 0000000000..9a24ae35b8 --- /dev/null +++ b/backend/src/app/migrations/clj/migration_0145.clj @@ -0,0 +1,82 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS INC + +(ns app.migrations.clj.migration-0145 + "Migrate plugins references on profiles" + (:require + [app.common.data :as d] + [app.common.logging :as l] + [app.db :as db] + [cuerdas.core :as str])) + +(def ^:private replacements + {"https://colors-to-tokens-plugin.pages.dev" + "https://colors-to-tokens.plugins.penpot.app" + + "https://contrast-penpot-plugin.pages.dev" + "https://contrast.plugins.penpot.app" + + "https://create-palette-penpot-plugin.pages.dev" + "https://create-palette.plugins.penpot.app" + + "https://icons-penpot-plugin.pages.dev" + "https://icons.plugins.penpot.app" + + "https://lorem-ipsum-penpot-plugin.pages.dev" + "https://lorem-ipsum.plugins.penpot.app" + + "https://rename-layers-penpot-plugin.pages.dev" + "https://rename-layers.plugins.penpot.app" + + "https://table-penpot-plugin.pages.dev" + "https://table.plugins.penpot.app"}) + +(defn- fix-url + [url] + (reduce-kv (fn [url prefix replacement] + (if (str/starts-with? url prefix) + (reduced (str replacement (subs url (count prefix)))) + url)) + url + replacements)) + + +(defn- fix-manifest + [manifest] + (-> manifest + (d/update-when :url fix-url) + (d/update-when :host fix-url))) + +(defn- fix-plugins-data + [props] + (d/update-in-when props [:plugins :data] + (fn [data] + (reduce-kv (fn [data id manifest] + (let [manifest' (fix-manifest manifest)] + (if (= manifest manifest') + data + (assoc data id manifest')))) + data + data)))) + +(def ^:private sql:get-profiles + "SELECT id, props FROM profile + WHERE props ?? '~:plugins' + ORDER BY created_at") + +(defn migrate + [conn] + (->> (db/plan conn [sql:get-profiles]) + (run! (fn [{:keys [id props]}] + (when-let [props (some-> props db/decode-transit-pgobject)] + (let [props' (fix-plugins-data props)] + (when (not= props props') + (l/inf :hint "fixing plugins data on profile props" :profile-id (str id)) + (db/update! conn :profile + {:props (db/tjson props')} + {:id id} + {::db/return-keys false})))))))) +