Fix notes type created from import
This commit is contained in:
parent
ccfe686007
commit
8bac6e41ef
12 changed files with 155 additions and 37 deletions
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
13
lib/github/import/issue.rb
Normal file
13
lib/github/import/issue.rb
Normal file
|
@ -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
|
12
lib/github/import/legacy_diff_note.rb
Normal file
12
lib/github/import/legacy_diff_note.rb
Normal file
|
@ -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
|
13
lib/github/import/merge_request.rb
Normal file
13
lib/github/import/merge_request.rb
Normal file
|
@ -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
|
13
lib/github/import/note.rb
Normal file
13
lib/github/import/note.rb
Normal file
|
@ -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
|
9
spec/lib/github/import/legacy_diff_note_spec.rb
Normal file
9
spec/lib/github/import/legacy_diff_note_spec.rb
Normal file
|
@ -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
|
9
spec/lib/github/import/note_spec.rb
Normal file
9
spec/lib/github/import/note_spec.rb
Normal file
|
@ -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
|
|
@ -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
|
22
spec/migrations/update_notes_type_for_import_spec.rb
Normal file
22
spec/migrations/update_notes_type_for_import_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue