Skip to content

Commit

Permalink
Added the record function and changed the dump command to insert vers…
Browse files Browse the repository at this point in the history
…ions of created migrations in the migrations table.
  • Loading branch information
budu committed Apr 23, 2011
1 parent ee5ff5e commit 39313ff
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/lobos/migration.clj
Expand Up @@ -74,7 +74,7 @@
(file *default-directory*
*stach-file*))

(defn append-stach-file [action]
(defn append-to-stach-file [action]
(append (stach-file) action))

(defn clear-stach-file []
Expand Down Expand Up @@ -128,6 +128,12 @@
(map read-string)
(map #(assoc % :version version)))))

(defn record [action]
(cond
(= *record* :stach) (append-to-stach-file action)
(= *record* :migration) (append-to-mfile (action->mfile action)
[action])))

;; ### Migrations Table Helpers

(defn create-migrations-table
Expand Down Expand Up @@ -240,12 +246,14 @@
(when (.exists (stach-file))
(print (slurp (stach-file)))))

(defn dump [& msg]
(defn- dump* [db-spec sname mfile actions]
(append-to-mfile mfile actions)
(insert-versions db-spec sname (mfile->version mfile)))

(defcommand dump [& msg]
(let [actions (read-stach-file)]
(if (empty? msg)
(doseq [action actions]
(let [mfile (action->mfile action)]
(append-to-mfile mfile [action])))
(let [mfile (apply msg->mfile msg)]
(append-to-mfile mfile actions)))
(dump* db-spec sname (action->mfile action) [action]))
(dump* db-spec sname (apply msg->mfile msg) actions))
(clear-stach-file)))

0 comments on commit 39313ff

Please sign in to comment.