Add: kmyblueから本家の引用への変換コード

This commit is contained in:
KMY 2025-05-07 13:04:24 +09:00
parent 35386bd054
commit acc662e490
4 changed files with 70 additions and 27 deletions

View file

@ -5,34 +5,33 @@
# Table name: statuses
#
# id :bigint(8) not null, primary key
# uri :string
# text :text default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# in_reply_to_id :bigint(8)
# reblog_of_id :bigint(8)
# url :string
# sensitive :boolean default(FALSE), not null
# visibility :integer default("public"), not null
# spoiler_text :text default(""), not null
# reply :boolean default(FALSE), not null
# language :string
# conversation_id :bigint(8)
# local :boolean
# account_id :bigint(8) not null
# application_id :bigint(8)
# in_reply_to_account_id :bigint(8)
# poll_id :bigint(8)
# deleted_at :datetime
# edited_at :datetime
# trendable :boolean
# ordered_media_attachment_ids :bigint(8) is an Array
# searchability :integer
# markdown :boolean default(FALSE)
# limited_scope :integer
# quote_of_id :bigint(8)
# fetched_replies_at :datetime
# language :string
# limited_scope :integer
# local :boolean
# markdown :boolean default(FALSE)
# ordered_media_attachment_ids :bigint(8) is an Array
# quote_approval_policy :integer default(0), not null
# reply :boolean default(FALSE), not null
# searchability :integer
# sensitive :boolean default(FALSE), not null
# spoiler_text :text default(""), not null
# text :text default(""), not null
# trendable :boolean
# uri :string
# url :string
# visibility :integer default("public"), not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint(8) not null
# application_id :bigint(8)
# conversation_id :bigint(8)
# in_reply_to_account_id :bigint(8)
# in_reply_to_id :bigint(8)
# poll_id :bigint(8)
# reblog_of_id :bigint(8)
#
require 'ostruct'

View file

@ -0,0 +1,37 @@
# frozen_string_literal: true
class MigrateKmyblueQuotes < ActiveRecord::Migration[8.0]
class Status < ApplicationRecord; end
class Quote < ApplicationRecord; end
def up
Status.where.not(quote_of_id: nil).select(:id, :quote_of_id, :account_id).in_batches do |owner_statuses|
quoted_statuses = Status.where(id: owner_statuses.pluck(:quote_of_id)).select(:id, :account_id)
owner_statuses.each do |owner_status|
quoted_status = quoted_statuses.detect { |status| status.id == owner_status.quote_of_id }
next unless quoted_status
Quote.create!(
status_id: owner_status.id,
quoted_status_id: owner_status.quote_of_id,
state: 1,
account_id: owner_status.account_id,
quoted_account_id: quoted_status.account_id
)
end
end
end
def down
Quote.select(:quoted_status_id, :status_id).in_batches do |quotes|
statuses = Status.where(id: quotes.pluck(:status_id))
quotes.each do |quote|
status = statuses.detect { |s| s.id == quote.status_id }
next unless status
status.update!(quote_of_id: quote.quoted_status_id)
end
end
end
end

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class RemoveQuoteOfIdFromStatuses < ActiveRecord::Migration[8.0]
def change
safety_assured do
remove_column :statuses, :quote_of_id, :bigint, default: nil, null: true
end
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_04_28_095029) do
ActiveRecord::Schema[8.0].define(version: 2025_05_07_035927) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
@ -1449,7 +1449,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_04_28_095029) do
t.integer "searchability"
t.boolean "markdown", default: false
t.integer "limited_scope"
t.bigint "quote_of_id"
t.datetime "fetched_replies_at"
t.integer "quote_approval_policy", default: 0, null: false
t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20190820", order: { id: :desc }, where: "(deleted_at IS NULL)"
@ -1461,7 +1460,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_04_28_095029) do
t.index ["id", "language", "account_id"], name: "index_statuses_public_20250210", order: { id: :desc }, where: "((deleted_at IS NULL) AND (visibility = ANY (ARRAY[0, 10, 11])) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))"
t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id", where: "(in_reply_to_account_id IS NOT NULL)"
t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id", where: "(in_reply_to_id IS NOT NULL)"
t.index ["quote_of_id", "account_id"], name: "index_statuses_on_quote_of_id_and_account_id"
t.index ["reblog_of_id", "account_id"], name: "index_statuses_on_reblog_of_id_and_account_id"
t.index ["uri"], name: "index_statuses_on_uri", unique: true, opclass: :text_pattern_ops, where: "(uri IS NOT NULL)"
t.index ["url"], name: "index_statuses_on_url", opclass: :text_pattern_ops, where: "((url IS NOT NULL) AND ((url)::text <> (uri)::text))"