2016-08-24 12:49:21 +05:30
|
|
|
module RuboCop
|
|
|
|
# Module containing helper methods for writing migration cops.
|
|
|
|
module MigrationHelpers
|
2020-04-22 19:07:51 +05:30
|
|
|
WHITELISTED_TABLES = %i[
|
|
|
|
application_settings
|
|
|
|
plan_limits
|
|
|
|
].freeze
|
|
|
|
|
|
|
|
# Blacklisted tables due to:
|
|
|
|
# - size in GB (>= 10 GB on GitLab.com as of 02/2020)
|
|
|
|
# - number of records
|
|
|
|
BLACKLISTED_TABLES = %i[
|
|
|
|
audit_events
|
|
|
|
ci_build_trace_sections
|
|
|
|
ci_builds
|
|
|
|
ci_builds_metadata
|
|
|
|
ci_job_artifacts
|
|
|
|
ci_pipeline_variables
|
|
|
|
ci_pipelines
|
|
|
|
ci_stages
|
|
|
|
deployments
|
|
|
|
events
|
|
|
|
issues
|
|
|
|
merge_request_diff_commits
|
|
|
|
merge_request_diff_files
|
|
|
|
merge_request_diffs
|
|
|
|
merge_request_metrics
|
|
|
|
merge_requests
|
|
|
|
namespaces
|
|
|
|
note_diff_files
|
|
|
|
notes
|
|
|
|
project_authorizations
|
|
|
|
projects
|
|
|
|
project_ci_cd_settings
|
|
|
|
project_features
|
|
|
|
push_event_payloads
|
|
|
|
resource_label_events
|
|
|
|
routes
|
|
|
|
sent_notifications
|
|
|
|
services
|
|
|
|
system_note_metadata
|
|
|
|
taggings
|
|
|
|
todos
|
|
|
|
users
|
|
|
|
web_hook_logs
|
|
|
|
].freeze
|
|
|
|
|
|
|
|
# Blacklisted tables due to:
|
|
|
|
# - number of columns (> 50 on GitLab.com as of 03/2020)
|
|
|
|
# - number of records
|
|
|
|
WIDE_TABLES = %i[
|
|
|
|
users
|
|
|
|
projects
|
|
|
|
ci_builds
|
|
|
|
].freeze
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
# Returns true if the given node originated from the db/migrate directory.
|
|
|
|
def in_migration?(node)
|
2019-12-21 20:55:43 +05:30
|
|
|
dirname(node).end_with?('db/migrate', 'db/geo/migrate') || in_post_deployment_migration?(node)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def in_post_deployment_migration?(node)
|
2019-12-21 20:55:43 +05:30
|
|
|
dirname(node).end_with?('db/post_migrate', 'db/geo/post_migrate')
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def version(node)
|
|
|
|
File.basename(node.location.expression.source_buffer.name).split('_').first.to_i
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
private
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def dirname(node)
|
|
|
|
File.dirname(node.location.expression.source_buffer.name)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|