luminus-framework/luminus

\*db\* state not being started on `lein run`

Closed this issue · 9 comments

Template: lein new luminus test-app +cider +auth +swagger +cljs +postgres

Migrations have been run.

Example: Running test-app.db.core/create-user! leads to the exception:
IllegalArgumentException db-spec mount.core.DerefableState@100caaab is missing a required parameter clojure.java.jdbc/get-connection (jdbc.clj:309)

Running the restart function in the dev profile's 'user' namespace corrects the issue.

Any idea how to start db on lein run?

Usually, this happens when the *db* is not used anywhere in the project. The way mount works is by resolving the namespace hierarchy and looking for places where defstate vars are used. Then the states are started in order of use. So, if *db* is not used anywhere, the state won't be started automatically. However, you can manually start the state by running (mount.core/start #'*db*) as well.

Hi Yogthos, thanks for getting back to me so quickly.

I've tested it with the template: lein new luminus test-app +postgres

It seems to be working correctly without having to reload the db namespace.

However, I think the issue lies with the +cider option for the template (using lein new luminus test-app +cider +postgres)

Upon lein run, the db state is not being started. In fact, the entire test-app.db.core namespace is not being loaded.

There are also a few other issues with the +cider option but I'll leave that for another Issue.

Not sure why cider would cause any problems, all the profile does is add the dependency and wraps the nrepl handler with its middleware. It should be unrelated to how mount loads the db state.

I think it's to do with how the test/ namespaces aren't loaded on lein run with the '+cider' template option.

If I reference the 'db.core' somewhere in the application then it works perfectly fine.

I think practically speaking it's not a big issue since you'd have to reference the ns somewhere to do anything with it anyways. So, it's only an annoyance right when you create the project.

Yeh, agreed. Just something that tripped me up as a newcomer to the framework while going through your book.

Yeah, I can see how it's note completely obvious why it doesn't start up. :)

Thanks for clearing up how mount works. I'll close this issue.

👍