Artur-Sulej / excellent_migrations

An Elixir tool for checking safety of database migrations.
MIT License
232 stars 25 forks source link

Fixed detect_many_columns_index parsing #16

Closed pyzlnar closed 2 years ago

pyzlnar commented 2 years ago

Hello!

I found a bug on detect_many_columns_index where it would raise an error and crash. This happens when creating a single column index if it also had options.

Eg:

create index(:a_table, :my_column, where: "arbitrary_option = null")
** (Protocol.UndefinedError) protocol Enumerable not implemented for :my_column of type Atom. This protocol is implemented for the following type(s): Date.Range, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Jason.OrderedObject, List, Map, MapSet, Range, Stream
     stacktrace:
     (elixir 1.13.2) lib/enum.ex:1: Enumerable.impl_for!/1
     (elixir 1.13.2) lib/enum.ex:155: Enumerable.count/1
     (elixir 1.13.2) lib/enum.ex:656: Enum.count/1
     (excellent_migrations 0.1.5) lib/ast_parser.ex:60: ExcellentMigrations.AstParser.detect_many_columns_index/1
     (excellent_migrations 0.1.5) lib/ast_parser.ex:24: ExcellentMigrations.AstParser.detect_dangers/1
     (excellent_migrations 0.1.5) lib/ast_parser.ex:15: anonymous fn/3 in ExcellentMigrations.AstParser.traverse_ast/2
     (excellent_migrations 0.1.5) lib/ast_parser.ex:14: ExcellentMigrations.AstParser.traverse_ast/2

This PR fixes the issue and adds a unit test for good measure.

lmk if something else is needed! :)