Commit 79cc73c6 authored by Chantal Rollison's avatar Chantal Rollison

Add migration to remove commas from prior weight notes

parent aa05be53
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180529093006) do ActiveRecord::Schema.define(version: 20180530201303) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
......
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class RemoveCommasFromWeightNote < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
ActiveRecord::Base.connection.execute(<<-EOQ)
UPDATE notes
SET notes.note = SUBSTRING(notes.note, 1, LEN(notes.note) - 1)
FROM system_note_metadata
WHERE system_note_metadata.note_id = notes.id AND notes.system AND system_note_metadata.action = 'weight' AND notes.note LIKE '%,'
EOQ
end
def down
old_notes = Note.where("note LIKE 'changed weight to%'")
old_notes.find_each do |note|
note.update_column(:note, note.note.concat(','))
end
end
end
require 'spec_helper'
require Rails.root.join('ee', 'db', 'migrate', '../../db/migrate/20180530201303_remove_commas_from_weight_note.rb')
describe RemoveCommasFromWeightNote, :migration do
let(:migration) { described_class.new }
describe '#up' do
let(:notes) {table(:notes)}
let!(:note_1) {notes.create(note: 'changed weight to 5,')}
let!(:note_2) {notes.create(note: 'removed the weight')}
it 'removes all trailing commas' do
expect { migrate! }.to change { Note.where("note LIKE '%,'").count }.from(1).to(0)
end
end
describe '#down' do
let(:notes) {table(:notes)}
let!(:note_1) {notes.create(note: 'changed weight to 5')}
let!(:note_2) {notes.create(note: 'removed the weight')}
it 'adds trailing commas' do
expect { migration.down }.to change { Note.where("note LIKE '%,'").count }.from(0).to(1)
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