Skip to content

Commit

Permalink
Merge pull request #113 from xsc/ys/111-migration-sorting
Browse files Browse the repository at this point in the history
Sort JDBC migrations by ':id'
  • Loading branch information
weavejester committed Mar 27, 2017
2 parents c445382 + 2929feb commit 5abd8aa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions ragtime.jdbc/src/ragtime/jdbc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@
:down (vec (mapcat read-sql (sort-by str down)))}))))

(defn- load-all-files [files]
(->> (sort-by str files)
(group-by file-extension)
(->> (group-by file-extension files)
(vals)
(mapcat load-files)))
(mapcat load-files)
(sort-by :id)))

(defn load-directory
"Load a collection of Ragtime migrations from a directory."
Expand Down
2 changes: 2 additions & 0 deletions ragtime.jdbc/test/migrations/006-test.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{:up ["CREATE TABLE last_table (id int)"]
:down ["DROP TABLE last_table"]}
8 changes: 4 additions & 4 deletions ragtime.jdbc/test/ragtime/jdbc_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
ms (jdbc/load-directory "test/migrations")
idx (core/into-index ms)]
(core/migrate-all db idx ms)
(is (= #{"RAGTIME_MIGRATIONS" "FOO" "BAR" "BAZ" "QUZA" "QUZB" "QUXA" "QUXB"}
(is (= #{"RAGTIME_MIGRATIONS" "FOO" "BAR" "BAZ" "QUZA" "QUZB" "QUXA" "QUXB" "LAST_TABLE"}
(table-names db)))
(is (= ["001-test" "002-bar" "003-test" "004-test" "005-test"]
(is (= ["001-test" "002-bar" "003-test" "004-test" "005-test" "006-test"]
(p/applied-migration-ids db)))
(core/rollback-last db idx (count ms))
(is (= #{"RAGTIME_MIGRATIONS"} (table-names db)))
Expand All @@ -67,9 +67,9 @@
ms (jdbc/load-resources "migrations")
idx (core/into-index ms)]
(core/migrate-all db idx ms)
(is (= #{"RAGTIME_MIGRATIONS" "FOO" "BAR" "BAZ" "QUZA" "QUZB" "QUXA" "QUXB"}
(is (= #{"RAGTIME_MIGRATIONS" "FOO" "BAR" "BAZ" "QUZA" "QUZB" "QUXA" "QUXB" "LAST_TABLE"}
(table-names db)))
(is (= ["001-test" "002-bar" "003-test" "004-test" "005-test"]
(is (= ["001-test" "002-bar" "003-test" "004-test" "005-test" "006-test"]
(p/applied-migration-ids db)))
(core/rollback-last db idx (count ms))
(is (= #{"RAGTIME_MIGRATIONS"} (table-names db)))
Expand Down

0 comments on commit 5abd8aa

Please sign in to comment.