From 7691ef14a02e91acbb93755aa22831b5b66766d5 Mon Sep 17 00:00:00 2001 From: Nicholas Moen Date: Sun, 1 Jun 2025 02:45:10 -0600 Subject: [PATCH 1/2] add formatter config instructions for migrations --- lib/ecto/migration.ex | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/ecto/migration.ex b/lib/ecto/migration.ex index 22d29ab61..20667965e 100644 --- a/lib/ecto/migration.ex +++ b/lib/ecto/migration.ex @@ -184,6 +184,39 @@ defmodule Ecto.Migration do To avoid that we recommend to use `execute/2` with anonymous functions instead. For more information and example usage please take a look at `execute/2` function. + ## Formatter configuration + + To enable Ecto's custom `mix format` rules in your migrations, you can create a new formatter + config file in your project called `priv/[your_repo]/migrations/.formatter.exs` with the + following content: + + ```elixir + [ + import_deps: [:ecto_sql], + inputs: ["*.exs"] + ] + ``` + + You will also need to add a line or two to your project's main formatter config so that the + formatter knows where to find the new config file. Update (or create) your project's main + `.formatter.exs` file: + + ```elixir + [ + # Add this line to enable Ecto formatter rules + import_deps: [:ecto, :ecto_sql], + + # Add this line to enable Ecto's formatter rules in your migrations directory + subdirectories: ["priv/*/migrations"], + + # Default Elixir project rules + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] + ] + ``` + + Now, when you run `mix format`, the formatter should apply Ecto's custom rules when formatting + your migrations (e.g. no brackets are automatically added when creating columns with `add/3`). + ## Repo configuration ### Migrator configuration From 1803568b779ad97654238edd32372e0dfe1d7662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 2 Jun 2025 08:39:05 +0200 Subject: [PATCH 2/2] Update lib/ecto/migration.ex --- lib/ecto/migration.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ecto/migration.ex b/lib/ecto/migration.ex index 20667965e..a920e47d4 100644 --- a/lib/ecto/migration.ex +++ b/lib/ecto/migration.ex @@ -204,7 +204,7 @@ defmodule Ecto.Migration do ```elixir [ # Add this line to enable Ecto formatter rules - import_deps: [:ecto, :ecto_sql], + import_deps: [:ecto], # Add this line to enable Ecto's formatter rules in your migrations directory subdirectories: ["priv/*/migrations"],