-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow --repo option & --migration-dir for phx.gen.schema #4905
Conversation
792263c
to
2a1c686
Compare
2a1c686
to
51acddd
Compare
lib/mix/tasks/phx.gen.schema.ex
Outdated
Generated migrations can be added to a specific `migration-dir` which sets the | ||
migration folder path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generated migrations can be added to a specific `migration-dir` which sets the | |
migration folder path | |
Generated migrations can be added to a specific `--migration-dir` which sets the | |
migration folder path: |
lib/mix/tasks/phx.gen.schema.ex
Outdated
## repo | ||
|
||
Generated migration can use `repo` to set the migration repository | ||
folder with option `--repo`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
folder with option `--repo`. | |
folder with option `--repo`: |
51acddd
to
661cf51
Compare
lib/mix/tasks/phx.gen.schema.ex
Outdated
case Map.new(opts) do | ||
%{migration_dir: migration_dir} -> | ||
migration_dir | ||
|
||
%{repo: _} -> | ||
repo_name = repo |> Module.split() |> List.last() |> Macro.underscore() | ||
Mix.Phoenix.context_app_path(ctx_app, "priv/#{repo_name}/migrations/") | ||
|
||
_ -> | ||
Mix.Phoenix.context_app_path(ctx_app, "priv/repo/migrations/") | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure converting to a map for this is worth it, but this code is not perf critical anyway. But in case you want something else:
case Map.new(opts) do | |
%{migration_dir: migration_dir} -> | |
migration_dir | |
%{repo: _} -> | |
repo_name = repo |> Module.split() |> List.last() |> Macro.underscore() | |
Mix.Phoenix.context_app_path(ctx_app, "priv/#{repo_name}/migrations/") | |
_ -> | |
Mix.Phoenix.context_app_path(ctx_app, "priv/repo/migrations/") | |
end | |
cond do | |
migration_dir = opts[:migration_dir] -> | |
migration_dir | |
opts[:repo] -> | |
repo_name = repo |> Module.split() |> List.last() |> Macro.underscore() | |
Mix.Phoenix.context_app_path(ctx_app, "priv/#{repo_name}/migrations/") | |
true -> | |
Mix.Phoenix.context_app_path(ctx_app, "priv/repo/migrations/") | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SHIP IT
The `repo` and `migration-dir` options change the location of the migrations directory, either to the specified directory or one that matches the repo name (underscored). The default is explicitly set to "repo" if neither option is set, to ensure backwards compatability even if the repo has a different name than the typical `MyApp.Repo`.
661cf51
to
05c83f4
Compare
This allows us to provide a
--repo
flag tomix phx.gen.schema
It seems support is already built in for this with
Mix.Phoenix.Schema
so I simply added it to theopts
in the format it seems is expected and made it utilise thatrepo
for the migration path as wellThrough options i've also added a
--migration_dir
which is passed in and used instead of the generated repo pathIf this is wanted lemme know and I'll add tests to get it merged