duct

y.khmelevskii 2019-07-14T12:10:11.066100Z

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

2019-07-16T20:41:58.079600Z

@y.khmelevskii 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.

2019-07-14T12:43:15.066500Z

I think you can make use of https://github.com/weavejester/integrant#composite-keys

2019-07-14T12:44:25.067400Z

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

2019-07-14T12:46:41.068800Z

[: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}

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

1👍
2019-07-14T12:47:08.069300Z

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

2019-07-14T12:50:42.070300Z

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

2019-07-14T12:58:05.071400Z

OTOH you can use the profiles feature.

2019-07-14T13:09:18.074900Z

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/read-config)
        (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)]

2019-07-14T16:16:38.076200Z

And if you'll go the profile way, you should derive the new profile from :duct/profile, like in https://github.com/duct-framework/core/blob/886e19e03d2181438a22c934a808ce10f2cc9081/src/duct_hierarchy.edn

2019-07-14T16:37:06.076900Z

Also I've found https://github.com/duct-framework/core/issues/20

y.khmelevskii 2019-07-14T18:37:50.079100Z

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