Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Upgrade Flyway
Browse files Browse the repository at this point in the history
In 9.1.4 Flyway changed to use transactional locks, but it causes
migrations to freeze. Reverted to old default.

In 9.19.0 breaks things. Audit tables create a log of added kayttaja
entries. The audit log try to use the function current_kayttaja_id(),
which relies on "application name" being set. It's set in
beforeMigration.sql, but in this version callbacks have a separate
connection. Added ApplicationName to connection url to get around the
problem.

Implements: AE-1909
  • Loading branch information
solita-antti-mottonen committed Aug 23, 2023
1 parent 13f4942 commit 7adf34f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion etp-db/deps.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{:paths ["src/main/clj" "src/main/sql" "src/main/resources"]
:deps
{org.clojure/clojure {:mvn/version "1.10.1"}
org.flywaydb/flyway-core {:mvn/version "6.2.0"}
org.flywaydb/flyway-core {:mvn/version "9.21.1"}
org.postgresql/postgresql {:mvn/version "42.2.9"}
ch.qos.logback/logback-classic {:mvn/version "1.2.3"}}
:aliases {:test {:extra-paths ["src/test/sql"]}
Expand Down
24 changes: 16 additions & 8 deletions etp-db/src/main/clj/solita/etp/db/flywaydb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
"- repair - attempt to fix migration checksum mismatches"]))

(def flyway-configuration {
ConfigUtils/SCHEMAS "etp,audit"
ConfigUtils/SQL_MIGRATION_PREFIX "v"
ConfigUtils/SQL_MIGRATION_SEPARATOR "-"
ConfigUtils/REPEATABLE_SQL_MIGRATION_PREFIX "r"
ConfigUtils/LOCATIONS "classpath:migration"})
ConfigUtils/SCHEMAS "etp,audit"
ConfigUtils/SQL_MIGRATION_PREFIX "v"
ConfigUtils/SQL_MIGRATION_SEPARATOR "-"
ConfigUtils/REPEATABLE_SQL_MIGRATION_PREFIX "r"
ConfigUtils/LOCATIONS "classpath:migration"
"flyway.postgresql.transactional.lock" "false"})


(defn map-keys [f m] (into {} (map (fn [[k, v]] [(f k) v]) m)))

Expand All @@ -33,9 +35,15 @@
(or (System/getenv name) default))

(defn read-configuration []
{:user (env "DB_USER" "etp")
:password (env "DB_PASSWORD" "etp")
:url (env "DB_URL" "jdbc:postgresql://localhost:5432/postgres")})
(let [url (env "DB_URL" "jdbc:postgresql://localhost:5432/postgres")
existing-query (-> url (str/split #"\?" 2) (get 1))
url-with-app-name (->> ["ApplicationName=0@database.etp" existing-query]
(remove nil?)
(str/join "&")
(str url "?"))]
{:user (env "DB_USER" "etp")
:password (env "DB_PASSWORD" "etp")
:url url-with-app-name}))

(defn run [args]
(let [command (str/trim (or (first args) "<empty string>"))
Expand Down
1 change: 0 additions & 1 deletion etp-db/src/main/sql/migration/beforeMigrate.sql

This file was deleted.

0 comments on commit 7adf34f

Please sign in to comment.