Skip to content

Commit

Permalink
ignore columns defined as string
Browse files Browse the repository at this point in the history
  • Loading branch information
faraaz-deepsource committed Aug 6, 2023
1 parent 2c34416 commit e1ac572
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/trains/utils/migration_tailor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def self.stitch(models = {}, migrations)
end
when :add_column, :add_column_with_default, :add_reference
models[mig.table_name].fields.push(*mig.fields)
when :ignore_column
models[mig.table_name].ignored_columns.push(*mig.fields.map(&:name))
when :remove_column
column =
models[mig.table_name].fields.find do |field|
Expand Down
4 changes: 2 additions & 2 deletions lib/trains/visitor/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ def parse_model(node)

arguments = node.arguments.first.to_a
arguments = arguments.select do |child|
child.is_a?(RuboCop::AST::SymbolNode)
child.is_a?(RuboCop::AST::SymbolNode) || child.is_a?(RuboCop::AST::StrNode)
end.map(&:value)

@result << DTO::Migration.new(
@model_class,
:ignore_column,
[*arguments.map { |arg| DTO::Field.new(arg, nil) }],
[*arguments.map { |arg| DTO::Field.new(arg.to_sym, nil) }],
nil
)

Expand Down
16 changes: 10 additions & 6 deletions spec/lib/trains/visitor/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ class AccountPin < ApplicationRecord

expect(parser.result).to eq(
[
Trains::DTO::Migration.new(
table_name: 'AccountPin',
modifier: :ignore_column,
fields: [Trains::DTO::Field.new(:foo, nil), Trains::DTO::Field.new(:baz, nil)],
version: nil
)
Trains::DTO::Migration.new(
table_name: 'AccountPin',
modifier: :ignore_column,
fields: [
Trains::DTO::Field.new(:foo, nil),
Trains::DTO::Field.new(:baz, nil),
Trains::DTO::Field.new(:what, nil)
],
version: nil
)
]
)
end
Expand Down

0 comments on commit e1ac572

Please sign in to comment.