fix migrations

Josha von Gizycki 5 years ago
parent 68167925e3
commit f3e3c67cde

@ -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)

Loading…
Cancel
Save