Skip to content

Conversation

@Eiji7
Copy link
Contributor

@Eiji7 Eiji7 commented Oct 31, 2019

ping @josevalim

Runner.flush
@doc "Executes queue migration commands."
defmacro flush do
quote bind_quoted: [caller: __CALLER__.module] do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need bind_quoted, the module inside the quote will be __MODULE__.

@doc "Executes queue migration commands."
defmacro flush do
quote bind_quoted: [caller: __CALLER__.module] do
if direction() == :down and function_exported?(caller, :change, 0) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migrator checks for down first and then falls back to :change, so we should express this here:

Suggested change
if direction() == :down and function_exported?(caller, :change, 0) do
if direction() == :down and not function_exported?(caller, :down, 0) do

defmacro flush do
quote bind_quoted: [caller: __CALLER__.module] do
if direction() == :down and function_exported?(caller, :change, 0) do
message = "Calling flush() inside change when doing rollback is not supported."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error messages start with lowercase:

Suggested change
message = "Calling flush() inside change when doing rollback is not supported."
message = "calling flush() inside change when doing rollback is not supported."

quote bind_quoted: [caller: __CALLER__.module] do
if direction() == :down and function_exported?(caller, :change, 0) do
message = "Calling flush() inside change when doing rollback is not supported."
raise ArgumentError, message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an ArgumentError in this case, so this is enough:

Suggested change
raise ArgumentError, message
raise message

@josevalim
Copy link
Member

Thanks @Eiji7, I have dropped some comments. Also, instead of adding an integration test, can you please add a unit test? See test/ecto/migrator_test.exs.

1. Use __MODULE__ inside quote instead of __CALLER__ in bind_quoted
2. Fix check in if
3. Changed error message to start with lowercase
4. Use raise/1 instead of raise/2 with ArgumentError
5. Moved test from integration_test/sql/migration.ex to test/ecto/migrator_test.exs
@Eiji7
Copy link
Contributor Author

Eiji7 commented Nov 1, 2019

@josevalim Thanks, everything makes sense for me. I have send all suggested changes as well as moved test.

@josevalim josevalim merged commit a5592af into elixir-ecto:master Nov 1, 2019
@josevalim
Copy link
Member

❤️ 💚 💙 💛 💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants