Merge remote-tracking branch 'mastodon/main' into custom/quote

This commit is contained in:
kyori19
2022-11-05 19:43:04 +00:00
1540 changed files with 62088 additions and 37209 deletions

View File

@@ -80,7 +80,7 @@ class IdsToBigints < ActiveRecord::Migration[5.1]
say 'This migration has some sections that can be safely interrupted'
say 'and restarted later, and will tell you when those are occurring.'
say ''
say 'For more information, see https://github.com/tootsuite/mastodon/pull/5088'
say 'For more information, see https://github.com/mastodon/mastodon/pull/5088'
10.downto(1) do |i|
say "Continuing in #{i} second#{i == 1 ? '' : 's'}...", true

View File

@@ -0,0 +1,12 @@
class CreateWebhooks < ActiveRecord::Migration[6.1]
def change
create_table :webhooks do |t|
t.string :url, null: false, index: { unique: true }
t.string :events, array: true, null: false, default: []
t.string :secret, null: false, default: ''
t.boolean :enabled, null: false, default: true
t.timestamps
end
end
end

View File

@@ -0,0 +1,13 @@
class CreateUserRoles < ActiveRecord::Migration[6.1]
def change
create_table :user_roles do |t|
t.string :name, null: false, default: ''
t.string :color, null: false, default: ''
t.integer :position, null: false, default: 0
t.bigint :permissions, null: false, default: 0
t.boolean :highlighted, null: false, default: false
t.timestamps
end
end
end

View File

@@ -0,0 +1,8 @@
class AddRoleIdToUsers < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def change
safety_assured { add_reference :users, :role, foreign_key: { to_table: 'user_roles', on_delete: :nullify }, index: false }
add_index :users, :role_id, algorithm: :concurrently, where: 'role_id IS NOT NULL'
end
end

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
class CreateCustomFilterKeywords < ActiveRecord::Migration[6.1]
def change
create_table :custom_filter_keywords do |t|
t.belongs_to :custom_filter, foreign_key: { on_delete: :cascade }, null: false
t.text :keyword, null: false, default: ''
t.boolean :whole_word, null: false, default: true
t.timestamps
end
end
end

View File

@@ -0,0 +1,34 @@
# frozen_string_literal: true
class MigrateCustomFilters < ActiveRecord::Migration[6.1]
def up
# Preserve IDs as much as possible to not confuse existing clients.
# As long as this migration is irreversible, we do not have to deal with conflicts.
safety_assured do
execute <<-SQL.squish
INSERT INTO custom_filter_keywords (id, custom_filter_id, keyword, whole_word, created_at, updated_at)
SELECT id, id, phrase, whole_word, created_at, updated_at
FROM custom_filters
SQL
end
end
def down
# Copy back changes from custom filters guaranteed to be from the old API
safety_assured do
execute <<-SQL.squish
UPDATE custom_filters
SET phrase = custom_filter_keywords.keyword, whole_word = custom_filter_keywords.whole_word
FROM custom_filter_keywords
WHERE custom_filters.id = custom_filter_keywords.id AND custom_filters.id = custom_filter_keywords.custom_filter_id
SQL
end
# Drop every keyword as we can't safely provide a 1:1 mapping
safety_assured do
execute <<-SQL.squish
TRUNCATE custom_filter_keywords RESTART IDENTITY
SQL
end
end
end

View File

@@ -0,0 +1,20 @@
# frozen_string_literal: true
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
class AddActionToCustomFilters < ActiveRecord::Migration[6.1]
include Mastodon::MigrationHelpers
disable_ddl_transaction!
def up
safety_assured do
add_column_with_default :custom_filters, :action, :integer, allow_null: false, default: 0
execute 'UPDATE custom_filters SET action = 1 WHERE irreversible IS TRUE'
end
end
def down
execute 'UPDATE custom_filters SET irreversible = (action = 1)'
remove_column :custom_filters, :action
end
end

View File

@@ -0,0 +1,5 @@
class AddDisplayNameToTags < ActiveRecord::Migration[6.1]
def change
add_column :tags, :display_name, :string
end
end

View File

@@ -0,0 +1,12 @@
class CreateTagFollows < ActiveRecord::Migration[6.1]
def change
create_table :tag_follows do |t|
t.belongs_to :tag, null: false, foreign_key: { on_delete: :cascade }
t.belongs_to :account, null: false, foreign_key: { on_delete: :cascade }, index: false
t.timestamps
end
add_index :tag_follows, [:account_id, :tag_id], unique: true
end
end

View File

@@ -0,0 +1,12 @@
# frozen_string_literal: true
class CreateCustomFilterStatuses < ActiveRecord::Migration[6.1]
def change
create_table :custom_filter_statuses do |t|
t.belongs_to :custom_filter, foreign_key: { on_delete: :cascade }, null: false
t.belongs_to :status, foreign_key: { on_delete: :cascade }, null: false
t.timestamps
end
end
end

View File

@@ -0,0 +1,7 @@
class AddHumanIdentifierToAdminActionLogs < ActiveRecord::Migration[6.1]
def change
add_column :admin_action_logs, :human_identifier, :string
add_column :admin_action_logs, :route_param, :string
add_column :admin_action_logs, :permalink, :string
end
end

View File

@@ -0,0 +1,12 @@
class CreateStatusTrends < ActiveRecord::Migration[6.1]
def change
create_table :status_trends do |t|
t.references :status, null: false, foreign_key: { on_delete: :cascade }, index: { unique: true }
t.references :account, null: false, foreign_key: { on_delete: :cascade }
t.float :score, null: false, default: 0
t.integer :rank, null: false, default: 0
t.boolean :allowed, null: false, default: false
t.string :language
end
end
end

View File

@@ -0,0 +1,5 @@
class ChangeCanonicalEmailBlocksNullable < ActiveRecord::Migration[6.1]
def change
safety_assured { change_column :canonical_email_blocks, :reference_account_id, :bigint, null: true, default: nil }
end
end

View File

@@ -0,0 +1,5 @@
class AddLanguagesToFollows < ActiveRecord::Migration[6.1]
def change
add_column :follows, :languages, :string, array: true
end
end

View File

@@ -0,0 +1,5 @@
class AddLanguagesToFollowRequests < ActiveRecord::Migration[6.1]
def change
add_column :follow_requests, :languages, :string, array: true
end
end

View File

@@ -0,0 +1,11 @@
class CreatePreviewCardTrends < ActiveRecord::Migration[6.1]
def change
create_table :preview_card_trends do |t|
t.references :preview_card, null: false, foreign_key: { on_delete: :cascade }, index: { unique: true }
t.float :score, null: false, default: 0
t.integer :rank, null: false, default: 0
t.boolean :allowed, null: false, default: false
t.string :language
end
end
end

View File

@@ -0,0 +1,5 @@
class AddBlurhashToSiteUploads < ActiveRecord::Migration[6.1]
def change
add_column :site_uploads, :blurhash, :string
end
end

View File

@@ -0,0 +1,19 @@
class AddIndexFeaturedTagsOnAccountIdAndTagId < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def up
duplicates = FeaturedTag.connection.select_all('SELECT string_agg(id::text, \',\') AS ids FROM featured_tags GROUP BY account_id, tag_id HAVING count(*) > 1').to_ary
duplicates.each do |row|
FeaturedTag.where(id: row['ids'].split(',')[0...-1]).destroy_all
end
add_index :featured_tags, [:account_id, :tag_id], unique: true, algorithm: :concurrently
remove_index :featured_tags, [:account_id], algorithm: :concurrently
end
def down
add_index :featured_tags, [:account_id], algorithm: :concurrently
remove_index :featured_tags, [:account_id, :tag_id], unique: true, algorithm: :concurrently
end
end

View File

@@ -0,0 +1,17 @@
class AddIndexIpBlocksOnIp < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def up
duplicates = IpBlock.connection.select_all('SELECT string_agg(id::text, \',\') AS ids FROM ip_blocks GROUP BY ip HAVING count(*) > 1').to_ary
duplicates.each do |row|
IpBlock.where(id: row['ids'].split(',')[0...-1]).destroy_all
end
add_index :ip_blocks, :ip, unique: true, algorithm: :concurrently
end
def down
remove_index :ip_blocks, :ip, unique: true
end
end

View File

@@ -0,0 +1,5 @@
class AddNameToFeaturedTags < ActiveRecord::Migration[6.1]
def change
add_column :featured_tags, :name, :string
end
end