Skip to content

Commit 5130cfa

Browse files
committed
Replace implicit migrations file with option
The #duct/include reader tag can still be used to factor the migrations out into their own file; it just needs to be explicit.
1 parent 655eff4 commit 5130cfa

5 files changed

Lines changed: 25 additions & 17 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ Or to your Leiningen project file:
2828
Add the `:duct.module/sql` key to your Duct configuration:
2929

3030
```edn
31-
{:duct.module/sql {}}
31+
{:duct.module/sql {:migrations #duct/include "migrations.edn"}}
3232
```
3333
This module uses the Integrant [expand][] function to add the
3434
following keys to the configuration:
3535

3636
* `:duct.database.sql/hikaricp` - a SQL datasource
3737
* `:duct.migrator/ragtime` - applies database migrations
3838

39-
This will setup a pooled database connection and a migrator that looks
40-
for a file `migrations.edn` in the current directory. See the
39+
This will setup a pooled database connection and a migrator with
40+
migrations loaded from the `migrations.edn` include file. See the
4141
documentation on [Ragtime's SQL migrations][migrations] for information
4242
about the syntax.
4343

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
66
:dependencies [[org.clojure/clojure "1.12.2"]
77
[org.duct-framework/database.sql.hikaricp "0.7.1"]
8-
[org.duct-framework/migrator.ragtime "0.5.3"]
8+
[org.duct-framework/migrator.ragtime "0.6.0"]
99
[org.duct-framework/repl.refers "0.1.0"]
1010
[integrant "1.0.0"]
1111
[com.github.seancorfield/next.jdbc "1.3.1070"]]

src/duct/module/sql.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
(ns duct.module.sql
22
(:require [integrant.core :as ig]))
33

4-
(defmethod ig/expand-key :duct.module/sql [_ _]
4+
(defmethod ig/expand-key :duct.module/sql [_ {:keys [migrations]}]
55
(let [components {:duct.database.sql/hikaricp
66
{:logger (ig/refset :duct/logger)
77
:jdbcUrl (ig/var 'jdbc-url)}
88
:duct.migrator/ragtime
9-
{:logger (ig/refset :duct/logger)
10-
:database (ig/ref :duct.database/sql)
11-
:strategy :rebase
12-
:migrations-file "migrations.edn"}}]
9+
{:logger (ig/refset :duct/logger)
10+
:database (ig/ref :duct.database/sql)
11+
:strategy :rebase
12+
:migrations migrations}}]
1313
(ig/profile
1414
:main (assoc-in components [:duct.migrator/ragtime :strategy]
1515
:raise-error)

src/integrant/annotations.edn

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
:doc "The JDBC database URL"}}
77
:doc
88
"A module that adds components for accessing SQL databases to the
9-
configuration. Takes no options.
9+
configuration.
10+
11+
Takes the following option:
12+
- `:migrations` - a data structure of [Ragtime SQL Migrations][1]
1013
1114
In the `:repl` profile, migrations are run using the `:rebase` strategy
1215
(conflicts replace existing migrations), while in the `:main` profile the
@@ -16,4 +19,6 @@
1619
- `db` - get a `DataSource` of the running system's database
1720
- `sql` - run a SQL statement on the system's database
1821
19-
A Duct `jdbc-url` variable is added to configure the JDBC database URL."}}
22+
A Duct `jdbc-url` variable is added to configure the JDBC database URL.
23+
24+
[1]: https://github.com/weavejester/ragtime/wiki/SQL-Migrations#edn"}}

test/duct/module/sql_test.clj

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
{:database (ig/ref :duct.database/sql)
1515
:logger (ig/refset :duct/logger)
1616
:strategy :raise-error
17-
:migrations-file "migrations.edn"}}
18-
(-> {:duct.module/sql {}}
17+
:migrations '[[:create-table foo (id "INTEGER")]]}}
18+
(-> {:duct.module/sql
19+
{:migrations '[[:create-table foo (id "INTEGER")]]}}
1920
(ig/expand (ig/deprofile [:main]))
2021
(ig/bind {'jdbc-url "jdbc:sqlite:"})))))
2122

@@ -27,11 +28,12 @@
2728
{:database (ig/ref :duct.database/sql)
2829
:logger (ig/refset :duct/logger)
2930
:strategy :rebase
30-
:migrations-file "migrations.edn"}
31+
:migrations '[[:create-table foo (id "INTEGER")]]}
3132
:duct.repl/refers
3233
'{db duct.repl.sql/db
3334
sql duct.repl.sql/sql}}
34-
(-> {:duct.module/sql {}}
35+
(-> {:duct.module/sql
36+
{:migrations '[[:create-table foo (id "INTEGER")]]}}
3537
(ig/expand (ig/deprofile [:repl]))
3638
(ig/bind {'jdbc-url "jdbc:sqlite:"})))))
3739

@@ -43,7 +45,8 @@
4345
{:database (ig/ref :duct.database/sql)
4446
:logger (ig/refset :duct/logger)
4547
:strategy :rebase
46-
:migrations-file "migrations.edn"}}
47-
(-> {:duct.module/sql {}}
48+
:migrations '[[:create-table foo (id "INTEGER")]]}}
49+
(-> {:duct.module/sql
50+
{:migrations '[[:create-table foo (id "INTEGER")]]}}
4851
(ig/expand (ig/deprofile [:test]))
4952
(ig/bind {'jdbc-url "jdbc:sqlite:"}))))))

0 commit comments

Comments
 (0)