Fork me on GitHub
#duct
<
2019-07-14
>
y.khmelevskii12:07:11

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.

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.

jahson12:07:25

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

jahson12:07:41

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

👍 4
jahson12:07:08

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

jahson12:07:42

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

jahson12:07:05

OTOH you can use the profiles feature.

jahson13:07:18

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)]

jahson16:07:38

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

y.khmelevskii18:07:50

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