diff --git a/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb b/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb new file mode 100644 index 000000000..188e017a5 --- /dev/null +++ b/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb @@ -0,0 +1,30 @@ +class ModifyMdAttachmentUrlForMdCotents < ActiveRecord::Migration[5.2] + def change + # 更新MarkDown图片的URL + homework_commons = HomeworkCommon.all + homework_commons.find_each do |hc| + hc.update_column(:description, hc.description.gsub("![](/attachments/download", "![](/api/attachments")) if hc.description.present? + end + + challenges = Challenge.all.unscoped + challenges.find_each do |c| + c.update_column(:task_pass, c.task_pass.gsub("![](/attachments/download", "![](/api/attachments")) if c.task_pass.present? + end + + challenge_answers = ChallengeAnswer.all.unscoped + challenge_answers.find_each do |ca| + ca.update_column(:contents, ca.contents.gsub("![](/attachments/download", "![](/api/attachments")) if ca.contents.present? + end + + shixun_infos = ShixunInfo.all + shixun_infos.find_each do |si| + si.update_column(:propaedeutics, si.propaedeutics.gsub("![](/attachments/download", "![](/api/attachments")) if si.propaedeutics.present? + si.update_column(:description, si.description.gsub("![](/attachments/download", "![](/api/attachments")) if si.description.present? + end + + subjects = Subject.all + subjects.find_each do |s| + s.update_column(:description, s.description.gsub("![](/attachments/download", "![](/api/attachments")) if s.description.present? + end + end +end