Skip to content

Commit 4c5776d

Browse files
Add formatter config instructions for migrations (#670)
1 parent a4cb762 commit 4c5776d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lib/ecto/migration.ex

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,39 @@ defmodule Ecto.Migration do
184184
To avoid that we recommend to use `execute/2` with anonymous functions instead.
185185
For more information and example usage please take a look at `execute/2` function.
186186
187+
## Formatter configuration
188+
189+
To enable Ecto's custom `mix format` rules in your migrations, you can create a new formatter
190+
config file in your project called `priv/[your_repo]/migrations/.formatter.exs` with the
191+
following content:
192+
193+
```elixir
194+
[
195+
import_deps: [:ecto_sql],
196+
inputs: ["*.exs"]
197+
]
198+
```
199+
200+
You will also need to add a line or two to your project's main formatter config so that the
201+
formatter knows where to find the new config file. Update (or create) your project's main
202+
`.formatter.exs` file:
203+
204+
```elixir
205+
[
206+
# Add this line to enable Ecto formatter rules
207+
import_deps: [:ecto],
208+
209+
# Add this line to enable Ecto's formatter rules in your migrations directory
210+
subdirectories: ["priv/*/migrations"],
211+
212+
# Default Elixir project rules
213+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
214+
]
215+
```
216+
217+
Now, when you run `mix format`, the formatter should apply Ecto's custom rules when formatting
218+
your migrations (e.g. no brackets are automatically added when creating columns with `add/3`).
219+
187220
## Repo configuration
188221
189222
### Migrator configuration

0 commit comments

Comments
 (0)