diff --git a/app/models/status.rb b/app/models/status.rb index 96a26b35e1..b5c6fe95e1 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -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' diff --git a/db/migrate/20250507033006_migrate_kmyblue_quotes.rb b/db/migrate/20250507033006_migrate_kmyblue_quotes.rb new file mode 100644 index 0000000000..cc23b0e650 --- /dev/null +++ b/db/migrate/20250507033006_migrate_kmyblue_quotes.rb @@ -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 diff --git a/db/post_migrate/20250507035927_remove_quote_of_id_from_statuses.rb b/db/post_migrate/20250507035927_remove_quote_of_id_from_statuses.rb new file mode 100644 index 0000000000..3794cb5e75 --- /dev/null +++ b/db/post_migrate/20250507035927_remove_quote_of_id_from_statuses.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index b7bcce86e7..60535936b3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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))"