From 8a06e42a2d6b1b498abe2c95046267c377a48630 Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 14 Dec 2018 15:27:27 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=B8=BAsql=20file=20=E5=A2=9E=E5=8A=A0tra?= =?UTF-8?q?nsation=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jdbc/src/ragtime/jdbc.clj | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/jdbc/src/ragtime/jdbc.clj b/jdbc/src/ragtime/jdbc.clj index 014b2fa..a4d896d 100644 --- a/jdbc/src/ragtime/jdbc.clj +++ b/jdbc/src/ragtime/jdbc.clj @@ -128,15 +128,27 @@ (defn- read-sql [file] (str/split (slurp file) #"(?m)\n\s*--;;\s*\n")) +(defn- sql-file-transactions [sql-migration-map] + (let [{:keys [up down]} sql-migration-map + is-up-transaction (-> up first (clojure.string/starts-with? "--transaction")) + is-down-transaction (-> down first (clojure.string/starts-with? "--transaction")) + transactions (case [is-up-transaction is-down-transaction] + [true true] :both + [true false] :up + [false true] :down + false)] + (assoc sql-migration-map :transactions transactions))) + (defmethod load-files ".sql" [files] (for [[id files] (->> files (group-by (comp first sql-file-parts)) (sort-by key))] (let [{:strs [up down]} (group-by (comp second sql-file-parts) files)] - (sql-migration + (-> {:id (basename id) :up (vec (mapcat read-sql (sort-by str up))) - :down (vec (mapcat read-sql (sort-by str down)))})))) + :down (vec (mapcat read-sql (sort-by str down)))} + sql-migration)))) (defn- load-all-files [files] (->> (group-by file-extension files) From 31bead3d0a123d5660383036fa06ba4fb6989bbe Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 14 Dec 2018 15:34:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jdbc/src/ragtime/jdbc.clj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jdbc/src/ragtime/jdbc.clj b/jdbc/src/ragtime/jdbc.clj index a4d896d..2936c3d 100644 --- a/jdbc/src/ragtime/jdbc.clj +++ b/jdbc/src/ragtime/jdbc.clj @@ -130,13 +130,13 @@ (defn- sql-file-transactions [sql-migration-map] (let [{:keys [up down]} sql-migration-map - is-up-transaction (-> up first (clojure.string/starts-with? "--transaction")) - is-down-transaction (-> down first (clojure.string/starts-with? "--transaction")) + is-up-transaction (-> up first (clojure.string/starts-with? "--transaction-off")) + is-down-transaction (-> down first (clojure.string/starts-with? "--transaction-off")) transactions (case [is-up-transaction is-down-transaction] - [true true] :both - [true false] :up - [false true] :down - false)] + [true true] :false + [true false] :down + [false true] :up + :both)] (assoc sql-migration-map :transactions transactions))) (defmethod load-files ".sql" [files] From 3c20e3a7a6e0710246ee0ca9c1d245b03fa65775 Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 14 Dec 2018 16:00:21 +0800 Subject: [PATCH 3/3] fix bug --- jdbc/src/ragtime/jdbc.clj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jdbc/src/ragtime/jdbc.clj b/jdbc/src/ragtime/jdbc.clj index 2936c3d..d2edc37 100644 --- a/jdbc/src/ragtime/jdbc.clj +++ b/jdbc/src/ragtime/jdbc.clj @@ -76,6 +76,7 @@ (defn- execute-sql! [db-spec statements transaction?] (doseq [s statements] + (println "sql:" s ", transaction:" transaction?) (sql/execute! db-spec [s] {:transaction? transaction?}))) (defrecord SqlMigration [id up down transactions] @@ -133,7 +134,7 @@ is-up-transaction (-> up first (clojure.string/starts-with? "--transaction-off")) is-down-transaction (-> down first (clojure.string/starts-with? "--transaction-off")) transactions (case [is-up-transaction is-down-transaction] - [true true] :false + [true true] false [true false] :down [false true] :up :both)] @@ -148,6 +149,7 @@ {:id (basename id) :up (vec (mapcat read-sql (sort-by str up))) :down (vec (mapcat read-sql (sort-by str down)))} + sql-file-transactions sql-migration)))) (defn- load-all-files [files]