Skip to content

Commit

Permalink
improvement: require name when generating migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Dec 27, 2023
1 parent 89a4363 commit 6ff25bf
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/mix/tasks/ash_postgres.generate_migrations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ defmodule Mix.Tasks.AshPostgres.GenerateMigrations do

@shortdoc "Generates migrations, and stores a snapshot of your resources"
def run(args) do
{name, args} =
case args do
["-" <> _ | _] ->
{nil, args}

[first | rest] ->
{first, rest}

[] ->
{nil, []}
end

{opts, _} =
OptionParser.parse!(args,
strict: [
Expand All @@ -94,6 +106,18 @@ defmodule Mix.Tasks.AshPostgres.GenerateMigrations do
opts
|> Keyword.put(:format, !opts[:no_format])
|> Keyword.delete(:no_format)
|> Keyword.put_new(:name, name)

if !opts[:name] && !opts[:dry_run] && !opts[:check] do
IO.warn("""
Name must be provided when generating migrations, unless `--dry-run` or `--check` is also provided.
Using an autogenerated name will be deprecated in a future release.
Please provide a name. for example:
mix ash_postgres.generate_migrations <name> #{Enum.join(args, " ")}
""")
end

AshPostgres.MigrationGenerator.generate(apis, opts)
end
Expand Down

0 comments on commit 6ff25bf

Please sign in to comment.