ファイル
btrc-hub/backend/db/migrate/20261005000000_repair_wiki_updated_at.rb
T
2026-10-05 01:22:54 +09:00

54 行
1.3 KiB
Ruby

class RepairWikiUpdatedAt < ActiveRecord::Migration[8.0]
class WikiPage < ActiveRecord::Base
self.table_name = 'wiki_pages'
end
class WikiVersion < ActiveRecord::Base
self.table_name = 'wiki_versions'
end
class TagDescription < ActiveRecord::Base
self.table_name = 'tag_descriptions'
end
class TagDescriptionVersion < ActiveRecord::Base
self.table_name = 'tag_description_versions'
end
def up
say_with_time 'Repairing wiki_pages.updated_at from wiki_versions' do
WikiPage.find_each do |page|
version =
WikiVersion
.where(wiki_page_id: page.id)
.order(version_no: :desc)
.first
next unless version
page.update_columns(updated_at: version.created_at)
end
end
say_with_time 'Repairing tag_descriptions.updated_at from tag_description_versions' do
TagDescription.find_each do |description|
version =
TagDescriptionVersion
.where(
tag_id: description.tag_id,
language_code: description.language_code)
.order(version_no: :desc)
.first
next unless version
description.update_columns(updated_at: version.created_at)
end
end
end
def down
;
end
end