Ok, seems to have fixed that by ok, by specifically specifying
:source-paths ["src"]
for profile Iβm runninglein migrate
with.
Current directory structure
src
βββ clj
βββ cljc
βββ cljs
βββ db_maintenance
βββ config
βΒ Β βββ db_version.txt
βΒ Β βββ migrate_config.clj
βββ migrations
βββ 20170219133740_create_database.clj
βββ 20170220100217_create_rooms_collection.clj
βββ 20170220101059_create_messages_collection.clj
My current migrate_config looks like this
(ns config.migrate-config
(:require [clojure.core :refer [slurp spit]]
[config.core :refer [env]]))
(defn current-db-version-fn []
(try
(->> "src/db_maintenance/config/db_version.txt"
(slurp)
(Long/parseLong))
(catch Exception e 0)))
(defn update-db-version-fn [version]
(spit "src/db_maintenance/config/db_version.txt" (str version)))
(defn migrate-config []
{ :directory (:migrations-path env)
:current-version current-db-version-fn
:update-version update-db-version-fn})
And in project.clj I have made some changes:
- added
drift
as plugin - added
drift
to :dev profile dependencies - changed
:source-paths ["src/db_maintenance" "env/dev/clj"]
for :dev profile - I also added
:env {:dev true :migrations-path "migrations"}}
for :dev - added new profile
:create-migration {:env {:migrations-path "src/db_maintenance/migrations"}}
Now everything is working almost right. lein migrate
does what it needs and lein with-profile +create-migration create-migration migration-name
would generate a migration in right spot src/db_maintenance/migrations
but its ns is going to be (ns db-maintenance.migrations.20170220210653-create-something)
which would then fail when I ran lein migrate
, with following output:
β¦
Feb 20, 2017 10:00:26 PM clojure.lang.Reflector invokeMatchingMethod
INFO: Running migrations.20170220210653-create-something up...
Exception in thread "main" java.lang.Exception: No namespace: migrations.20170220210653-create-something found, compiling:(/private/var/folders/30/6yf_9lfs645dd27t2x_yx_0w0000gn/T/form-init4545089215940166995.clj:1:125)
And I'm not sure what to do.
- If I use
:env {:dev true :migrations-path "src/db_maintenance/migrations"}}
for both envs drift seems not to see the migrations :env {:dev true :migrations-path "/src/db_maintenance/migrations"}}
same- If I try to change my :source-paths ["src" "env/dev/clj"] for dev and update all ns's in db_maintenance to be
db-maintenance.config.migrate-config
etc, when I runlein migrate -c "db-maintenance.config.migrate-config"
I will getjava.lang.NullPointerException