Skip to content

Commit

Permalink
Merge pull request #160 from dharrigan/feat/issue-159
Browse files Browse the repository at this point in the history
Fix SQL separator marker for MySQL
  • Loading branch information
weavejester authored Dec 20, 2023
2 parents 091a7a7 + ef0b47c commit bf05448
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion jdbc/src/ragtime/jdbc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
(rest (re-matches #"(.*?)\.(up|down)(?:\.(\d+))?\.sql" (str file))))

(defn- read-sql [file]
(str/split (slurp file) #"(?m)\n\s*--;;\s*\n"))
(str/split (slurp file) #"(?m)\n\s*--\s?;;\s*\n"))

(defmethod load-files ".sql" [files]
(for [[id files] (->> files
Expand Down
6 changes: 6 additions & 0 deletions jdbc/test/migrations/007-test.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--
-- ISSUE 159 Test
--
DROP TABLE quxc;
-- ;;
DROP TABLE quxd;
6 changes: 6 additions & 0 deletions jdbc/test/migrations/007-test.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--
-- ISSUE 159 Test
--
CREATE TABLE quxc (id int);
-- ;;
CREATE TABLE quxd (id int);
8 changes: 4 additions & 4 deletions jdbc/test/ragtime/jdbc_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,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" "LAST_TABLE"}
(is (= #{"RAGTIME_MIGRATIONS" "FOO" "BAR" "BAZ" "QUZA" "QUZB" "QUXA" "QUXB" "LAST_TABLE" "QUXC" "QUXD"}
(table-names db)))
(is (= ["001-test" "002-bar" "003-test" "004-test" "005-test" "006-test"]
(is (= ["001-test" "002-bar" "003-test" "004-test" "005-test" "006-test" "007-test"]
(p/applied-migration-ids db)))
(core/rollback-last db idx (count ms))
(is (= #{"RAGTIME_MIGRATIONS"} (table-names db)))
Expand All @@ -90,9 +90,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" "LAST_TABLE"}
(is (= #{"RAGTIME_MIGRATIONS" "FOO" "BAR" "BAZ" "QUZA" "QUZB" "QUXA" "QUXB" "LAST_TABLE" "QUXC" "QUXD"}
(table-names db)))
(is (= ["001-test" "002-bar" "003-test" "004-test" "005-test" "006-test"]
(is (= ["001-test" "002-bar" "003-test" "004-test" "005-test" "006-test" "007-test"]
(p/applied-migration-ids db)))
(core/rollback-last db idx (count ms))
(is (= #{"RAGTIME_MIGRATIONS"} (table-names db)))
Expand Down
2 changes: 1 addition & 1 deletion next-jdbc/src/ragtime/next_jdbc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
(rest (re-matches #"(.*?)\.(up|down)(?:\.(\d+))?\.sql" (str file))))

(defn- read-sql [file]
(str/split (slurp file) #"(?m)\n\s*--;;\s*\n"))
(str/split (slurp file) #"(?m)\n\s*--\s?;;\s*\n"))

(defmethod load-files ".sql" [files]
(for [[id files] (->> files
Expand Down
6 changes: 6 additions & 0 deletions next-jdbc/test/migrations/007-test.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--
-- ISSUE 159 Test
--
DROP TABLE quxc;
-- ;;
DROP TABLE quxd;
6 changes: 6 additions & 0 deletions next-jdbc/test/migrations/007-test.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--
-- ISSUE 159 Test
--
CREATE TABLE quxc (id int);
-- ;;
CREATE TABLE quxd (id int);
8 changes: 4 additions & 4 deletions next-jdbc/test/ragtime/next_jdbc_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@
idx (core/into-index ms)]
(core/migrate-all db idx ms)
(is (= #{"RAGTIME_MIGRATIONS" "FOO" "BAR" "BAZ"
"QUZA" "QUZB" "QUXA" "QUXB" "LAST_TABLE"}
"QUZA" "QUZB" "QUXA" "QUXB" "LAST_TABLE" "QUXC" "QUXD"}
(table-names db)))
(is (= ["001-test" "002-bar" "003-test" "004-test" "005-test" "006-test"]
(is (= ["001-test" "002-bar" "003-test" "004-test" "005-test" "006-test" "007-test"]
(p/applied-migration-ids db)))
(core/rollback-last db idx (count ms))
(is (= #{"RAGTIME_MIGRATIONS"} (table-names db)))
Expand All @@ -108,9 +108,9 @@
idx (core/into-index ms)]
(core/migrate-all db idx ms)
(is (= #{"RAGTIME_MIGRATIONS" "FOO" "BAR" "BAZ"
"QUZA" "QUZB" "QUXA" "QUXB" "LAST_TABLE"}
"QUZA" "QUZB" "QUXA" "QUXB" "LAST_TABLE" "QUXC" "QUXD"}
(table-names db)))
(is (= ["001-test" "002-bar" "003-test" "004-test" "005-test" "006-test"]
(is (= ["001-test" "002-bar" "003-test" "004-test" "005-test" "006-test" "007-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 bf05448

Please sign in to comment.