Fork me on GitHub

Hi everybody! Can you please help me to understand how I can use another db user/creds for ragtime migrations in duct I need to use default user in app and admin user for running migrations.

Greg Rynkowski20:07:58

@U1GTUPAVB I think the simplest solutions would be to keep your credentials outside of the app. - When you run migrations call:

JDBC_URL=<url-containing-admin-creds> java -jar app.jar :duct/migrator
- When the app is running, run it by :
JDBC_URL=<url-containing-app-creds> java -jar app.jar :duct/migrator
- When you work, keep in dev.edn or local.edn
:duct.database.sql/hikaricp {:jdbc-url <jdbc-with-your-dev-creds>}
so that config will provide you creds for the local development.


IIRC the migrations run only when you run the app like java -jar app.jar :duct/migrator


[:duct.database.sql :db/master]
 {:jdbc-url #duct/env ["JDBC_URL_MASTER" Str]
  :zero-date-time-behavior "CONVERT_TO_NULL"
  :use-unicode true
  :character-encoding "UTF-8"
  :use-legacy-date-time-code false}

 [:duct.database.sql :db/migrations]
 {:jdbc-url #duct/env ["JDBC_URL_MIGRATIONS" Str]
  :zero-date-time-behavior "CONVERT_TO_NULL"
  :use-unicode true
  :character-encoding "UTF-8"
  :use-legacy-date-time-code false}

 {:database #ig/ref :db/migrations
  :migrations-table "app_migrations"
  :migrations [...]}

👍 4

For me it seems like the most straightforward way to do it.


ps. The code above is mostly made up, I've used a similar approach for app with a couple of hikaricp pools.


OTOH you can use the profiles feature.


I don't see the easy way to set the profiles, but you can make some changes

;; src/app/main.clj

(defn -main [& args]
  (let [keys     (or (duct/parse-keys args) [:duct/daemon])
        profiles [:duct.profile/prod]]
    (-> (duct/resource "app/config.edn")
        (duct/exec-config profiles keys))))
You can see there is a predefined profiles binding. You can do something like profiles [(if (some #{:duct/migrator} keys) :duct.profile/migrator :duct.profile/prod)]


And if you'll go the profile way, you should derive the new profile from :duct/profile, like in


Thank you @jahson for detail explanation! I will play with it tomorrow