From 8bac6e41ef1568b5b46a92a2279b4fb488ae73bc Mon Sep 17 00:00:00 2001 From: "Lin Jen-Shin (godfat)" Date: Fri, 29 Sep 2017 11:18:58 +0000 Subject: [PATCH] Fix notes type created from import --- .../38432-fix-notes-type-for-import.yml | 6 +++ ...pdate_legacy_diff_notes_type_for_import.rb | 16 ++++++++ ...0927112319_update_notes_type_for_import.rb | 16 ++++++++ lib/github/import.rb | 41 ++----------------- lib/github/import/issue.rb | 13 ++++++ lib/github/import/legacy_diff_note.rb | 12 ++++++ lib/github/import/merge_request.rb | 13 ++++++ lib/github/import/note.rb | 13 ++++++ .../github/import/legacy_diff_note_spec.rb | 9 ++++ spec/lib/github/import/note_spec.rb | 9 ++++ ..._legacy_diff_notes_type_for_import_spec.rb | 22 ++++++++++ .../update_notes_type_for_import_spec.rb | 22 ++++++++++ 12 files changed, 155 insertions(+), 37 deletions(-) create mode 100644 changelogs/unreleased/38432-fix-notes-type-for-import.yml create mode 100644 db/post_migrate/20170927112318_update_legacy_diff_notes_type_for_import.rb create mode 100644 db/post_migrate/20170927112319_update_notes_type_for_import.rb create mode 100644 lib/github/import/issue.rb create mode 100644 lib/github/import/legacy_diff_note.rb create mode 100644 lib/github/import/merge_request.rb create mode 100644 lib/github/import/note.rb create mode 100644 spec/lib/github/import/legacy_diff_note_spec.rb create mode 100644 spec/lib/github/import/note_spec.rb create mode 100644 spec/migrations/update_legacy_diff_notes_type_for_import_spec.rb create mode 100644 spec/migrations/update_notes_type_for_import_spec.rb diff --git a/changelogs/unreleased/38432-fix-notes-type-for-import.yml b/changelogs/unreleased/38432-fix-notes-type-for-import.yml new file mode 100644 index 00000000000..db8371f4420 --- /dev/null +++ b/changelogs/unreleased/38432-fix-notes-type-for-import.yml @@ -0,0 +1,6 @@ +--- +title: Fix notes type created from import. This should fix some missing notes issues + from imported projects +merge_request: 14524 +author: +type: fixed diff --git a/db/post_migrate/20170927112318_update_legacy_diff_notes_type_for_import.rb b/db/post_migrate/20170927112318_update_legacy_diff_notes_type_for_import.rb new file mode 100644 index 00000000000..a238216253b --- /dev/null +++ b/db/post_migrate/20170927112318_update_legacy_diff_notes_type_for_import.rb @@ -0,0 +1,16 @@ +class UpdateLegacyDiffNotesTypeForImport < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + update_column_in_batches(:notes, :type, 'LegacyDiffNote') do |table, query| + query.where(table[:type].eq('Github::Import::LegacyDiffNote')) + end + end + + def down + end +end diff --git a/db/post_migrate/20170927112319_update_notes_type_for_import.rb b/db/post_migrate/20170927112319_update_notes_type_for_import.rb new file mode 100644 index 00000000000..1e70acd9868 --- /dev/null +++ b/db/post_migrate/20170927112319_update_notes_type_for_import.rb @@ -0,0 +1,16 @@ +class UpdateNotesTypeForImport < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + update_column_in_batches(:notes, :type, 'Note') do |table, query| + query.where(table[:type].eq('Github::Import::Note')) + end + end + + def down + end +end diff --git a/lib/github/import.rb b/lib/github/import.rb index f5f62dc8b6f..c0cd8382875 100644 --- a/lib/github/import.rb +++ b/lib/github/import.rb @@ -1,46 +1,13 @@ require_relative 'error' +require_relative 'import/issue' +require_relative 'import/legacy_diff_note' +require_relative 'import/merge_request' +require_relative 'import/note' module Github class Import include Gitlab::ShellAdapter - class MergeRequest < ::MergeRequest - self.table_name = 'merge_requests' - - self.reset_callbacks :create - self.reset_callbacks :save - self.reset_callbacks :commit - self.reset_callbacks :update - self.reset_callbacks :validate - end - - class Issue < ::Issue - self.table_name = 'issues' - - self.reset_callbacks :save - self.reset_callbacks :create - self.reset_callbacks :commit - self.reset_callbacks :update - self.reset_callbacks :validate - end - - class Note < ::Note - self.table_name = 'notes' - - self.reset_callbacks :save - self.reset_callbacks :commit - self.reset_callbacks :update - self.reset_callbacks :validate - end - - class LegacyDiffNote < ::LegacyDiffNote - self.table_name = 'notes' - - self.reset_callbacks :commit - self.reset_callbacks :update - self.reset_callbacks :validate - end - attr_reader :project, :repository, :repo, :repo_url, :wiki_url, :options, :errors, :cached, :verbose diff --git a/lib/github/import/issue.rb b/lib/github/import/issue.rb new file mode 100644 index 00000000000..171f0872666 --- /dev/null +++ b/lib/github/import/issue.rb @@ -0,0 +1,13 @@ +module Github + class Import + class Issue < ::Issue + self.table_name = 'issues' + + self.reset_callbacks :save + self.reset_callbacks :create + self.reset_callbacks :commit + self.reset_callbacks :update + self.reset_callbacks :validate + end + end +end diff --git a/lib/github/import/legacy_diff_note.rb b/lib/github/import/legacy_diff_note.rb new file mode 100644 index 00000000000..18adff560b6 --- /dev/null +++ b/lib/github/import/legacy_diff_note.rb @@ -0,0 +1,12 @@ +module Github + class Import + class LegacyDiffNote < ::LegacyDiffNote + self.table_name = 'notes' + self.store_full_sti_class = false + + self.reset_callbacks :commit + self.reset_callbacks :update + self.reset_callbacks :validate + end + end +end diff --git a/lib/github/import/merge_request.rb b/lib/github/import/merge_request.rb new file mode 100644 index 00000000000..c258e5d5e0e --- /dev/null +++ b/lib/github/import/merge_request.rb @@ -0,0 +1,13 @@ +module Github + class Import + class MergeRequest < ::MergeRequest + self.table_name = 'merge_requests' + + self.reset_callbacks :create + self.reset_callbacks :save + self.reset_callbacks :commit + self.reset_callbacks :update + self.reset_callbacks :validate + end + end +end diff --git a/lib/github/import/note.rb b/lib/github/import/note.rb new file mode 100644 index 00000000000..8cf4f30e6b7 --- /dev/null +++ b/lib/github/import/note.rb @@ -0,0 +1,13 @@ +module Github + class Import + class Note < ::Note + self.table_name = 'notes' + self.store_full_sti_class = false + + self.reset_callbacks :save + self.reset_callbacks :commit + self.reset_callbacks :update + self.reset_callbacks :validate + end + end +end diff --git a/spec/lib/github/import/legacy_diff_note_spec.rb b/spec/lib/github/import/legacy_diff_note_spec.rb new file mode 100644 index 00000000000..8c50b46cacb --- /dev/null +++ b/spec/lib/github/import/legacy_diff_note_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe Github::Import::LegacyDiffNote do + describe '#type' do + it 'returns the original note type' do + expect(described_class.new.type).to eq('LegacyDiffNote') + end + end +end diff --git a/spec/lib/github/import/note_spec.rb b/spec/lib/github/import/note_spec.rb new file mode 100644 index 00000000000..fcdccd9e097 --- /dev/null +++ b/spec/lib/github/import/note_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe Github::Import::Note do + describe '#type' do + it 'returns the original note type' do + expect(described_class.new.type).to eq('Note') + end + end +end diff --git a/spec/migrations/update_legacy_diff_notes_type_for_import_spec.rb b/spec/migrations/update_legacy_diff_notes_type_for_import_spec.rb new file mode 100644 index 00000000000..d625b60ff50 --- /dev/null +++ b/spec/migrations/update_legacy_diff_notes_type_for_import_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20170927112318_update_legacy_diff_notes_type_for_import.rb') + +describe UpdateLegacyDiffNotesTypeForImport, :migration do + let(:notes) { table(:notes) } + + before do + notes.inheritance_column = nil + + notes.create(type: 'Note') + notes.create(type: 'LegacyDiffNote') + notes.create(type: 'Github::Import::Note') + notes.create(type: 'Github::Import::LegacyDiffNote') + end + + it 'updates the notes type' do + migrate! + + expect(notes.pluck(:type)) + .to contain_exactly('Note', 'Github::Import::Note', 'LegacyDiffNote', 'LegacyDiffNote') + end +end diff --git a/spec/migrations/update_notes_type_for_import_spec.rb b/spec/migrations/update_notes_type_for_import_spec.rb new file mode 100644 index 00000000000..06195d970d8 --- /dev/null +++ b/spec/migrations/update_notes_type_for_import_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20170927112319_update_notes_type_for_import.rb') + +describe UpdateNotesTypeForImport, :migration do + let(:notes) { table(:notes) } + + before do + notes.inheritance_column = nil + + notes.create(type: 'Note') + notes.create(type: 'LegacyDiffNote') + notes.create(type: 'Github::Import::Note') + notes.create(type: 'Github::Import::LegacyDiffNote') + end + + it 'updates the notes type' do + migrate! + + expect(notes.pluck(:type)) + .to contain_exactly('Note', 'Note', 'LegacyDiffNote', 'Github::Import::LegacyDiffNote') + end +end