Hi guys, I’d like to use a different db (duct.database/sql) when running my tests (via: lein test, or the repl : dev> (test) ) vs. the one I use in development and in production. The idea is to have a h2 in memory db (vs a postgres db in dev/prod) where the same migrations would be run (+ some lines inserted for the tests). Is this a good parctice? How would you achieve this ? Is creating a new lein profile the good way ? thx !
Asked a similar question, a boundary (defprotocol) we defined ourselves, but idea is the same I think
So create a test profile I guess with the specific config for test
duct profile
Instead of writing to postgres you write to h2
I think it is a good practice.
You could also setup the environment with a local postgres instance (docker image) and then run integration tests against that.
Then mark the tests with (deftest ^:integration
and add test-selectors to project.clj
:test-selectors {:unit (complement :integration)
:integration :integration}
so you can run unit tests with lein test :unit
and integration tests with lein test :integration
hello @erwinrooijakkers and @kelveden, thank you very much for your replies that helped me solve my issue. What I did is that : 1. I realized that in [duct/core “0.8.0”] a specific duct.profile/test was introduced (I was using 0.7.0), and upgraded to 0.8.0. This helped me avoid the creation of test lein profile 2. In my config.edn added a line (below the dev profile one) :
:duct.profile/test #duct/include "test.edn"
there is a small issue that caused me a crash in duct.core and this is why I had to introduce the “.edn” extension (https://github.com/duct-framework/core/issues/23)
and then : 3. added in duct_hierarchy.edn the code:
{:my-project.migration/h2 [:my-project.migration/sql]
:my-project.migration/postgres [:my-project.migration/sql]}
4. referenced :my-project.migration/sql in the config.edn file :
:duct.migrator/ragtime
{:migrations [#ig/ref :co.ytems.aeolus.migration/sql]}
5. defined the :my-project.migration/h2 in test.edn file and :my-project.migration/postgres in both dev.edn and prod profilesthanks again for your help ! 👍
You could define a :duct.database.sql/hikaricp
value in your dev.edn
which also included a key initialising your H2 db (`:dev.db/H2` or whatever). You'd need to make sure that the H2 db component initialised first though to make sure that the connection could be made - this could be achieved by just adding a reference to :dev.db/H2
to the hikaricp key.
We actually do something very similar to this except that we have postgres in memory instead of H2. We use this: https://github.com/Bigsy/pg-embedded-clj
(Bill is a colleague of mine.)
I'm not sure how easy it would be to add in extra ragtime migrations in a separate profile though.