From b69471fd98b8148a8ad63cb738d52698af02906f Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Sat, 1 Feb 2020 12:45:54 +0100 Subject: [PATCH] fix migrations --- src/wanijo/infrastructure/repl.clj | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/wanijo/infrastructure/repl.clj b/src/wanijo/infrastructure/repl.clj index 08e8761..ac4634c 100644 --- a/src/wanijo/infrastructure/repl.clj +++ b/src/wanijo/infrastructure/repl.clj @@ -16,11 +16,15 @@ :pw (hashers/derive pw) :uuid (neo4j/uuid)})) -(db/defquery init-config +(db/defquery merge-config "MERGE (c:dbconfig) ON CREATE SET c.installed_at = {now}, - c.db_version = 0") + c.db_version = 0, + c.last_migration = '' + ON MATCH SET + c.last_migration = {now}, + c.db_version = {version}") (db/defquery config "MATCH (c:dbconfig) RETURN c") @@ -74,11 +78,18 @@ init-version-1]) (defn run-migrations! [] - (neo4j/exec-query! init-config {:now (neo4j/now-str)}) + (neo4j/exec-query! merge-config {:now (neo4j/now-str) + :version (count migrations)}) (let [version (-> (neo4j/exec-query! config {}) first :c :db_version)] - (if-let [to-run (nthrest migrations version)] + (println "got version" version "from db," (count migrations) "available") + (when-let [to-run (nthrest migrations version)] + (println "running" (count to-run) "migrations") (doseq [mig to-run] - (mig))))) + (println "running" mig) + (mig)))) + (neo4j/exec-query! merge-config {:now (neo4j/now-str) + :version (count migrations)}) + nil)