Maintenance: Added rubocop to make sure that migration reset their column information if needed.
This commit is contained in:
parent
09d2d4df58
commit
e7039d7046
5 changed files with 144 additions and 2 deletions
|
@ -3,7 +3,7 @@ module RuboCop
|
||||||
module Zammad
|
module Zammad
|
||||||
class ExistsDateTimePrecision < Cop
|
class ExistsDateTimePrecision < Cop
|
||||||
def_node_matcher :column?, <<-PATTERN
|
def_node_matcher :column?, <<-PATTERN
|
||||||
$(send _ {:create_column :change_column} (sym _) (sym _) (sym :datetime) ... )
|
$(send _ {:add_column :change_column} (sym _) (sym _) (sym :datetime) ... )
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def_node_matcher :column_limit?, <<-PATTERN
|
def_node_matcher :column_limit?, <<-PATTERN
|
||||||
|
@ -25,7 +25,7 @@ module RuboCop
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
This rubocop will match all change_column/create_column/create_table/alter_table statements
|
This rubocop will match all change_column/add_column/create_table/alter_table statements
|
||||||
and check if there are :datetime or :timestamps column which do not have the limit: 3 setting.
|
and check if there are :datetime or :timestamps column which do not have the limit: 3 setting.
|
||||||
|
|
||||||
good:
|
good:
|
||||||
|
|
88
.rubocop/cop/zammad/exists_reset_column_information.rb
Normal file
88
.rubocop/cop/zammad/exists_reset_column_information.rb
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
module RuboCop
|
||||||
|
module Cop
|
||||||
|
module Zammad
|
||||||
|
class ExistsResetColumnInformation < Cop
|
||||||
|
def_node_matcher :table?, <<-PATTERN
|
||||||
|
$(send _ {:create_table :change_table} ... )
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
def_node_matcher :column?, <<-PATTERN
|
||||||
|
$(send _ {:add_column :change_column :rename_column :remove_column} ... )
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
def_node_matcher :reset?, <<-PATTERN
|
||||||
|
$( ... :reset_column_information )
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
def message(class_name)
|
||||||
|
"Changes of the schema need to be followed by a #{class_name}.reset_column_information to have the right state of the db in the migration and future migrations."
|
||||||
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
|
|
||||||
|
This rubocop will match all add, change, rename and remove column statements
|
||||||
|
and check if there are reset_column_information function calls existing for the model.
|
||||||
|
|
||||||
|
good:
|
||||||
|
|
||||||
|
change_column :smime_certificates, :not_after_at, :datetime, limit: 3
|
||||||
|
|
||||||
|
SMIMECertificate.reset_column_information
|
||||||
|
|
||||||
|
bad:
|
||||||
|
|
||||||
|
change_column :smime_certificates, :not_after_at, :datetime, limit: 3
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def column_classes
|
||||||
|
@column_classes ||= {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def table_classes
|
||||||
|
@table_classes ||= {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset_classes
|
||||||
|
@reset_classes ||= {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def column_class(node)
|
||||||
|
node.children[2].children[0].to_s.classify
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset_class(node)
|
||||||
|
node.children[0].children[1].to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def table_class(node)
|
||||||
|
node.children[2].children[0].to_s.classify
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_send(node)
|
||||||
|
if column?(node)
|
||||||
|
column_classes[column_class(node)] = node
|
||||||
|
elsif table?(node)
|
||||||
|
table_classes[table_class(node)] = node
|
||||||
|
elsif reset?(node)
|
||||||
|
reset_classes[reset_class(node)] = node
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_investigation_end
|
||||||
|
column_classes.each do |key, value|
|
||||||
|
next if reset_classes.key?(key)
|
||||||
|
|
||||||
|
add_offense(value, message: message(key))
|
||||||
|
end
|
||||||
|
table_classes.each do |key, value|
|
||||||
|
next if reset_classes.key?(key)
|
||||||
|
|
||||||
|
add_offense(value, message: message(key))
|
||||||
|
end
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -312,3 +312,11 @@ Lint/UnusedMethodArgument:
|
||||||
Zammad/PreferNegatedIfOverUnless:
|
Zammad/PreferNegatedIfOverUnless:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'bin/rspec'
|
- 'bin/rspec'
|
||||||
|
|
||||||
|
Zammad/ExistsDateTimePrecision:
|
||||||
|
Include:
|
||||||
|
- "db/migrate/*.rb"
|
||||||
|
|
||||||
|
Zammad/ExistsResetColumnInformation:
|
||||||
|
Include:
|
||||||
|
- "db/migrate/*.rb"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
require_relative 'cop/zammad/exists_condition'
|
require_relative 'cop/zammad/exists_condition'
|
||||||
require_relative 'cop/zammad/exists_date_time_precision'
|
require_relative 'cop/zammad/exists_date_time_precision'
|
||||||
|
require_relative 'cop/zammad/exists_reset_column_information'
|
||||||
require_relative 'cop/zammad/have_no_over_not_to'
|
require_relative 'cop/zammad/have_no_over_not_to'
|
||||||
require_relative 'cop/zammad/no_to_sym_on_string'
|
require_relative 'cop/zammad/no_to_sym_on_string'
|
||||||
require_relative 'cop/zammad/prefer_negated_if_over_unless'
|
require_relative 'cop/zammad/prefer_negated_if_over_unless'
|
||||||
|
|
|
@ -751,3 +751,48 @@ RSpec/MultipleMemoizedHelpers:
|
||||||
Description: Checks if example groups contain too many `let` and `subject` calls.
|
Description: Checks if example groups contain too many `let` and `subject` calls.
|
||||||
Enabled: false
|
Enabled: false
|
||||||
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers
|
||||||
|
|
||||||
|
Zammad/ExistsResetColumnInformation:
|
||||||
|
Exclude:
|
||||||
|
- 'db/migrate/20120101000001_create_base.rb'
|
||||||
|
- 'db/migrate/20120101000010_create_ticket.rb'
|
||||||
|
- 'db/migrate/20150979000001_update_timestamps.rb'
|
||||||
|
- 'db/migrate/20160921000001_permission_active.rb'
|
||||||
|
- 'db/migrate/20160921000001_permission_active.rb.rb'
|
||||||
|
- 'db/migrate/20161101131409_create_doorkeeper_tables.rb'
|
||||||
|
- 'db/migrate/20161112000001_organization_domain_based_assignment.rb'
|
||||||
|
- 'db/migrate/20161117000001_job_unable_to_create_issue_432.rb'
|
||||||
|
- 'db/migrate/20161228000001_add_taskbar_meta.rb'
|
||||||
|
- 'db/migrate/20170116000001_add_ticket_time_accounting_373.rb'
|
||||||
|
- 'db/migrate/20170119000001_login_email_length_650.rb'
|
||||||
|
- 'db/migrate/20170207081400_ticket_state_priority_defaults.rb'
|
||||||
|
- 'db/migrate/20170419000001_ldap_support.rb'
|
||||||
|
- 'db/migrate/20170419000002_overview_role_ids.rb'
|
||||||
|
- 'db/migrate/20170420000001_chat_increase_message_size.rb'
|
||||||
|
- 'db/migrate/20170421110000_add_origin_by_id.rb'
|
||||||
|
- 'db/migrate/20170426135500_add_reply_to.rb'
|
||||||
|
- 'db/migrate/20170515000001_scheduler_status.rb'
|
||||||
|
- 'db/migrate/20170531144425_foreign_keys.rb'
|
||||||
|
- 'db/migrate/20170608151442_enhanced_permissions.rb'
|
||||||
|
- 'db/migrate/20170619000001_tree_select.rb'
|
||||||
|
- 'db/migrate/20170626000001_locale_add_direction.rb'
|
||||||
|
- 'db/migrate/20171002091043_change_note_char_limit_for_users_and_organizations.rb'
|
||||||
|
- 'db/migrate/20171213000001_change_authorization_token_size.rb'
|
||||||
|
- 'db/migrate/20180128000001_chat_add_ip_country.rb'
|
||||||
|
- 'db/migrate/20180709020509_add_group_direction_to_overviews.rb'
|
||||||
|
- 'db/migrate/20180719033247_add_confidential_to_doorkeeper_application.rb'
|
||||||
|
- 'db/migrate/20180809000001_cti_generic_api.rb'
|
||||||
|
- 'db/migrate/20181017000001_cti_generic_api2.rb'
|
||||||
|
- 'db/migrate/20190409000001_setting_ticket_overview_priority_icon_and_color.rb'
|
||||||
|
- 'db/migrate/20190531180304_initialize_knowledge_base.rb'
|
||||||
|
- 'db/migrate/20190713000001_group_dependent_macros.rb'
|
||||||
|
- 'db/migrate/20190717210244_issue_2641_kb_color_change_limit.rb'
|
||||||
|
- 'db/migrate/20190724000001_rename_reserved_words.rb'
|
||||||
|
- 'db/migrate/20190918114553_issue_2867_footer_header_public_link.rb'
|
||||||
|
- 'db/migrate/20191001090809_create_active_job_locks.rb'
|
||||||
|
- 'db/migrate/20200121000001_smime_support.rb'
|
||||||
|
- 'db/migrate/20200205000001_chat_add_allow_website.rb'
|
||||||
|
- 'db/migrate/20200707000001_data_privacy_init.rb'
|
||||||
|
- 'db/migrate/20200911070327_data_privacy_delete_name.rb'
|
||||||
|
- 'db/migrate/20201002094932_datetime_precision.rb'
|
||||||
|
- 'db/migrate/20201006131231_stats_store_polymorphic_association.rb'
|
||||||
|
|
Loading…
Reference in a new issue