Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/database/schema_validation/track_inconsistency.rb')
-rw-r--r--lib/gitlab/database/schema_validation/track_inconsistency.rb138
1 files changed, 0 insertions, 138 deletions
diff --git a/lib/gitlab/database/schema_validation/track_inconsistency.rb b/lib/gitlab/database/schema_validation/track_inconsistency.rb
deleted file mode 100644
index 6e167653d32..00000000000
--- a/lib/gitlab/database/schema_validation/track_inconsistency.rb
+++ /dev/null
@@ -1,138 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module Database
- module SchemaValidation
- class TrackInconsistency
- COLUMN_TEXT_LIMIT = 6144
-
- def initialize(inconsistency, project, user)
- @inconsistency = inconsistency
- @project = project
- @user = user
- end
-
- def execute
- return unless Gitlab.com?
- return refresh_issue if inconsistency_record.present?
-
- result = ::Issues::CreateService.new(
- container: project,
- current_user: user,
- params: params,
- perform_spam_check: false).execute
-
- track_inconsistency(result[:issue]) if result.success?
- end
-
- private
-
- attr_reader :inconsistency, :project, :user
-
- def track_inconsistency(issue)
- schema_inconsistency_model.create!(
- issue: issue,
- object_name: inconsistency.object_name,
- table_name: inconsistency.table_name,
- valitador_name: inconsistency.type,
- diff: inconsistency_diff
- )
- end
-
- def params
- {
- title: issue_title,
- description: description,
- issue_type: 'issue',
- labels: default_labels + group_labels
- }
- end
-
- def issue_title
- "New schema inconsistency: #{inconsistency.object_name}"
- end
-
- def description
- <<~MSG
- We have detected a new schema inconsistency.
-
- **Table name:** #{inconsistency.table_name}\
- **Object name:** #{inconsistency.object_name}\
- **Validator name:** #{inconsistency.type}\
- **Object type:** #{inconsistency.object_type}\
- **Error message:** #{inconsistency.error_message}
-
-
- **Structure.sql statement:**
-
- ```sql
- #{inconsistency.structure_sql_statement}
- ```
-
- **Database statement:**
-
- ```sql
- #{inconsistency.database_statement}
- ```
-
- **Diff:**
-
- ```diff
- #{inconsistency.diff}
-
- ```
-
-
- For more information, please contact the database team.
- MSG
- end
-
- def group_labels
- dictionary = YAML.safe_load(File.read(table_file_path))
-
- dictionary['feature_categories'].to_a.filter_map do |feature_category|
- Gitlab::Database::ConvertFeatureCategoryToGroupLabel.new(feature_category).execute
- end
- rescue Errno::ENOENT
- []
- end
-
- def default_labels
- %w[database database-inconsistency-report type::maintenance severity::4]
- end
-
- def table_file_path
- Rails.root.join(Gitlab::Database::GitlabSchema.dictionary_paths.first, "#{inconsistency.table_name}.yml")
- end
-
- def schema_inconsistency_model
- Gitlab::Database::SchemaValidation::SchemaInconsistency
- end
-
- def refresh_issue
- return if inconsistency_diff == inconsistency_record.diff # Nothing to refresh
-
- note = ::Notes::CreateService.new(
- inconsistency_record.issue.project,
- user,
- { noteable_type: 'Issue', noteable: inconsistency_record.issue, note: description }
- ).execute
-
- inconsistency_record.update!(diff: inconsistency_diff) if note.persisted?
- end
-
- def inconsistency_diff
- @inconsistency_diff ||= inconsistency.diff.to_s.first(COLUMN_TEXT_LIMIT)
- end
-
- def inconsistency_record
- @inconsistency_record ||= schema_inconsistency_model.with_open_issues.find_by(
- object_name: inconsistency.object_name,
- table_name: inconsistency.table_name,
- valitador_name: inconsistency.type
- )
- end
- end
- end
- end
-end