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.
@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.I think you can make use of https://github.com/weavejester/integrant#composite-keys
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}
:duct.migrator/ragtime
{:database #ig/ref :db/migrations
:migrations-table "app_migrations"
:migrations [...]}
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/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)]
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
Also I've found https://github.com/duct-framework/core/issues/20
Thank you @jahson for detail explanation! I will play with it tomorrow