Skip to content
Snippets Groups Projects
Unverified Commit 7b962f73 authored by Cam Saul's avatar Cam Saul Committed by GitHub
Browse files

Fix Liquibase when running Cypress tests locally (#33629)

parent c1d88bae
Branches
Tags
No related merge requests found
......@@ -5,7 +5,9 @@
[clojure.string :as str]
[compojure.core :refer [POST]]
[metabase.api.common :as api]
[metabase.config :as config]
[metabase.db.connection :as mdb.connection]
[metabase.db.setup :as mdb.setup]
[metabase.util.files :as u.files]
[metabase.util.log :as log])
(:import
......@@ -61,7 +63,15 @@
(doseq [sql-args [["SET LOCK_TIMEOUT 180000"]
["DROP ALL OBJECTS"]
["RUNSCRIPT FROM ?" snapshot-path]]]
(jdbc/execute! {:connection conn} sql-args))))
(jdbc/execute! {:connection conn} sql-args)))
;; don't know why this happens but when I try to test things locally with `yarn-test-cypress-open-no-backend` and a
;; backend server started with `dev/start!` the snapshots are always missing columms added by DB migrations. So let's
;; just check and make sure it's fully up to date in this scenario. Not doing this outside of dev because it seems to
;; work fine for whatever reason normally and we don't want tests taking 5 million years to run because we're wasting
;; a bunch of time initializing Liquibase and checking for unrun migrations for every test when we don't need to. --
;; Cam
(when config/is-dev?
(mdb.setup/migrate! (mdb.connection/db-type) mdb.connection/*application-db* :up)))
(defn- increment-app-db-unique-indentifier!
"Increment the [[mdb.connection/unique-identifier]] for the Metabase application DB. This effectively flushes all
......
......@@ -4,8 +4,10 @@
[clojure.java.jdbc :as jdbc]
[clojure.string :as str]
[metabase.config :as config]
[metabase.db.custom-migrations]
[metabase.db.liquibase.h2 :as liquibase.h2]
[metabase.db.liquibase.mysql :as liquibase.mysql]
[metabase.plugins.classloader :as classloader]
[metabase.util :as u]
[metabase.util.i18n :refer [trs]]
[metabase.util.log :as log]
......@@ -13,9 +15,9 @@
[toucan2.connection :as t2.conn])
(:import
(java.io StringWriter)
(liquibase Contexts LabelExpression Liquibase)
(liquibase.change.custom CustomChangeWrapper)
(liquibase.changelog ChangeSet)
(liquibase Contexts LabelExpression Liquibase)
(liquibase.database Database DatabaseFactory)
(liquibase.database.jvm JdbcConnection)
(liquibase.exception LockException)
......@@ -23,6 +25,10 @@
(set! *warn-on-reflection* true)
(comment
;; load our custom migrations
metabase.db.custom-migrations/keep-me)
;; register our custom MySQL SQL generators
(liquibase.mysql/register-mysql-generators!)
......@@ -54,7 +60,7 @@
(.findCorrectDatabaseImplementation (DatabaseFactory/getInstance) liquibase-conn)))
(defn- liquibase ^Liquibase [^Database database]
(Liquibase. changelog-file (ClassLoaderResourceAccessor.) database))
(Liquibase. changelog-file (ClassLoaderResourceAccessor. (classloader/the-classloader)) database))
(s/defn do-with-liquibase
"Impl for [[with-liquibase-macro]]."
......
......@@ -9,7 +9,7 @@
(:require
[honey.sql :as sql]
[metabase.db.connection :as mdb.connection]
metabase.db.custom-migrations ;; load our custom migrations
[metabase.db.custom-migrations]
[metabase.db.jdbc-protocols :as mdb.jdbc-protocols]
[metabase.db.liquibase :as liquibase]
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
......@@ -29,8 +29,11 @@
(set! *warn-on-reflection* true)
;;; needed so the `:h2` dialect gets registered with Honey SQL
(comment metabase.util.honey-sql-2/keep-me)
(comment
;; load our custom migrations
metabase.db.custom-migrations/keep-me
;; needed so the `:h2` dialect gets registered with Honey SQL
metabase.util.honey-sql-2/keep-me)
(defn- print-migrations-and-quit-if-needed!
"If we are not doing auto migrations then print out migration SQL for user to run manually. Then throw an exception to
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment