Commit 8bac6e41 authored by Lin Jen-Shin (godfat)'s avatar Lin Jen-Shin (godfat) Committed by Rémy Coutable

Fix notes type created from import

parent ccfe6860
---
title: Fix notes type created from import. This should fix some missing notes issues
from imported projects
merge_request: 14524
author:
type: fixed
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
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
require_relative 'error' require_relative 'error'
require_relative 'import/issue'
require_relative 'import/legacy_diff_note'
require_relative 'import/merge_request'
require_relative 'import/note'
module Github module Github
class Import class Import
include Gitlab::ShellAdapter 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, attr_reader :project, :repository, :repo, :repo_url, :wiki_url,
:options, :errors, :cached, :verbose :options, :errors, :cached, :verbose
......
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
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
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
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
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
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
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
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment