Skip to content

Commit 3c3c4b3

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

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

examples/postgres/README.md

Lines changed: 28 additions & 1 deletion
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,11 @@ 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+
98+
export MIGRATUS_CONFIG='{:store :database :db {:jdbcUrl "jdbc:postgresql://dev1.int.drevidence.com:5433/docsearch_sample?user=docsearch&password=docsearch"} :migration-dir "/netdava/DRE/DocSearch/workspace/components/sqldb_migrate/resources/migrations"}'
99+
75100
clojure -M:migratus status
101+
# via bb
102+
bb migratus status
76103

77-
```
104+
```

examples/postgres/bb.edn

Lines changed: 8 additions & 0 deletions
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)