Commit 1aa78d23 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '353381-fj-remove-obsolete-wiki-notes' into 'master'

Remove obsolete wiki notes

See merge request gitlab-org/gitlab!83391
parents 0b38a141 db2aab7a
# frozen_string_literal: true
class RemoveWikiNotes < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
class Note < ApplicationRecord
self.table_name = 'notes'
self.inheritance_column = :_type_disabled
end
def up
return unless Gitlab.dev_or_test_env? || Gitlab.staging? || Gitlab.com?
Note.where(noteable_type: 'Wiki', id: [97, 98, 110, 242, 272]).delete_all
end
def down
# NO-OP
end
end
09722b398f82651c433f6b05962827351e6e7c0841f2a6414feb206bb831e523
\ No newline at end of file
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe RemoveWikiNotes, :migration do
let(:notes) { table(:notes) }
it 'removes all wiki notes' do
notes.create!(id: 97, note: 'Wiki note', noteable_type: 'Wiki')
notes.create!(id: 98, note: 'Commit note', noteable_type: 'Commit')
notes.create!(id: 110, note: 'Issue note', noteable_type: 'Issue')
notes.create!(id: 242, note: 'MergeRequest note', noteable_type: 'MergeRequest')
expect(notes.where(noteable_type: 'Wiki').size).to eq(1)
expect { migrate! }.to change { notes.count }.by(-1)
expect(notes.where(noteable_type: 'Wiki').size).to eq(0)
end
context 'when not staging nor com' do
it 'does not remove notes' do
allow(::Gitlab).to receive(:com?).and_return(false)
allow(::Gitlab).to receive(:dev_or_test_env?).and_return(false)
allow(::Gitlab).to receive(:staging?).and_return(false)
notes.create!(id: 97, note: 'Wiki note', noteable_type: 'Wiki')
expect { migrate! }.not_to change { notes.count }
end
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