Back

run (clj)

(source)

function

(run store ids command)

Examples

migratus
;;;; Copyright © 2011 Paul Stadig
;;;;
;;;; Licensed under the Apache License, Version 2.0 (the "License"); you may not
;;;; use this file except in compliance with the License.  You may obtain a copy
;;;; of the License at
;;;;
;;;;   http://www.apache.org/licenses/LICENSE-2.0
;;;;
;;;; Unless required by applicable law or agreed to in writing, software
;;;; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
;;;; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
;;;; License for the specific language governing permissions and limitations
;;;; under the License.
(ns migratus.test.database
  (:require [clojure.java.io :as io]
            [next.jdbc :as jdbc]
            [next.jdbc.result-set :as rs]
            [next.jdbc.quoted :as q]
            [next.jdbc.sql :as sql]
            [migratus.protocols :as proto]
            [migratus.core :as core]
            [clojure.test :refer :all]
            [migratus.database :refer :all :as db]
            [clojure.tools.logging :as log]
            [migratus.test.migration.edn :as test-edn]
            [migratus.test.migration.sql :as test-sql]
            [migratus.utils :as utils])
  (:import java.io.File
           java.sql.Connection
           java.util.jar.JarFile
           (java.util.concurrent CancellationException)))

  (run-test test-rollback-until-just-after)

  (jdbc/execute! (:db config)
                 [(str "CREATE TABLE " (q/ansi "table")
                       "(id BIGINT UNIQUE NOT NULL, applied TIMESTAMP,
                        description VARCHAR(1024) )")])
  (run-test test-init)
  (run-test test-rollback-until-just-after)
  (run-test test-backing-out-bad-migration-no-tx)


(deftest test-migration-ignored-when-already-reserved
  (test-with-store
    (proto/make-store config)
    (fn [{:keys [db migration-table-name] :as config}]
      (testing "can only reserve once"
        (is (mark-reserved db migration-table-name))
        (is (not (mark-reserved db migration-table-name))))
      (testing "migrations don't run when locked"
        (is (not (test-sql/verify-table-exists? config "foo")))
        (is (= :ignore (core/migrate config)))
        (is (not (test-sql/verify-table-exists? config "foo"))))
      (testing "migrations run once lock is freed"
        (mark-unreserved db migration-table-name)
        (is (nil? (core/migrate config)))
        (is (test-sql/verify-table-exists? config "foo")))
      (testing "rollback migration isn't run when locked"
        (is (mark-reserved db migration-table-name))
        (core/down config 20111202110600)
        (is (test-sql/verify-table-exists? config "foo")))
      (testing "rollback migration run once lock is freed"
        (mark-unreserved db migration-table-name)
        (core/down config 20111202110600)
        (is (not (test-sql/verify-table-exists? config "foo")))))))

(comment
  (run-test test-migration-ignored-when-already-reserved)

  (run-test test-migration-ignored-when-already-reserved)
  )

(deftest test-backing-out-bad-migration
  (log/debug "running backout tests")
  (test-backing-out* (assoc config :migration-dir "migrations-intentionally-broken")))

(deftest test-backing-out-bad-migration-no-tx
  (log/debug "running backout tests without tx")
  (test-backing-out* (assoc config :migration-dir "migrations-intentionally-broken-no-tx")))
migratus
(ns migratus.test.migration.edn-with-args
  (:require [clojure.java.io :as io]
            [clojure.test :refer :all]
            [migratus.core :as core]
            [migratus.migration.edn :refer :all]
            migratus.mock
            [migratus.protocols :as proto]
            [migratus.utils :as utils])
  (:import java.io.File))

(deftest test-run-edn-migrations
  (let [config (merge test-config
                      {:store :mock
                       :completed-ids (atom #{})
                       :migration-dir "migrations-edn-args"})]
    (is (not (test-file-exists?)))
    (core/migrate config)
    (is (test-file-exists?))
    (core/rollback config)
    (is (not (test-file-exists?)))))
migratus
(ns migratus.test.migration.sql
  (:require [clojure.java.io :as io]
            [clojure.test :refer :all]
            [migratus.core :as core]
            [migratus.database :as db]
            [migratus.migration.sql :refer :all]
            [next.jdbc :as jdbc]
            [next.jdbc.result-set :as rs]))

(deftest test-run-sql-migrations
  (let [config (merge test-config
                      {:store :mock
                       :completed-ids (atom #{})})]


  (run-test test-run-sql-migrations)
migratus
(ns migratus.test.migration.edn
  (:require [clojure.java.io :as io]
            [clojure.test :refer :all]
            [migratus.core :as core]
            [migratus.migration.edn :refer :all]
            migratus.mock
            [migratus.protocols :as proto]
            [migratus.utils :as utils])
  (:import java.io.File))

(deftest test-run-edn-migrations
  (let [config (merge test-config
                      {:store :mock
                       :completed-ids (atom #{})
                       :migration-dir "migrations-edn"})]
    (is (not (test-file-exists?)))
    (core/migrate config)
    (is (test-file-exists?))
    (core/rollback config)
    (is (not (test-file-exists?)))))