Revert "Upstream 20240517"

This commit is contained in:
KMY(雪あすか) 2024-05-24 08:15:12 +09:00 committed by GitHub
parent 9c006fd893
commit f6dec44e95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2347 changed files with 26470 additions and 87494 deletions

View file

@ -1,229 +0,0 @@
# frozen_string_literal: true
# rubocop:disable all
namespace :dangerous do
task :back_upstream do
require './config/environment'
prompt = TTY::Prompt.new
unless ENV['BACK_UPSTREAM_FORCE']
exit(0) unless prompt.yes?('[1/3] Do you really want to go back to the original Mastodon?', default: false)
exit(0) unless prompt.yes?('[2/3] All proprietary data of kmyblue will be deleted and cannot be restored. Are you sure?', default: false)
exit(0) unless prompt.yes?('[3/3] This operation is irreversible. You have backups in case this operation causes a system malfunction, do you not?', default: false)
end
target_migrations = %w(
20240426233435
20240426000034
20240401222541
20240327234026
20240326231854
20240320231633
20240312230204
20240229233617
20240227225017
20240227222450
20240227033337
20240218233621
20240217230006
20240217093511
20240217022038
20240216042730
20240212230358
20240212224800
20240121231131
20240117022353
20240117021025
20240109035435
20231214225249
20231212225737
20231130083634
20231130031209
20231115001356
20231105225839
20231028005948
20231028004612
20231023083359
20231022074913
20231021005339
20231009235215
20231007090808
20231006030102
20231005074832
20231001050733
20231001031337
20230930233930
20230923103430
20230919232836
20230911022527
20230826023400
20230821061713
20230819084858
20230812130612
20230812083752
20230804222017
20230714004824
20230706031715
20230705232953
20230522093135
20230522082252
20230521122642
20230514030455
20230512122757
20230510033040
20230510004621
20230510000439
20230509045358
20230430110057
20230428111230
20230427233749
20230427122753
20230427072650
20230427022606
20230426013738
20230423233429
20230423002728
20230420081634
20230414010523
20230412073021
20230412005311
20230410004651
20230406041523
20230405121625
20230405121613
20230320234918
20230314121142
20230314120530
20230314081013
20230314021909
20230308061833
20230223102416
20230222232121
)
# Removed: account_groups
target_tables = %w(
antennas
antenna_accounts
antenna_domains
antenna_tags
bookmark_categories
bookmark_category_statuses
circles
circle_accounts
circle_statuses
emoji_reactions
friend_domains
instance_infos
list_statuses
ng_rules
ng_rule_histories
ngword_histories
ng_words
pending_follow_requests
pending_statuses
scheduled_expiration_statuses
sensitive_words
specified_domains
status_capability_tokens
status_references
)
target_table_columns = [
# Removed: accounts dissubscribable
# Removed: accounts group_allow_private_message
# Removed: accounts group_message_following_only
%w(accounts master_settings),
%w(accounts remote_pending),
%w(accounts searchability),
%w(accounts settings),
# Removed: accounts stop_emoji_reaction_streaming
# Removed: account_stats group_activitypub_count
%w(account_statuses_cleanup_policies keep_self_emoji),
%w(account_statuses_cleanup_policies min_emojis),
%w(conversations ancestor_status_id),
%w(conversations inbox_url),
%w(custom_emojis aliases),
%w(custom_emojis image_height),
%w(custom_emojis image_width),
%w(custom_emojis is_sensitive),
%w(custom_emojis license),
%w(custom_filters exclude_follows),
%w(custom_filters exclude_localusers),
%w(custom_filters with_quote),
%w(domain_blocks block_trends),
%w(domain_blocks detect_invalid_subscription),
%w(domain_blocks hidden),
# Removed: domain_blocks hidden_anonymous
%w(domain_blocks reject_favourite),
%w(domain_blocks reject_friend),
%w(domain_blocks reject_hashtag),
%w(domain_blocks reject_new_follow),
# Removed: domain_blocks reject_reply
%w(domain_blocks reject_reply_exclude_followers),
# Removed: domain_blocks reject_send_dissubscribable
# Removed: domain_blocks reject_send_media
# Removed: domain_blocks reject_send_not_public_searchability
# Removed: domain_blocks reject_send_public_unlisted
# Removed: domain_blocks reject_send_unlisted_dissubscribable
%w(domain_blocks reject_send_sensitive),
%w(domain_blocks reject_straight_follow),
%w(favourites uri),
%w(lists notify),
%w(statuses limited_scope),
%w(statuses markdown),
%w(statuses quote_of_id),
%w(statuses searchability),
%w(status_edits markdown),
%w(status_stats emoji_reactions),
%w(status_stats emoji_reactions_count),
%w(status_stats emoji_reaction_accounts_count),
%w(status_stats status_referred_by_count),
# Removed: status_stats test
]
target_indices = %w(
index_statuses_on_url
index_statuses_on_conversation_id
index_preview_cards_vacuum
index_media_attachments_vacuum
)
prompt.say 'Processing...'
ActiveRecord::Base.connection.execute('UPDATE statuses SET visibility = 1 WHERE visibility IN (10, 11)')
ActiveRecord::Base.connection.execute('UPDATE custom_filters SET action = 0 WHERE action = 2')
ActiveRecord::Base.connection.execute('UPDATE account_warnings SET action = 1250 WHERE action = 1200')
ActiveRecord::Base.connection.execute('CREATE INDEX IF NOT EXISTS index_statuses_local_20190824 ON statuses USING btree (id DESC, account_id) WHERE (local OR (uri IS NULL)) AND deleted_at IS NULL AND visibility = 0 AND reblog_of_id IS NULL AND ((NOT reply) OR (in_reply_to_account_id = account_id))')
ActiveRecord::Base.connection.execute('CREATE INDEX IF NOT EXISTS index_statuses_public_20200119 ON statuses USING btree (id DESC, account_id) WHERE deleted_at IS NULL AND visibility = 0 AND reblog_of_id IS NULL AND ((NOT reply) OR (in_reply_to_account_id = account_id))')
ActiveRecord::Base.connection.execute('DROP INDEX IF EXISTS index_statuses_local_20231213')
ActiveRecord::Base.connection.execute('DROP INDEX IF EXISTS index_statuses_public_20231213')
ActiveRecord::Base.connection.execute('ALTER TABLE ONLY custom_filter_keywords ALTER COLUMN whole_word SET DEFAULT true')
prompt.ok 'Proceed'
prompt.say 'Removing migration histories...'
ActiveRecord::Base.connection.execute("DELETE FROM schema_migrations WHERE version IN ('#{target_migrations.join("','")}')")
prompt.ok 'Removed'
prompt.say 'Removing tables...'
target_tables.each do |table_name|
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS #{table_name} CASCADE")
end
prompt.ok 'Removed'
prompt.say 'Removing table columns...'
target_table_columns.each do |table_name, column_name|
ActiveRecord::Base.connection.execute("ALTER TABLE #{table_name} DROP COLUMN IF EXISTS #{column_name}")
end
prompt.ok 'Removed'
prompt.say 'Removing indices...'
target_indices.each do |index_name|
ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS #{index_name}")
end
prompt.ok 'Removed'
prompt.ok 'Done!'
prompt.say "\n"
prompt.ok 'Thanks for using kmyblue. Good bye!'
end
end
# rubocop:enable all

View file

@ -1,22 +1,6 @@
# frozen_string_literal: true
# We are providing our own task with our own format
Rake::Task['db:encryption:init'].clear
namespace :db do
namespace :encryption do
desc 'Generate a set of keys for configuring Active Record encryption in a given environment'
task :init do # rubocop:disable Rails/RakeEnvironment
puts <<~MSG
Add these environment variables to your Mastodon environment:#{' '}
ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=#{SecureRandom.alphanumeric(32)}
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=#{SecureRandom.alphanumeric(32)}
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=#{SecureRandom.alphanumeric(32)}
MSG
end
end
namespace :migrate do
desc 'Setup the db or migrate depending on state of db'
task setup: :environment do
@ -31,9 +15,9 @@ namespace :db do
end
end
task pre_migration_check: :environment do
version = ActiveRecord::Base.connection.database_version
abort 'This version of Mastodon requires PostgreSQL 12.0 or newer. Please update PostgreSQL before updating Mastodon.' if version < 120_000
task :pre_migration_check do
version = ActiveRecord::Base.connection.select_one("SELECT current_setting('server_version_num') AS v")['v'].to_i
abort 'This version of Mastodon requires PostgreSQL 9.5 or newer. Please update PostgreSQL before updating Mastodon' if version < 90_500
end
Rake::Task['db:migrate'].enhance(['db:pre_migration_check'])

View file

@ -22,7 +22,7 @@ def find_used_icons
Dir[Rails.root.join('app', 'javascript', '**', '*.*s*')].map do |path|
File.open(path, 'r') do |file|
pattern = %r{\Aimport .* from '@/material-icons/(?<weight>[0-9]+)-(?<size>[0-9]+)px/(?<icon>[^-]*)(?<fill>-fill)?.svg\?react';}
pattern = %r{\Aimport .* from 'mastodon/../material-icons/(?<weight>[0-9]+)-(?<size>[0-9]+)px/(?<icon>[^-]*)(?<fill>-fill)?.svg\?react';}
file.each_line do |line|
match = pattern.match(line)
next if match.blank?

View file

@ -36,15 +36,6 @@ namespace :mastodon do
env[key] = SecureRandom.hex(64)
end
# Required by ActiveRecord encryption feature
%w(
ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY
).each do |key|
env[key] = SecureRandom.alphanumeric(32)
end
vapid_key = Webpush.generate_key
env['VAPID_PRIVATE_KEY'] = vapid_key.private_key
@ -458,7 +449,7 @@ namespace :mastodon do
prompt.say "\n"
env['UPDATE_CHECK_URL'] = '' unless prompt.yes?('Do you want kmyblue to periodically check for important updates and notify you? (Recommended)', default: true)
env['UPDATE_CHECK_URL'] = '' unless prompt.yes?('Do you want Mastodon to periodically check for important updates and notify you? (Recommended)', default: true)
prompt.say "\n"
prompt.say 'This configuration will be written to .env.production'
@ -553,7 +544,6 @@ namespace :mastodon do
owner_role = UserRole.find_by(name: 'Owner')
user = User.new(email: email, password: password, confirmed_at: Time.now.utc, account_attributes: { username: username }, bypass_invite_request_check: true, role: owner_role)
user.save(validate: false)
user.approve!
Setting.site_contact_username = username

View file

@ -1,11 +0,0 @@
# frozen_string_literal: true
namespace :sidekiq_unique_jobs do
task delete_all_locks: :environment do
digests = SidekiqUniqueJobs::Digests.new
digests.delete_by_pattern('*', count: digests.count)
expiring_digests = SidekiqUniqueJobs::ExpiringDigests.new
expiring_digests.delete_by_pattern('*', count: expiring_digests.count)
end
end

13
lib/tasks/spec.rake Normal file
View file

@ -0,0 +1,13 @@
# frozen_string_literal: true
if Rake::Task.task_defined?('spec:system')
namespace :spec do
task :enable_system_specs do # rubocop:disable Rails/RakeEnvironment
ENV['LOCAL_DOMAIN'] = 'localhost:3000'
ENV['LOCAL_HTTPS'] = 'false'
ENV['RUN_SYSTEM_SPECS'] = 'true'
end
end
Rake::Task['spec:system'].enhance ['spec:enable_system_specs']
end

View file

@ -2,23 +2,6 @@
namespace :tests do
namespace :migrations do
desc 'Prepares all migrations and test data for consistency checks'
task prepare_database: :environment do
{
'2' => 2017_10_10_025614,
'2_4' => 2018_05_14_140000,
'2_4_3' => 2018_07_07_154237,
'3_3_0' => 2020_12_18_054746,
}.each do |release, version|
ActiveRecord::Tasks::DatabaseTasks
.migration_connection
.migration_context
.migrate(version)
Rake::Task["tests:migrations:populate_v#{release}"]
.invoke
end
end
desc 'Check that database state is consistent with a successful migration from populated data'
task check_database: :environment do
unless Account.find_by(username: 'admin', domain: nil)&.hide_collections? == false
@ -41,7 +24,7 @@ namespace :tests do
exit(1)
end
if Account.exists?(domain: Rails.configuration.x.local_domain)
if Account.where(domain: Rails.configuration.x.local_domain).exists?
puts 'Faux remote accounts not properly cleaned up'
exit(1)
end
@ -51,7 +34,7 @@ namespace :tests do
exit(1)
end
if Account.find(Account::INSTANCE_ACTOR_ID).private_key.blank?
if Account.find(-99).private_key.blank?
puts 'Instance actor does not have a private key'
exit(1)
end
@ -105,54 +88,6 @@ namespace :tests do
puts 'Locale for fr-QC users not updated to fr-CA as expected'
exit(1)
end
policy = NotificationPolicy.find_by(account: User.find(1).account)
unless policy.filter_private_mentions == false && policy.filter_not_following == true
puts 'Notification policy not migrated as expected'
exit(1)
end
unless Identity.where(provider: 'foo', uid: 0).count == 1
puts 'Identities not deduplicated as expected'
exit(1)
end
unless WebauthnCredential.where(user_id: 1, nickname: 'foo').count == 1
puts 'Webauthn credentials not deduplicated as expected'
exit(1)
end
unless AccountAlias.where(account_id: 1, uri: 'https://example.com/users/foobar').count == 1
puts 'Account aliases not deduplicated as expected'
exit(1)
end
# This is checking the attribute rather than the method, to avoid the legacy fallback
# and ensure the data has been migrated
unless Account.find_local('qcuser').user[:otp_secret] == 'anotpsecretthatshouldbeencrypted'
puts "DEBUG: #{Account.find_local('qcuser').user.inspect}"
puts 'OTP secret for user not preserved as expected'
exit(1)
end
puts 'No errors found. Database state is consistent with a successful migration process.'
end
desc 'Populate the database with test data for 3.3.0'
task populate_v3_3_0: :environment do # rubocop:disable Naming/VariableNumber
ActiveRecord::Base.connection.execute(<<~SQL.squish)
INSERT INTO "webauthn_credentials"
(user_id, nickname, external_id, public_key, created_at, updated_at)
VALUES
(1, 'foo', 1, 'foo', now(), now()),
(1, 'foo', 2, 'bar', now(), now());
INSERT INTO "account_aliases"
(account_id, uri, acct, created_at, updated_at)
VALUES
(1, 'https://example.com/users/foobar', 'foobar@example.com', now(), now()),
(1, 'https://example.com/users/foobar', 'foobar@example.com', now(), now());
SQL
end
desc 'Populate the database with test data for 2.4.3'
@ -206,7 +141,7 @@ namespace :tests do
INSERT INTO "settings"
(id, thing_type, thing_id, var, value, created_at, updated_at)
VALUES
(3, 'User', 1, 'notification_emails', E'--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\nfollow: false\nreblog: true\nfavourite: true\nmention: false\nfollow_request: true\ndigest: true\nreport: true\npending_account: false\npending_friend_server: true\ntrending_tag: true\nappeal: true\n', now(), now()),
(3, 'User', 1, 'notification_emails', E'--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\nfollow: false\nreblog: true\nfavourite: true\nmention: false\nfollow_request: true\ndigest: true\nreport: true\npending_account: false\ntrending_tag: true\nappeal: true\n', now(), now()),
(4, 'User', 1, 'trends', E'--- false\n', now(), now());
INSERT INTO "accounts"
@ -221,27 +156,14 @@ namespace :tests do
(4, 10, 'kmruser@localhost', now(), now(), false, 'ku', '{en,kmr,ku,ckb}');
INSERT INTO "users"
(id, account_id, email, created_at, updated_at, locale,
encrypted_otp_secret, encrypted_otp_secret_iv, encrypted_otp_secret_salt,
otp_required_for_login)
(id, account_id, email, created_at, updated_at, locale)
VALUES
(5, 11, 'qcuser@localhost', now(), now(), 'fr-QC',
E'Fttsy7QAa0edaDfdfSz094rRLAxc8cJweDQ4BsWH/zozcdVA8o9GLqcKhn2b\nGi/V\n',
'rys3THICkr60BoWC',
'_LMkAGvdg7a+sDIKjI3mR2Q==',
true);
(5, 11, 'qcuser@localhost', now(), now(), 'fr-QC');
INSERT INTO "settings"
(id, thing_type, thing_id, var, value, created_at, updated_at)
VALUES
(5, 'User', 4, 'default_language', E'--- kmr\n', now(), now()),
(6, 'User', 1, 'interactions', E'--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\nmust_be_follower: false\nmust_be_following: true\nmust_be_following_dm: false\n', now(), now());
INSERT INTO "identities"
(provider, uid, user_id, created_at, updated_at)
VALUES
('foo', 0, 1, now(), now()),
('foo', 0, 1, now(), now());
(5, 'User', 4, 'default_language', E'--- kmr\n', now(), now());
SQL
end