mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
improvement: properly format generated migrations
This commit is contained in:
parent
2a326ea6bd
commit
ea853e5171
2 changed files with 6 additions and 16 deletions
|
@ -305,7 +305,7 @@ defmodule AshPostgres.MigrationGenerator do
|
|||
pretty: true
|
||||
)
|
||||
|
||||
contents = format(contents, opts)
|
||||
contents = String.trim(format(migration_file, contents, opts))
|
||||
create_file(snapshot_file, snapshot_contents, force: true)
|
||||
create_file(migration_file, contents)
|
||||
end
|
||||
|
@ -869,7 +869,7 @@ defmodule AshPostgres.MigrationGenerator do
|
|||
"""
|
||||
|
||||
try do
|
||||
contents = format(contents, opts)
|
||||
contents = String.trim(format(migration_file, contents, opts))
|
||||
|
||||
if opts.dry_run do
|
||||
Mix.shell().info(contents)
|
||||
|
@ -980,9 +980,10 @@ defmodule AshPostgres.MigrationGenerator do
|
|||
|
||||
defp maybe_comment(text, _), do: text
|
||||
|
||||
defp format(string, opts) do
|
||||
defp format(path, string, opts) do
|
||||
if opts.format do
|
||||
Code.format_string!(string, locals_without_parens: ecto_sql_locals_without_parens())
|
||||
{func, _} = Mix.Tasks.Format.formatter_for_file(path)
|
||||
func.(string)
|
||||
else
|
||||
string
|
||||
end
|
||||
|
@ -999,17 +1000,6 @@ defmodule AshPostgres.MigrationGenerator do
|
|||
reraise exception, __STACKTRACE__
|
||||
end
|
||||
|
||||
defp ecto_sql_locals_without_parens do
|
||||
path = File.cwd!() |> Path.join("deps/ecto_sql/.formatter.exs")
|
||||
|
||||
if File.exists?(path) do
|
||||
{opts, _} = Code.eval_file(path)
|
||||
Keyword.get(opts, :locals_without_parens, [])
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
defp streamline(ops, acc \\ [])
|
||||
defp streamline([], acc), do: Enum.reverse(acc)
|
||||
|
||||
|
|
2
mix.exs
2
mix.exs
|
@ -12,7 +12,7 @@ defmodule AshPostgres.MixProject do
|
|||
[
|
||||
app: :ash_postgres,
|
||||
version: @version,
|
||||
elixir: "~> 1.11",
|
||||
elixir: "~> 1.13",
|
||||
start_permanent: Mix.env() == :prod,
|
||||
deps: deps(),
|
||||
description: @description,
|
||||
|
|
Loading…
Reference in a new issue