Files
mastodon/db/post_migrate/20260804081821_convert_materialized_views_to_tables.rb
jcoffey-dev 319ed76dbd
Crowdin / Upload translations / upload-translations (push) Skipped
Historical data migration test / test (14-alpine) (push) Canceled after 0s
Historical data migration test / test (15-alpine) (push) Canceled after 0s
Historical data migration test / test (16-alpine) (push) Canceled after 0s
Historical data migration test / test (17-alpine) (push) Canceled after 0s
Bundler Audit / security (push) Canceled after 0s
Haml Linting / lint (push) Canceled after 0s
JavaScript Linting / lint (push) Canceled after 0s
Ruby Linting / lint (push) Canceled after 0s
JavaScript Testing / test (push) Canceled after 0s
Ruby Testing / build (production) (push) Canceled after 0s
Ruby Testing / test (.ruby-version) (push) Canceled after 0s
Ruby Testing / test (3.3) (push) Canceled after 0s
Ruby Testing / test (3.4) (push) Canceled after 0s
Ruby Testing / End to End testing (.ruby-version) (push) Canceled after 0s
Ruby Testing / End to End testing (3.3) (push) Canceled after 0s
Ruby Testing / End to End testing (3.4) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check i18n / check-i18n (push) Canceled after 0s
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (javascript) (push) Canceled after 0s
CodeQL / Analyze (ruby) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check formatting / lint (push) Canceled after 0s
CSS Linting / lint (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Canceled after 0s
Chromatic / Check for relevant changes (push) Canceled after 0s
Chromatic / Run Chromatic (push) Canceled after 0s
Import Mastodon v4.7.3
Snapshot of upstream tag v4.7.3 (commit 8ff11c2bb7b9f0714e947b10fa3629c6542c7121) from
https://github.com/mastodon/mastodon, unmodified.
2026-10-05 22:03:13 -07:00

59 lines
3.0 KiB
Ruby

# 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