The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Log errors in downgrades (#64309)
dpsutton16dc5bece063
diff --git a/src/metabase/app_db/liquibase.clj b/src/metabase/app_db/liquibase.cljindex 58e4f504a23..93b32a63951 100644--- a/src/metabase/app_db/liquibase.clj+++ b/src/metabase/app_db/liquibase.clj@@ -530,8 +530,8 @@(format "target version must be a number between 44 and the previous major version (%d), inclusive"(config/current-major-version)))))(with-scope-locked liquibase- ;; count and rollback only the applied change set ids which come after the target version (only the "v..." IDs need- ;; to be considered)+ ;; count and rollback only the applied change set ids which come after the target version (only the "v..." IDs need+ ;; to be considered)(let [changeset-query (format "SELECT id FROM %s WHERE id LIKE 'v%%'" (changelog-table-name liquibase))changeset-ids (map :id (jdbc/query {:connection conn} [changeset-query]));; IDs in changesets do not include the leading 0/1 digit, so the major version is the first number@@ -556,7 +556,8 @@[(AlreadyRanChangeSetFilter. ran-changesets)(IgnoreChangeSetFilter.)(DbmsChangeSetFilter. lb-db)- changeset-filter])))]+ changeset-filter])))+ error-ids (atom [])](when (and (not force) (> latest-applied latest-available))(throw (ex-info(format "Cannot downgrade a database at version %d from Metabase version %d. You must run 'migrate down' from Metabase version >= %d."@@ -568,11 +569,25 @@(if (empty? ids-to-drop)(log/info "No changesets to roll back")(do- (AbstractRollbackCommandStep/doRollback lb-db changelog-file nil changelog-iterator (.getChangeLogParameters liquibase) changelog nil nil)+ (let [change-listener (proxy [liquibase.changelog.visitor.AbstractChangeExecListener] []+ (rollbackFailed [^ChangeSet change-set _dbchangelog _db ^Exception e]+ (swap! error-ids conj (.getId change-set))+ (log/errorf e "Error rolling back migration %s" (.getId change-set))))]+ (AbstractRollbackCommandStep/doRollback lb-db+ changelog-file+ nil+ changelog-iterator+ (.getChangeLogParameters liquibase)+ changelog+ change-listener))(let [remaining-query (-> (sql.helpers/select :id)(sql.helpers/from (keyword (changelog-table-name liquibase)))(sql.helpers/where [:in :id ids-to-drop]))formatted-sql (sql/format remaining-query)remaining-ids (map :id (t2/query conn formatted-sql))](when (seq remaining-ids)- (log/warnf "The following changesets were not rolled back. Likely because they are not in the changelog file: %s" (str/join ", " remaining-ids))))))))))+ (log/warnf "The following changesets were not rolled back. Likely because %s: %s"+ (if (seq @error-ids)+ (format "there were errors in rollback (%s)" (str/join ", " @error-ids))+ "they are not in the changelog file")+ (str/join ", " remaining-ids))))))))))