scinote-web/db/migrate/20190903145834_convert_activities_json_to_jsonb.rb
2019-11-18 13:59:54 +01:00

15 lines
463 B
Ruby

# frozen_string_literal: true
class ConvertActivitiesJsonToJsonb < ActiveRecord::Migration[5.2]
def change
change_column :activities, :values, 'jsonb USING CAST(values AS jsonb)'
ActiveRecord::Base.connection.execute("
UPDATE activities SET
values = REGEXP_REPLACE(
REGEXP_REPLACE(
REGEXP_REPLACE(values::text, '\\\\\"', '\"', 'g'),
'^\"||\"$', '', 'g'),
'\\\\\\\\', '\\\\', 'g')::jsonb
")
end
end