Script to migrate comments to new URL scheme

This commit is contained in:
Jorge Manrubia
2025-09-10 12:24:15 +02:00
parent 4b1f27057c
commit f4ad6800f3
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
require_relative "../config/environment"
def replace_url(string)
string.gsub(%r{/collections/\d+/cards/(\d+)}) do
"/cards/#{$1}"
end
end
def fix_rich_text(rich_text)
original_html = rich_text.body_before_type_cast
new_html = replace_url(original_html)
if original_html != new_html
rich_text.update_columns(body: new_html)
end
end
ApplicationRecord.with_each_tenant do
ActionText::RichText.where(record_type: "Card", name: "description").find_each do |rich_text|
fix_rich_text rich_text
end
ActionText::RichText.where(record_type: "Comment", name: "body").find_each do |rich_text|
fix_rich_text rich_text
end
end