Merge remote-tracking branch 'upstream/stable-4.7', removing Mastodon-Modern folder.

This commit is contained in:
Tarrien committed 2026-11-06 04:33:35 -05:00
commit 8eabb7ea31
959 files changed
+29430 -9565

No files matched your search

@@ -3,7 +3,7 @@
class CreateGeneratedAnnualReports < ActiveRecord::Migration[7.1]
def change
create_table :generated_annual_reports do |t|
t.belongs_to :account, null: false, foreign_key: { on_cascade: :delete }, index: false
t.belongs_to :account, null: false, foreign_key: true, index: false
t.integer :year, null: false
t.jsonb :data, null: false
t.integer :schema_version, null: false
@@ -0,0 +1,8 @@
# frozen_string_literal: true
class AddRecordedChangesToActionLogs < ActiveRecord::Migration[8.1]
def change
add_column :admin_action_logs, :recorded_changes, :jsonb, null: true, default: nil
add_column :admin_action_logs, :recorded_changes_format, :string, null: true
end
end
@@ -0,0 +1,7 @@
# frozen_string_literal: true
class ChangeKeypairUriNonNullable < ActiveRecord::Migration[8.1]
def change
change_column_null :keypairs, :uri, true
end
end
@@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddLocalFragmentToKeypair < ActiveRecord::Migration[8.1]
def change
add_column :keypairs, :local_fragment, :string, null: true
end
end
@@ -0,0 +1,15 @@
# frozen_string_literal: true
class AddIndexAccountIdLocalFragmentToKeypair < ActiveRecord::Migration[8.1]
disable_ddl_transaction!
def up
add_index :keypairs, [:account_id, :local_fragment], unique: true, where: 'local_fragment IS NOT NULL', algorithm: :concurrently
rescue ActiveRecord::StatementInvalid
safety_assured { execute 'REINDEX INDEX CONCURRENTLY index_keypairs_on_account_id_and_local_fragment' }
end
def down
remove_index :keypairs, name: :index_keypairs_on_account_id_and_local_fragment
end
end
@@ -0,0 +1,13 @@
# frozen_string_literal: true
class RevertAddNewIndexOnUriToKeypairs < ActiveRecord::Migration[8.1]
disable_ddl_transaction!
def up
return unless index_exists?(:keypairs, :uri, name: :index_keypairs_on_non_null_uri)
remove_index :keypairs, :uri, name: :index_keypairs_on_non_null_uri
end
def down; end
end
@@ -0,0 +1,13 @@
# frozen_string_literal: true
class RevertRemoveOldIndexOnUriFromKeypair < ActiveRecord::Migration[8.1]
disable_ddl_transaction!
def up
return if index_exists?(:keypairs, :uri, name: :index_keypairs_on_uri)
add_index :keypairs, :uri, name: :index_keypairs_on_uri, unique: true, algorithm: :concurrently
end
def down; end
end
@@ -0,0 +1,7 @@
# frozen_string_literal: true
class RenameIndexAccountIdLocalFragmentToKeypair < ActiveRecord::Migration[8.1]
def change
rename_index :keypairs, 'index_keypairs_on_account_id_and_local_fragment', 'old_index_keypairs_on_account_id_and_local_fragment'
end
end
@@ -0,0 +1,15 @@
# frozen_string_literal: true
class AddNewIndexAccountIdLocalFragmentToKeypair < ActiveRecord::Migration[8.1]
disable_ddl_transaction!
def up
add_index :keypairs, [:account_id, :local_fragment], unique: true, name: :index_keypairs_on_account_id_and_local_fragment, algorithm: :concurrently
rescue ActiveRecord::StatementInvalid
safety_assured { execute 'REINDEX INDEX CONCURRENTLY index_keypairs_on_account_id_and_local_fragment' }
end
def down
remove_index :keypairs, name: :index_keypairs_on_account_id_and_local_fragment
end
end
@@ -0,0 +1,9 @@
# frozen_string_literal: true
class RemoveOldIndexAccountIdLocalFragmentToKeypair < ActiveRecord::Migration[8.1]
disable_ddl_transaction!
def change
remove_index :keypairs, [:account_id, :local_fragment], name: :old_index_keypairs_on_account_id_and_local_fragment, unique: true, where: 'local_fragment IS NOT NULL', algorithm: :concurrently
end
end
@@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddEndOfSupportToSoftwareUpdates < ActiveRecord::Migration[8.1]
def change
add_column :software_updates, :end_of_support, :date
end
end
@@ -0,0 +1,15 @@
# frozen_string_literal: true
class CreateSoftwareDeprecations < ActiveRecord::Migration[8.1]
def change
create_table :software_deprecations do |t|
t.string :branch, null: false
t.date :end_of_support, null: false
t.integer :warning_issued, null: false
t.timestamps
end
add_index :software_deprecations, :branch, unique: true
end
end
@@ -0,0 +1,19 @@
# frozen_string_literal: true
class ChangeAccountUriNullable < ActiveRecord::Migration[8.1]
disable_ddl_transaction!
class Account < ApplicationRecord; end
def up
change_column_null :accounts, :uri, true
end
def down
change_column_null :accounts, :uri, false
rescue ActiveRecord::NotNullViolation
Account.where(uri: nil).update_all(uri: '')
retry
end
end
@@ -0,0 +1,7 @@
# frozen_string_literal: true
class ChangeAccountUriDefault < ActiveRecord::Migration[8.1]
def change
change_column_default :accounts, :uri, from: '', to: nil
end
end
@@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddRequestedDeletionAtToAccounts < ActiveRecord::Migration[8.0]
def change
add_column :accounts, :requested_deletion_at, :datetime
end
end
@@ -0,0 +1,41 @@
# frozen_string_literal: true
class UpdateAccountSummariesToVersion3 < ActiveRecord::Migration[8.0]
def up
# First, create a temporary `account_summaries` and populate it.
# This is the most expensive part.
create_view :tmp_account_summaries,
sql_definition: Scenic::Definition.new(:account_summaries, 3).to_sql,
materialized: true
rename_index :account_summaries, :index_account_summaries_on_account_id, :tmp_index_account_summaries_on_account_id
safety_assured { add_index :tmp_account_summaries, :account_id, name: :index_account_summaries_on_account_id, unique: true }
# Then, drop `global_follow_recommendations` and `account_summaries`
# Downtime starts here but should hopefuly be pretty short.
drop_view :global_follow_recommendations, materialized: true
drop_view :account_summaries, materialized: true
# Then rename `tmp_account_summaries` to `account_summaries`
safety_assured { execute('ALTER MATERIALIZED VIEW tmp_account_summaries RENAME TO account_summaries') }
# Then re-create `global_follow_recommendations`, populating it
create_view :global_follow_recommendations, version: 1, materialized: true
safety_assured { add_index :global_follow_recommendations, :account_id, unique: true }
end
def down
reapplication_global_follow_recommendations_v1 do
drop_view :account_summaries, materialized: true
create_view :account_summaries, version: 2, materialized: { no_data: true }
safety_assured { add_index :account_summaries, :account_id, unique: true }
end
end
def reapplication_global_follow_recommendations_v1
drop_view :global_follow_recommendations, materialized: true
yield
create_view :global_follow_recommendations, version: 1, materialized: { no_data: true }
safety_assured { add_index :global_follow_recommendations, :account_id, unique: true }
end
end
@@ -0,0 +1,9 @@
# frozen_string_literal: true
class AddBackLanguagesIndexToAccountSummaries < ActiveRecord::Migration[8.1]
disable_ddl_transaction!
def change
add_index :account_summaries, [:account_id, :language, :sensitive], algorithm: :concurrently
end
end
@@ -0,0 +1,9 @@
# frozen_string_literal: true
class AddTargetAccountIndexToFollowRequests < ActiveRecord::Migration[8.1]
disable_ddl_transaction!
def change
add_index :follow_requests, [:target_account_id, :account_id], algorithm: :concurrently
end
end
@@ -0,0 +1,15 @@
# frozen_string_literal: true
class FixGeneratedAnnualReportsForeignKey < ActiveRecord::Migration[8.1]
def up
safety_assured do
execute 'ALTER TABLE generated_annual_reports DROP CONSTRAINT fk_rails_4ca37f035c, ADD CONSTRAINT fk_rails_4ca37f035c FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE;'
end
end
def down
safety_assured do
execute 'ALTER TABLE generated_annual_reports DROP CONSTRAINT fk_rails_4ca37f035c, ADD CONSTRAINT fk_rails_4ca37f035c FOREIGN KEY (account_id) REFERENCES accounts(id);'
end
end
end
@@ -0,0 +1,9 @@
# frozen_string_literal: true
class RemoveIndexKeypairsOnAccountId < ActiveRecord::Migration[8.1]
disable_ddl_transaction!
def change
remove_index :keypairs, :account_id, algorithm: :concurrently
end
end
@@ -0,0 +1,64 @@
# frozen_string_literal: true
class MigrateLocalAccountKeypairs < ActiveRecord::Migration[8.1]
disable_ddl_transaction!
class Account < ApplicationRecord
has_many :keypairs, inverse_of: :account
scope :local, -> { where(domain: nil) }
end
class Keypair < ApplicationRecord
self.inheritance_column = nil
encrypts :private_key
belongs_to :account
enum :type, {
rsa: 0,
}, validate: true
end
def up
Account.reset_column_information
Keypair.reset_column_information
Account.local.where.not(private_key: nil).in_batches do |accounts|
Keypair.upsert_all(
accounts.map do |account|
{
type: :rsa,
account_id: account.id,
local_fragment: '#main-key',
public_key: account.public_key,
private_key: account.private_key,
}
end,
unique_by: [:account_id, :local_fragment]
)
accounts.update_all(public_key: '', private_key: nil)
end
Account.reset_column_information
Keypair.reset_column_information
end
def down
Account.reset_column_information
Keypair.reset_column_information
Account.local.where(private_key: nil).find_each do |account|
keypair = account.keypairs.find_by(local_fragment: '#main-key')
next if keypair.nil?
account.update(public_key: keypair.public_key, private_key: keypair.private_key)
keypair.delete
end
Account.reset_column_information
Keypair.reset_column_information
end
end
@@ -0,0 +1,14 @@
# frozen_string_literal: true
class FixBlankAccountUri < ActiveRecord::Migration[8.1]
# Dummy classes to make migration possible across version changes
class Account < ApplicationRecord; end
def up
Account.where(uri: '').in_batches.update_all(uri: nil)
end
def down
Account.where(uri: nil).in_batches.update_all(uri: '')
end
end
@@ -0,0 +1,7 @@
# frozen_string_literal: true
class RenameIndexAccountsOnUriToOld < ActiveRecord::Migration[8.1]
def change
rename_index :accounts, :index_accounts_on_uri, :old_index_accounts_on_uri
end
end
@@ -0,0 +1,114 @@
# frozen_string_literal: true
class AddUniqueIndexOnAccountsUri < ActiveRecord::Migration[8.1]
disable_ddl_transaction!
# Dummy classes to make migration possible across version changes
class Account < ApplicationRecord; end
class AccountDeletionRequest < ApplicationRecord; end
class AccountModerationNote < ApplicationRecord; end
class AccountNote < ApplicationRecord; end
class AccountPin < ApplicationRecord; end
class AccountStat < ApplicationRecord; end
class Appeal < ApplicationRecord; end
class Block < ApplicationRecord; end
class CanonicalEmailBlock < ApplicationRecord; end
class Collection < ApplicationRecord; end
class CollectionItem < ApplicationRecord; end
class Favourite < ApplicationRecord; end
class Follow < ApplicationRecord; end
class FollowRecommendationSuppression < ApplicationRecord; end
class FollowRequest < ApplicationRecord; end
class ListAccount < ApplicationRecord; end
class MediaAttachment < ApplicationRecord
self.inheritance_column = nil
end
class Mention < ApplicationRecord; end
class Mute < ApplicationRecord; end
class Notification < ApplicationRecord
self.inheritance_column = nil
end
class NotificationPermission < ApplicationRecord; end
class NotificationRequest < ApplicationRecord; end
class Poll < ApplicationRecord; end
class PollVote < ApplicationRecord; end
class Quote < ApplicationRecord; end
class Report < ApplicationRecord; end
class SeveredRelationship < ApplicationRecord; end
class Status < ApplicationRecord; end
class StatusPin < ApplicationRecord; end
class TagFollow < ApplicationRecord; end
class Tombstone < ApplicationRecord; end
def up
add_index :accounts, :uri, algorithm: :concurrently, unique: true
rescue ActiveRecord::RecordNotUnique
deduplicate_and_reindex!
rescue
remove_index :accounts, name: :index_accounts_on_uri
raise
end
def down
remove_index :accounts, name: :index_accounts_on_uri
end
private
def deduplicate_and_reindex!
deduplicate_accounts!
safety_assured { execute 'REINDEX INDEX CONCURRENTLY index_accounts_on_uri' }
rescue ActiveRecord::RecordNotUnique
retry
end
def deduplicate_accounts!
duplicate_uris = select_all('SELECT uri FROM accounts WHERE uri IS NOT NULL GROUP BY uri HAVING count(*) > 1').rows
duplicate_uris.each do |uri|
# Fetch the conflicting accounts and keep the most recently-discovered one as reference
duplicate_records = Account.where(uri: uri).reorder(Arel.sql("COALESCE(last_webfingered_at, 'epoch'::date)"), :created_at, :id).to_a
reference_account = duplicate_records.pop
duplicate_records.each do |other_account|
merge_accounts!(reference_account, other_account)
other_account.destroy
end
end
end
def merge_accounts!(account, other_account)
{
account_id: [
Status, StatusPin, MediaAttachment, Poll, Report, Tombstone, Favourite,
Follow, FollowRequest, Block, Mute,
AccountModerationNote, AccountPin, AccountStat, ListAccount,
PollVote, Mention, AccountDeletionRequest, AccountNote, FollowRecommendationSuppression,
Appeal, TagFollow, Quote, Collection, CollectionItem
],
from_account_id: [
Notification, NotificationPermission, NotificationRequest
],
target_account_id: [
Follow, FollowRequest, Block, Mute, AccountModerationNote, AccountPin, AccountNote
],
reference_account_id: [CanonicalEmailBlock],
local_account_id: [SeveredRelationship],
remote_account_id: [SeveredRelationship],
quoted_account_id: [Quote],
}.each do |attribute, classes|
classes.each do |klass|
klass.where({ attribute => other_account.id }).reorder(nil).find_each do |record|
record.update_attribute(attribute, account.id)
rescue ActiveRecord::RecordNotUnique
next
end
end
end
end
end
@@ -0,0 +1,9 @@
# frozen_string_literal: true
class RemoveOldIndexOnAccountsUri < ActiveRecord::Migration[8.1]
disable_ddl_transaction!
def change
remove_index :accounts, :uri, name: :old_index_accounts_on_uri, algorithm: :concurrently
end
end
@@ -0,0 +1,15 @@
# frozen_string_literal: true
class CleanUpInvalidAccounts < ActiveRecord::Migration[8.1]
# Dummy classes to make migration possible across version changes
class Account < ApplicationRecord; end
def up
# A very old bug could cause incompletely-processed remote accounts to be added
# to the database; those would not have a URI, which could be an issue in the
# future. Delete them.
Account.where.not(domain: nil).where(uri: nil).in_batches.delete_all
end
def down; end
end
@@ -0,0 +1,29 @@
# frozen_string_literal: true
class BackfillAccountRequestedDeletionAt < ActiveRecord::Migration[8.1]
def up
safety_assured do
execute <<~SQL
UPDATE
accounts
SET
requested_deletion_at = suspended_at, suspended_at = NULL, suspension_origin = NULL
WHERE
-- rule out remote accounts, as deleted remote accounts are deleted locally
domain IS NULL
-- only care about accounts marked as suspended (which prior to this migration applies to both suspended and self-deleted accounts)
AND suspended_at IS NOT NULL
-- rule accounts that were not self-deleted (might still include suspended but self-deleted accounts)
AND NOT EXISTS (SELECT 1 FROM users WHERE account_id = accounts.id) AND NOT EXISTS (SELECT 1 FROM canonical_email_blocks WHERE reference_account_id = accounts.id)
-- rule out accounts that have a canonical email block: sign they were suspended and not unsuspended
AND NOT EXISTS (SELECT 1 FROM canonical_email_blocks WHERE reference_account_id = accounts.id)
SQL
end
end
def down
safety_assured do
execute 'UPDATE accounts SET suspended_at = requested_deletion_at WHERE domain is NULL AND suspended_at IS NULL AND requested_deletion_at IS NOT NULL'
end
end
end
@@ -0,0 +1,58 @@
# frozen_string_literal: true
class ConvertMaterializedViewsToTables < ActiveRecord::Migration[8.1]
def up
# Prepare replacement of `account_summaries`
rename_index :account_summaries, :index_account_summaries_on_account_id, :tmp_index_account_summaries_on_account_id
rename_index :account_summaries, :idx_on_account_id_language_sensitive_250461e1eb, :tmp_idx_on_account_id_language_sensitive_250461e1eb
# Create replacement table for `account_summaries`
create_table :tmp_account_summaries, primary_key: :account_id do |t| # rubocop:disable Rails/CreateTableWithTimestamps
t.string :language
t.boolean :sensitive, default: false, null: false
end
safety_assured do # The table is empty, so blocking is minimal
add_foreign_key :tmp_account_summaries, :accounts, on_delete: :cascade
add_index :tmp_account_summaries, [:account_id, :language, :sensitive], name: :idx_on_account_id_language_sensitive_250461e1eb
end
# Create replacement table for `global_follow_recommendations`
rename_index :global_follow_recommendations, :index_global_follow_recommendations_on_account_id, :tmp_index_global_follow_recommendations_on_account_id
create_table :tmp_global_follow_recommendations, primary_key: :account_id do |t| # rubocop:disable Rails/CreateTableWithTimestamps
t.decimal :rank, null: false
t.string :reason, array: true, null: false
t.boolean :stale, null: false, default: false
end
safety_assured do # The table is empty, so blocking is minimal
add_foreign_key :tmp_global_follow_recommendations, :accounts, on_delete: :cascade
add_index :tmp_global_follow_recommendations, :rank, name: :index_global_follow_recommendations_on_rank
end
# Fill the tables
safety_assured do
execute 'INSERT INTO tmp_account_summaries SELECT account_summaries.* FROM account_summaries INNER JOIN accounts ON accounts.id = account_summaries.account_id' if Scenic.database.populated?('account_summaries')
execute 'INSERT INTO tmp_global_follow_recommendations SELECT global_follow_recommendations.* FROM global_follow_recommendations INNER JOIN accounts ON accounts.id = global_follow_recommendations.account_id' if Scenic.database.populated?('global_follow_recommendations')
end
# Drop and rename
drop_view :global_follow_recommendations, materialized: true
safety_assured { rename_table :tmp_global_follow_recommendations, :global_follow_recommendations }
drop_view :account_summaries, materialized: true
safety_assured { rename_table :tmp_account_summaries, :account_summaries }
end
def down
drop_table :account_summaries
create_view :account_summaries, version: 3, materialized: true
add_index :account_summaries, :account_id, unique: true
add_index :account_summaries, [:account_id, :language, :sensitive]
drop_table :global_follow_recommendations
create_view :global_follow_recommendations, version: 1, materialized: true
add_index :global_follow_recommendations, :account_id, unique: true
end
end
+36 -56
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.1].define(version: 2026_06_11_150940) do
ActiveRecord::Schema[8.1].define(version: 2026_08_12_154114) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
@@ -130,6 +130,12 @@ ActiveRecord::Schema[8.1].define(version: 2026_06_11_150940) do
t.index ["account_id"], name: "index_account_statuses_cleanup_policies_on_account_id"
end
create_table "account_summaries", primary_key: "account_id", force: :cascade do |t|
t.string "language"
t.boolean "sensitive", default: false, null: false
t.index ["account_id", "language", "sensitive"], name: "idx_on_account_id_language_sensitive_250461e1eb"
end
create_table "account_warning_presets", force: :cascade do |t|
t.datetime "created_at", precision: nil, null: false
t.text "text", default: "", null: false
@@ -192,6 +198,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_06_11_150940) do
t.text "private_key"
t.integer "protocol", default: 0, null: false
t.text "public_key", default: "", null: false
t.datetime "requested_deletion_at"
t.datetime "requested_review_at", precision: nil
t.datetime "reviewed_at", precision: nil
t.datetime "sensitized_at", precision: nil
@@ -204,14 +211,14 @@ ActiveRecord::Schema[8.1].define(version: 2026_06_11_150940) do
t.integer "suspension_origin"
t.boolean "trendable"
t.datetime "updated_at", precision: nil, null: false
t.string "uri", default: "", null: false
t.string "uri"
t.string "url"
t.string "username", default: "", null: false
t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
t.index "lower((username)::text), COALESCE(lower((domain)::text), ''::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
t.index ["domain", "id"], name: "index_accounts_on_domain_and_id"
t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id", where: "(moved_to_account_id IS NOT NULL)"
t.index ["uri"], name: "index_accounts_on_uri"
t.index ["uri"], name: "index_accounts_on_uri", unique: true
t.index ["url"], name: "index_accounts_on_url", opclass: :text_pattern_ops, where: "(url IS NOT NULL)"
end
@@ -227,6 +234,8 @@ ActiveRecord::Schema[8.1].define(version: 2026_06_11_150940) do
t.datetime "created_at", precision: nil, null: false
t.string "human_identifier"
t.string "permalink"
t.jsonb "recorded_changes"
t.string "recorded_changes_format"
t.string "route_param"
t.bigint "target_id"
t.string "target_type"
@@ -629,6 +638,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_06_11_150940) do
t.datetime "updated_at", precision: nil, null: false
t.string "uri"
t.index ["account_id", "target_account_id"], name: "index_follow_requests_on_account_id_and_target_account_id", unique: true
t.index ["target_account_id", "account_id"], name: "index_follow_requests_on_target_account_id_and_account_id"
end
create_table "follows", force: :cascade do |t|
@@ -656,6 +666,13 @@ ActiveRecord::Schema[8.1].define(version: 2026_06_11_150940) do
t.index ["account_id", "year"], name: "index_generated_annual_reports_on_account_id_and_year", unique: true
end
create_table "global_follow_recommendations", primary_key: "account_id", force: :cascade do |t|
t.decimal "rank", null: false
t.string "reason", null: false, array: true
t.boolean "stale", default: false, null: false
t.index ["rank"], name: "index_global_follow_recommendations_on_rank"
end
create_table "identities", force: :cascade do |t|
t.datetime "created_at", precision: nil, null: false
t.string "provider", default: "", null: false
@@ -703,13 +720,14 @@ ActiveRecord::Schema[8.1].define(version: 2026_06_11_150940) do
t.bigint "account_id", null: false
t.datetime "created_at", null: false
t.datetime "expires_at"
t.string "local_fragment"
t.string "private_key"
t.string "public_key", null: false
t.boolean "revoked", default: false, null: false
t.integer "type", null: false
t.datetime "updated_at", null: false
t.string "uri", null: false
t.index ["account_id"], name: "index_keypairs_on_account_id"
t.string "uri"
t.index ["account_id", "local_fragment"], name: "index_keypairs_on_account_id_and_local_fragment", unique: true
t.index ["uri"], name: "index_keypairs_on_uri", unique: true
end
@@ -1153,8 +1171,18 @@ ActiveRecord::Schema[8.1].define(version: 2026_06_11_150940) do
t.index ["var"], name: "index_site_uploads_on_var", unique: true
end
create_table "software_deprecations", force: :cascade do |t|
t.string "branch", null: false
t.datetime "created_at", null: false
t.date "end_of_support", null: false
t.datetime "updated_at", null: false
t.integer "warning_issued", null: false
t.index ["branch"], name: "index_software_deprecations_on_branch", unique: true
end
create_table "software_updates", force: :cascade do |t|
t.datetime "created_at", null: false
t.date "end_of_support"
t.string "release_notes", default: "", null: false
t.integer "type", default: 0, null: false
t.datetime "updated_at", null: false
@@ -1471,6 +1499,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_06_11_150940) do
add_foreign_key "account_relationship_severance_events", "relationship_severance_events", on_delete: :cascade
add_foreign_key "account_stats", "accounts", on_delete: :cascade
add_foreign_key "account_statuses_cleanup_policies", "accounts", on_delete: :cascade
add_foreign_key "account_summaries", "accounts", on_delete: :cascade
add_foreign_key "account_warnings", "accounts", column: "target_account_id", on_delete: :cascade
add_foreign_key "account_warnings", "accounts", on_delete: :nullify
add_foreign_key "account_warnings", "reports", on_delete: :cascade
@@ -1524,7 +1553,8 @@ ActiveRecord::Schema[8.1].define(version: 2026_06_11_150940) do
add_foreign_key "follow_requests", "accounts", name: "fk_76d644b0e7", on_delete: :cascade
add_foreign_key "follows", "accounts", column: "target_account_id", name: "fk_745ca29eac", on_delete: :cascade
add_foreign_key "follows", "accounts", name: "fk_32ed1b5560", on_delete: :cascade
add_foreign_key "generated_annual_reports", "accounts"
add_foreign_key "generated_annual_reports", "accounts", on_delete: :cascade
add_foreign_key "global_follow_recommendations", "accounts", on_delete: :cascade
add_foreign_key "identities", "users", name: "fk_bea040f377", on_delete: :cascade
add_foreign_key "instance_moderation_notes", "accounts", on_delete: :cascade
add_foreign_key "invites", "users", on_delete: :cascade
@@ -1609,56 +1639,6 @@ ActiveRecord::Schema[8.1].define(version: 2026_06_11_150940) do
add_foreign_key "web_settings", "users", name: "fk_11910667b2", on_delete: :cascade
add_foreign_key "webauthn_credentials", "users", on_delete: :cascade
create_view "account_summaries", materialized: true, sql_definition: <<-SQL
SELECT accounts.id AS account_id,
mode() WITHIN GROUP (ORDER BY t0.language) AS language,
mode() WITHIN GROUP (ORDER BY t0.sensitive) AS sensitive
FROM (accounts
CROSS JOIN LATERAL ( SELECT statuses.account_id,
statuses.language,
statuses.sensitive
FROM statuses
WHERE ((statuses.account_id = accounts.id) AND (statuses.deleted_at IS NULL) AND (statuses.reblog_of_id IS NULL))
ORDER BY statuses.id DESC
LIMIT 20) t0)
WHERE ((accounts.suspended_at IS NULL) AND (accounts.silenced_at IS NULL) AND (accounts.moved_to_account_id IS NULL) AND (accounts.discoverable = true) AND (accounts.locked = false))
GROUP BY accounts.id;
SQL
add_index "account_summaries", ["account_id", "language", "sensitive"], name: "idx_on_account_id_language_sensitive_250461e1eb"
add_index "account_summaries", ["account_id"], name: "index_account_summaries_on_account_id", unique: true
create_view "global_follow_recommendations", materialized: true, sql_definition: <<-SQL
SELECT account_id,
sum(rank) AS rank,
array_agg(reason) AS reason
FROM ( SELECT account_summaries.account_id,
((count(follows.id))::numeric / (1.0 + (count(follows.id))::numeric)) AS rank,
'most_followed'::text AS reason
FROM ((follows
JOIN account_summaries ON ((account_summaries.account_id = follows.target_account_id)))
JOIN users ON ((users.account_id = follows.account_id)))
WHERE ((users.current_sign_in_at >= (now() - 'P30D'::interval)) AND (account_summaries.sensitive = false) AND (NOT (EXISTS ( SELECT 1
FROM follow_recommendation_suppressions
WHERE (follow_recommendation_suppressions.account_id = follows.target_account_id)))))
GROUP BY account_summaries.account_id
HAVING (count(follows.id) >= 5)
UNION ALL
SELECT account_summaries.account_id,
(sum((status_stats.reblogs_count + status_stats.favourites_count)) / (1.0 + sum((status_stats.reblogs_count + status_stats.favourites_count)))) AS rank,
'most_interactions'::text AS reason
FROM ((status_stats
JOIN statuses ON ((statuses.id = status_stats.status_id)))
JOIN account_summaries ON ((account_summaries.account_id = statuses.account_id)))
WHERE ((statuses.id >= (((date_part('epoch'::text, (now() - 'P30D'::interval)) * (1000)::double precision))::bigint << 16)) AND (account_summaries.sensitive = false) AND (NOT (EXISTS ( SELECT 1
FROM follow_recommendation_suppressions
WHERE (follow_recommendation_suppressions.account_id = statuses.account_id)))))
GROUP BY account_summaries.account_id
HAVING (sum((status_stats.reblogs_count + status_stats.favourites_count)) >= (5)::numeric)) t0
GROUP BY account_id
ORDER BY (sum(rank)) DESC;
SQL
add_index "global_follow_recommendations", ["account_id"], name: "index_global_follow_recommendations_on_account_id", unique: true
create_view "instances", materialized: true, sql_definition: <<-SQL
WITH domain_counts(domain, accounts_count) AS (
SELECT accounts.domain,
+24
View File
@@ -0,0 +1,24 @@
SELECT
accounts.id AS account_id,
mode() WITHIN GROUP (ORDER BY language ASC) AS language,
mode() WITHIN GROUP (ORDER BY sensitive ASC) AS sensitive
FROM accounts
CROSS JOIN LATERAL (
SELECT
statuses.account_id,
statuses.language,
statuses.sensitive
FROM statuses
WHERE statuses.account_id = accounts.id
AND statuses.deleted_at IS NULL
AND statuses.reblog_of_id IS NULL
ORDER BY statuses.id DESC
LIMIT 20
) t0
WHERE accounts.suspended_at IS NULL
AND accounts.requested_deletion_at IS NULL
AND accounts.silenced_at IS NULL
AND accounts.moved_to_account_id IS NULL
AND accounts.discoverable = 't'
AND accounts.locked = 'f'
GROUP BY accounts.id