I'm new to Clojure and I've been struggling to get Migratus to work with an SQLite database. I've been through a bit of a debugging and I feel stuck! :(
The issue is that, when I try running migrations, I get the following error:
Execution error (SQLException) at java.sql.DriverManager/getConnection (DriverManager.java:702).
No suitable driver found for jdbc:://127.0.0.1/
(which is weird: this should be referring to a SQLite file, not the local host)
Using java.sql.DriverManager
, I can successfully establish a connection to the SQLite database manually. So the driver seems to be set up correctly.
This is my project.clj
:
(defproject sample-project "0.1.0-SNAPSHOT"
:description "TODO"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.10.0"]
[io.pedestal/pedestal.route "0.6.0"]
[io.pedestal/pedestal.service "0.6.0"]
[io.pedestal/pedestal.jetty "0.6.0"]
[org.clojure/java.jdbc "0.7.12"]
[org.xerial/sqlite-jdbc "3.42.0.0"]
[migratus/migratus "1.5.1"]
[buddy/buddy-hashers "2.0.167"]]
:source-paths ["src"]
:repl-options {:init-ns sample-project.core}
:profiles {:dev {:aliases {"run-dev" ["trampoline" "run" "-m" "simple-api-proxy.werver/run-dev"]}
:dependencies [[io.pedestal/pedestal.service-tools "0.6.0"]]}}
:main sample-project.core)
And this is how the run-migrations
function is configured in core.clj
:
(ns simple-api-proxy.db
(:require [clojure.java.jdbc :as jdbc]
[migratus.core :as migratus]))
(def db-spec
{:classname "org.sqlite.JDBC"
:subprotocol "sqlite"
:subname ":db.sqlite3"}) ; Also tried with 'db.sqlite3' and "jdbc:sqlite:db.sqlite3"
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn run-migrations "Run migrations" []
(let [config {:store :database
:migration-dir "resources/migrations"
:db db-spec}]
(migratus/migrate config)))
Am I missing something? Is there any incompatibility between Migratus and SQLite?
afaik the migratus
db spec declaration uses different prop names:
the documentation shows something like
:migratus {:store :database
:migration-dir "migrations"
:db {:dbtype "sqlite"
:dbname "db.sqlite3"}}
so, probably you need to update your migration spec.