Repository: penpot/penpot
File: backend/src/app/migrations.clj (Clojure)

Code before:

   {:name "0135-mod-team-invitation-table.sql"
    :fn (mg/resource "app/migrations/sql/0135-mod-team-invitation-table.sql")}

   {:name "0136-mod-comments-mentions.sql"
    :fn (mg/resource "app/migrations/sql/0136-mod-comments-mentions.sql")}

   {:name "0137-add-file-migration-table.sql"
    :fn (mg/resource "app/migrations/sql/0137-add-file-migration-table.sql")}

   {:name "0138-mod-file-data-fragment-table.sql"
    :fn (mg/resource "app/migrations/sql/0138-mod-file-data-fragment-table.sql")}

   {:name "0139-mod-file-change-table.sql"
    :fn (mg/resource "app/migrations/sql/0139-mod-file-change-table.sql")}

   {:name "0140-mod-file-change-table.sql"
    :fn (mg/resource "app/migrations/sql/0140-mod-file-change-table.sql")}

   {:name "0140-add-locked-by-column-to-file-change-table"
    :fn (mg/resource "app/migrations/sql/0140-add-locked-by-column-to-file-change-table.sql")}

   {:name "0141-add-idx-to-file-library-rel"
    :fn (mg/resource "app/migrations/sql/0141-add-idx-to-file-library-rel.sql")}

   {:name "0142-create-view-file_with_library_files"
    :fn (mg/resource "app/migrations/sql/0142-create-view-file_with_library_files.sql")}])

(defn apply-migrations!
  [pool name migrations]
  (dm/with-open [conn (db/open pool)]
    (mg/setup! conn)
    (mg/migrate! conn {:name name :steps migrations})))

(defmethod ig/assert-key ::migrations
  [_ {:keys [::db/pool]}]
  (assert (db/pool? pool) "expected valid pool"))

(defmethod ig/init-key ::migrations
  [module {:keys [::db/pool]}]
  (when-not (db/read-only? pool)
    (l/info :hint "running migrations" :module module)
    (some->> (seq migrations) (apply-migrations! pool "main"))))


Review comment (suggestion):
The migration name and the file should not mix casing. All should use the `-` as separator, following the same way as the rest of migrations

Code after:

   {:name "0135-mod-team-invitation-table.sql"
    :fn (mg/resource "app/migrations/sql/0135-mod-team-invitation-table.sql")}

   {:name "0136-mod-comments-mentions.sql"
    :fn (mg/resource "app/migrations/sql/0136-mod-comments-mentions.sql")}

   {:name "0137-add-file-migration-table.sql"
    :fn (mg/resource "app/migrations/sql/0137-add-file-migration-table.sql")}

   {:name "0138-mod-file-data-fragment-table.sql"
    :fn (mg/resource "app/migrations/sql/0138-mod-file-data-fragment-table.sql")}

   {:name "0139-mod-file-change-table.sql"
    :fn (mg/resource "app/migrations/sql/0139-mod-file-change-table.sql")}

   {:name "0140-mod-file-change-table.sql"
    :fn (mg/resource "app/migrations/sql/0140-mod-file-change-table.sql")}

   {:name "0140-add-locked-by-column-to-file-change-table"
    :fn (mg/resource "app/migrations/sql/0140-add-locked-by-column-to-file-change-table.sql")}

   {:name "0141-add-idx-to-file-library-rel"
    :fn (mg/resource "app/migrations/sql/0141-add-idx-to-file-library-rel.sql")}])

(defn apply-migrations!
  [pool name migrations]
  (dm/with-open [conn (db/open pool)]
    (mg/setup! conn)
    (mg/migrate! conn {:name name :steps migrations})))

(defmethod ig/assert-key ::migrations
  [_ {:keys [::db/pool]}]
  (assert (db/pool? pool) "expected valid pool"))

(defmethod ig/init-key ::migrations
  [module {:keys [::db/pool]}]
  (when-not (db/read-only? pool)
    (l/info :hint "running migrations" :module module)
    (some->> (seq migrations) (apply-migrations! pool "main"))))