Skip to content

Instantly share code, notes, and snippets.

@sudodoki
Last active February 22, 2017 09:42
Show Gist options
  • Save sudodoki/98b422931a79301ed0f543df29306fb7 to your computer and use it in GitHub Desktop.
Save sudodoki/98b422931a79301ed0f543df29306fb7 to your computer and use it in GitHub Desktop.
I have a question related to adding drift (https://github.com/macourtney/drift) to reagent-template (https://github.com/reagent-project/reagent-template). If anyone has a working setup like that to point me out or help me to sort things out, I would be really grateful. πŸ™‡

Ok, seems to have fixed that by ok, by specifically specifying :source-paths ["src"] for profile I’m running lein 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.

  1. If I use :env {:dev true :migrations-path "src/db_maintenance/migrations"}} for both envs drift seems not to see the migrations
  2. :env {:dev true :migrations-path "/src/db_maintenance/migrations"}} same
  3. 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 run lein migrate -c "db-maintenance.config.migrate-config" I will get java.lang.NullPointerException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment