Back
find-migrations (clj)
(source)function
(find-migrations dir exclude-scripts properties)
Examples
migratus
(ns migratus.test.migrations
(:require
[clojure.test :refer [deftest is]]
[migratus.migration.sql :as sql-mig]
[migratus.migrations :as sut]
[migratus.properties :as props]
[migratus.utils :as utils]))
(deftest test-find-migrations
(let [create-migrations {"20111202113000"
{"create-bar-table"
{:sql
{:up "CREATE TABLE IF NOT EXISTS bar(id BIGINT);\n"
:down "DROP TABLE IF EXISTS bar;\n"}}}
"20111202110600"
{"create-foo-table"
{:sql
{:up "CREATE TABLE IF NOT EXISTS foo(id bigint);\n"
:down "DROP TABLE IF EXISTS foo;\n"}}}}
migrations (assoc create-migrations "20120827170200"
{"multiple-statements"
{:sql
{:up multi-stmt-up
:down multi-stmt-down}}})]
(is (= migrations (sut/find-migrations "migrations" ["init.sql"] nil))
"single migrations dir")
(is (= create-migrations (sut/find-migrations "migrations" ["init.sql" "*-multiple-*"] nil))
"single migrations dir with glob exclusions"))
(is (= {"20220604110500"
{"create-foo1-table"
{:sql
{:down "DROP TABLE IF EXISTS foo1;"
:up "CREATE TABLE IF NOT EXISTS foo1(id bigint);"}}}
"20220604113000"
{"create-bar1-table"
{:sql
{:down "DROP TABLE IF EXISTS bar1;"
:up "CREATE TABLE IF NOT EXISTS bar1(id BIGINT);"}}}
"20220604113500"
{"create-bar2-table"
{:sql
{:up "CREATE TABLE IF NOT EXISTS bar2(id BIGINT);"
:down "DROP TABLE IF EXISTS bar2;"}}}
"20220604111500"
{"create-foo2-table"
{:sql
{:down "DROP TABLE IF EXISTS foo2;",
:up "CREATE TABLE IF NOT EXISTS foo2(id bigint);"}}}}
(sut/find-migrations ["migrations1" "migrations2"] [] nil))
"multiple migrations dirs")
(is (= {"20111202110600" {"create-foo-table" {:sql {:up "CREATE TABLE IF NOT EXISTS foo(id bigint);\n",
:down "DROP TABLE IF EXISTS TEST_SCHEMA.foo;\n"}},
"create-schema" {:sql {:up "CREATE SCHEMA TEST_SCHEMA\n"}}}}
(sut/find-migrations "migrations-with-props" [] {"${migratus.schema}" "TEST_SCHEMA"}))))
yogthos/migratus
(ns migratus.test.migrations
(:require
[clojure.test :refer [deftest is]]
[migratus.migration.sql :as sql-mig]
[migratus.migrations :as sut]
[migratus.properties :as props]
[migratus.utils :as utils]))
(deftest test-find-migrations
(let [create-migrations {"20111202113000"
{"create-bar-table"
{:sql
{:up "CREATE TABLE IF NOT EXISTS bar(id BIGINT);\n"
:down "DROP TABLE IF EXISTS bar;\n"}}}
"20111202110600"
{"create-foo-table"
{:sql
{:up "CREATE TABLE IF NOT EXISTS foo(id bigint);\n"
:down "DROP TABLE IF EXISTS foo;\n"}}}}
migrations (assoc create-migrations "20120827170200"
{"multiple-statements"
{:sql
{:up multi-stmt-up
:down multi-stmt-down}}})]
(is (= migrations (sut/find-migrations "migrations" ["init.sql"] nil))
"single migrations dir")
(is (= create-migrations (sut/find-migrations "migrations" ["init.sql" "*-multiple-*"] nil))
"single migrations dir with glob exclusions"))
(is (= {"20220604110500"
{"create-foo1-table"
{:sql
{:down "DROP TABLE IF EXISTS foo1;"
:up "CREATE TABLE IF NOT EXISTS foo1(id bigint);"}}}
"20220604113000"
{"create-bar1-table"
{:sql
{:down "DROP TABLE IF EXISTS bar1;"
:up "CREATE TABLE IF NOT EXISTS bar1(id BIGINT);"}}}
"20220604113500"
{"create-bar2-table"
{:sql
{:up "CREATE TABLE IF NOT EXISTS bar2(id BIGINT);"
:down "DROP TABLE IF EXISTS bar2;"}}}
"20220604111500"
{"create-foo2-table"
{:sql
{:down "DROP TABLE IF EXISTS foo2;",
:up "CREATE TABLE IF NOT EXISTS foo2(id bigint);"}}}}
(sut/find-migrations ["migrations1" "migrations2"] [] nil))
"multiple migrations dirs")
(is (= {"20111202110600" {"create-foo-table" {:sql {:up "CREATE TABLE IF NOT EXISTS foo(id bigint);\n",
:down "DROP TABLE IF EXISTS TEST_SCHEMA.foo;\n"}},
"create-schema" {:sql {:up "CREATE SCHEMA TEST_SCHEMA\n"}}}}
(sut/find-migrations "migrations-with-props" [] {"${migratus.schema}" "TEST_SCHEMA"}))))