Skip to content

Commit 3af6f4f

Browse files
committed
[#240] Added example on how to call migrations with bb
1 parent cb0c76e commit 3af6f4f

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Diff for: examples/postgres/README.md

+26-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@ Since Migratus is a clojure library, we need to run it via clojure like this `cl
6464

6565
There is also a bash script `migratus.sh` that does the same: `./migratus.sh --help`
6666

67+
#### Calling migratus via babashka task
68+
69+
We can use [babashka](https://babashka.org/) tasks to drive migratus.
70+
This is usefull for creating developer and ops tooling.
71+
72+
Developers can easily create migrations from cli.
73+
Operations people can query the migration status on the server.
74+
75+
Bellow is a sample `bb.edn` file that calls the migratus alias in `deps.edn`, that we created earlier.
76+
77+
bb.edn
78+
```clojure
79+
;; example on how to call migrations via babashka
80+
{:tasks {:requires ([clojure.string :as str])
81+
migrate
82+
{:doc "Run migration tasks. Specify MIGRATUS_DB_SPEC to choose db."
83+
:task (clojure {:dir "."
84+
:extra-env {"MIGRATUS_STORE" "database"
85+
"MIGRATUS_MIGRATION_DIR" "resources/migrations"}}
86+
(str/join " " (list* "-M:migratus" *command-line-args*)))}}}
87+
88+
```
6789

6890
Commands with migratus
6991

@@ -72,6 +94,9 @@ Commands with migratus
7294
# We export the configuration as env variable, but we can use cli or file as well
7395
export MIGRATUS_CONFIG='{:store :database :db {:jdbcUrl "jdbc:postgresql://localhost:5432/migratus_example_db?user=postgres&password=migrate-me"}}'
7496

97+
7598
clojure -M:migratus status
99+
# via bb
100+
bb migratus status
76101

77-
```
102+
```

Diff for: examples/postgres/bb.edn

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
;; example on how to call migrations via babashka
2+
{:tasks {:requires ([clojure.string :as str])
3+
migrate
4+
{:doc "Run migration tasks. Specify MIGRATUS_DB_SPEC to choose db."
5+
:task (clojure {:dir "."
6+
:extra-env {"MIGRATUS_STORE" "database"
7+
"MIGRATUS_MIGRATION_DIR" "resources/migrations"}}
8+
(str/join " " (list* "-M:migratus" *command-line-args*)))}}}

0 commit comments

Comments
 (0)