Merge remote-tracking branch 'mastodon/main' into custom/quote
This commit is contained in:
@@ -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
|
||||
|
12
db/migrate/20220606044941_create_webhooks.rb
Normal file
12
db/migrate/20220606044941_create_webhooks.rb
Normal 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
|
13
db/migrate/20220611210335_create_user_roles.rb
Normal file
13
db/migrate/20220611210335_create_user_roles.rb
Normal 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
|
8
db/migrate/20220611212541_add_role_id_to_users.rb
Normal file
8
db/migrate/20220611212541_add_role_id_to_users.rb
Normal 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
|
13
db/migrate/20220613110628_create_custom_filter_keywords.rb
Normal file
13
db/migrate/20220613110628_create_custom_filter_keywords.rb
Normal 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
|
34
db/migrate/20220613110711_migrate_custom_filters.rb
Normal file
34
db/migrate/20220613110711_migrate_custom_filters.rb
Normal 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
|
20
db/migrate/20220613110834_add_action_to_custom_filters.rb
Normal file
20
db/migrate/20220613110834_add_action_to_custom_filters.rb
Normal 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
|
5
db/migrate/20220710102457_add_display_name_to_tags.rb
Normal file
5
db/migrate/20220710102457_add_display_name_to_tags.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddDisplayNameToTags < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :tags, :display_name, :string
|
||||
end
|
||||
end
|
12
db/migrate/20220714171049_create_tag_follows.rb
Normal file
12
db/migrate/20220714171049_create_tag_follows.rb
Normal 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
|
12
db/migrate/20220808101323_create_custom_filter_statuses.rb
Normal file
12
db/migrate/20220808101323_create_custom_filter_statuses.rb
Normal 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
|
@@ -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
|
12
db/migrate/20220824233535_create_status_trends.rb
Normal file
12
db/migrate/20220824233535_create_status_trends.rb
Normal 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
|
@@ -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
|
5
db/migrate/20220829192633_add_languages_to_follows.rb
Normal file
5
db/migrate/20220829192633_add_languages_to_follows.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddLanguagesToFollows < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :follows, :languages, :string, array: true
|
||||
end
|
||||
end
|
@@ -0,0 +1,5 @@
|
||||
class AddLanguagesToFollowRequests < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :follow_requests, :languages, :string, array: true
|
||||
end
|
||||
end
|
11
db/migrate/20221006061337_create_preview_card_trends.rb
Normal file
11
db/migrate/20221006061337_create_preview_card_trends.rb
Normal 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
|
@@ -0,0 +1,5 @@
|
||||
class AddBlurhashToSiteUploads < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :site_uploads, :blurhash, :string
|
||||
end
|
||||
end
|
@@ -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
|
17
db/migrate/20221025171544_add_index_ip_blocks_on_ip.rb
Normal file
17
db/migrate/20221025171544_add_index_ip_blocks_on_ip.rb
Normal 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
|
5
db/migrate/20221104133904_add_name_to_featured_tags.rb
Normal file
5
db/migrate/20221104133904_add_name_to_featured_tags.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddNameToFeaturedTags < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :featured_tags, :name, :string
|
||||
end
|
||||
end
|
@@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class RemoveFilteredLanguagesFromUsers < ActiveRecord::Migration[6.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
safety_assured do
|
||||
remove_column :users, :filtered_languages, :string, array: true, default: [], null: false
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class RemoveWholeWordFromCustomFilters < ActiveRecord::Migration[6.1]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
remove_column :custom_filters, :whole_word
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
safety_assured do
|
||||
add_column_with_default :custom_filters, :whole_word, :boolean, default: true, allow_null: false
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class RemoveIrreversibleFromCustomFilters < ActiveRecord::Migration[6.1]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
remove_column :custom_filters, :irreversible
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
safety_assured do
|
||||
add_column_with_default :custom_filters, :irreversible, :boolean, allow_null: false, default: false
|
||||
end
|
||||
end
|
||||
end
|
27
db/post_migrate/20220617202502_migrate_roles.rb
Normal file
27
db/post_migrate/20220617202502_migrate_roles.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class MigrateRoles < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
class UserRole < ApplicationRecord; end
|
||||
class User < ApplicationRecord; end
|
||||
|
||||
def up
|
||||
load Rails.root.join('db', 'seeds', '03_roles.rb')
|
||||
|
||||
owner_role = UserRole.find_by(name: 'Owner')
|
||||
moderator_role = UserRole.find_by(name: 'Moderator')
|
||||
|
||||
User.where(admin: true).in_batches.update_all(role_id: owner_role.id)
|
||||
User.where(moderator: true).in_batches.update_all(role_id: moderator_role.id)
|
||||
end
|
||||
|
||||
def down
|
||||
admin_role = UserRole.find_by(name: 'Admin')
|
||||
owner_role = UserRole.find_by(name: 'Owner')
|
||||
moderator_role = UserRole.find_by(name: 'Moderator')
|
||||
|
||||
User.where(role_id: [admin_role.id, owner_role.id]).in_batches.update_all(admin: true) if admin_role
|
||||
User.where(role_id: moderator_role.id).in_batches.update_all(moderator: true) if moderator_role
|
||||
end
|
||||
end
|
@@ -0,0 +1,41 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class MigrateSettingsToUserRoles < ActiveRecord::Migration[6.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
class UserRole < ApplicationRecord; end
|
||||
|
||||
def up
|
||||
owner_role = UserRole.find_by(name: 'Owner')
|
||||
admin_role = UserRole.find_by(name: 'Admin')
|
||||
moderator_role = UserRole.find_by(name: 'Moderator')
|
||||
everyone_role = UserRole.find_by(id: -99)
|
||||
|
||||
min_invite_role = Setting.min_invite_role
|
||||
show_staff_badge = Setting.show_staff_badge
|
||||
|
||||
if everyone_role
|
||||
everyone_role.permissions &= ~::UserRole::FLAGS[:invite_users] unless min_invite_role == 'user'
|
||||
everyone_role.save
|
||||
end
|
||||
|
||||
if owner_role
|
||||
owner_role.highlighted = show_staff_badge
|
||||
owner_role.save
|
||||
end
|
||||
|
||||
if admin_role
|
||||
admin_role.permissions |= ::UserRole::FLAGS[:invite_users] if %w(admin moderator).include?(min_invite_role)
|
||||
admin_role.highlighted = show_staff_badge
|
||||
admin_role.save
|
||||
end
|
||||
|
||||
if moderator_role
|
||||
moderator_role.permissions |= ::UserRole::FLAGS[:invite_users] if %w(moderator).include?(min_invite_role)
|
||||
moderator_role.highlighted = show_staff_badge
|
||||
moderator_role.save
|
||||
end
|
||||
end
|
||||
|
||||
def down; end
|
||||
end
|
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class FixCustomFilterKeywordsIdSeq < ActiveRecord::Migration[6.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
# 20220613110711 manually inserts items with set `id` in the database, but
|
||||
# we also need to bump the sequence number, otherwise
|
||||
safety_assured do
|
||||
execute <<-SQL.squish
|
||||
BEGIN;
|
||||
LOCK TABLE custom_filter_keywords IN EXCLUSIVE MODE;
|
||||
SELECT setval('custom_filter_keywords_id_seq'::regclass, id) FROM custom_filter_keywords ORDER BY id DESC LIMIT 1;
|
||||
COMMIT;
|
||||
SQL
|
||||
end
|
||||
end
|
||||
|
||||
def down; end
|
||||
end
|
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class RemoveRecordedChangesFromAdminActionLogs < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
safety_assured { remove_column :admin_action_logs, :recorded_changes, :text }
|
||||
end
|
||||
end
|
150
db/post_migrate/20221101190723_backfill_admin_action_logs.rb
Normal file
150
db/post_migrate/20221101190723_backfill_admin_action_logs.rb
Normal file
@@ -0,0 +1,150 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class BackfillAdminActionLogs < ActiveRecord::Migration[6.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
class Account < ApplicationRecord
|
||||
# Dummy class, to make migration possible across version changes
|
||||
has_one :user, inverse_of: :account
|
||||
|
||||
def local?
|
||||
domain.nil?
|
||||
end
|
||||
|
||||
def acct
|
||||
local? ? username : "#{username}@#{domain}"
|
||||
end
|
||||
end
|
||||
|
||||
class User < ApplicationRecord
|
||||
# Dummy class, to make migration possible across version changes
|
||||
belongs_to :account
|
||||
end
|
||||
|
||||
class Status < ApplicationRecord
|
||||
include RoutingHelper
|
||||
|
||||
# Dummy class, to make migration possible across version changes
|
||||
belongs_to :account
|
||||
|
||||
def local?
|
||||
attributes['local'] || attributes['uri'].nil?
|
||||
end
|
||||
|
||||
def uri
|
||||
local? ? activity_account_status_url(account, self) : attributes['uri']
|
||||
end
|
||||
end
|
||||
|
||||
class DomainBlock < ApplicationRecord; end
|
||||
class DomainAllow < ApplicationRecord; end
|
||||
class EmailDomainBlock < ApplicationRecord; end
|
||||
class UnavailableDomain < ApplicationRecord; end
|
||||
|
||||
class AccountWarning < ApplicationRecord
|
||||
# Dummy class, to make migration possible across version changes
|
||||
belongs_to :account
|
||||
end
|
||||
|
||||
class Announcement < ApplicationRecord; end
|
||||
class IpBlock < ApplicationRecord; end
|
||||
class CustomEmoji < ApplicationRecord; end
|
||||
class CanonicalEmailBlock < ApplicationRecord; end
|
||||
|
||||
class Appeal < ApplicationRecord
|
||||
# Dummy class, to make migration possible across version changes
|
||||
belongs_to :account
|
||||
end
|
||||
|
||||
class AdminActionLog < ApplicationRecord
|
||||
# Dummy class, to make migration possible across version changes
|
||||
|
||||
# Cannot use usual polymorphic support because of namespacing issues
|
||||
belongs_to :status, foreign_key: :target_id
|
||||
belongs_to :account, foreign_key: :target_id
|
||||
belongs_to :user, foreign_key: :user_id
|
||||
belongs_to :domain_block, foreign_key: :target_id
|
||||
belongs_to :domain_allow, foreign_key: :target_id
|
||||
belongs_to :email_domain_block, foreign_key: :target_id
|
||||
belongs_to :unavailable_domain, foreign_key: :target_id
|
||||
belongs_to :account_warning, foreign_key: :target_id
|
||||
belongs_to :announcement, foreign_key: :target_id
|
||||
belongs_to :ip_block, foreign_key: :target_id
|
||||
belongs_to :custom_emoji, foreign_key: :target_id
|
||||
belongs_to :canonical_email_block, foreign_key: :target_id
|
||||
belongs_to :appeal, foreign_key: :target_id
|
||||
end
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
AdminActionLog.includes(:account).where(target_type: 'Account', human_identifier: nil).find_each do |log|
|
||||
next if log.account.nil?
|
||||
log.update(human_identifier: log.account.acct)
|
||||
end
|
||||
|
||||
AdminActionLog.includes(user: :account).where(target_type: 'User', human_identifier: nil).find_each do |log|
|
||||
next if log.user.nil?
|
||||
log.update(human_identifier: log.user.account.acct, route_param: log.user.account_id)
|
||||
end
|
||||
|
||||
Admin::ActionLog.where(target_type: 'Report', human_identifier: nil).in_batches.update_all('human_identifier = target_id::text')
|
||||
|
||||
AdminActionLog.includes(:domain_block).where(target_type: 'DomainBlock').find_each do |log|
|
||||
next if log.domain_block.nil?
|
||||
log.update(human_identifier: log.domain_block.domain)
|
||||
end
|
||||
|
||||
AdminActionLog.includes(:domain_allow).where(target_type: 'DomainAllow').find_each do |log|
|
||||
next if log.domain_allow.nil?
|
||||
log.update(human_identifier: log.domain_allow.domain)
|
||||
end
|
||||
|
||||
AdminActionLog.includes(:email_domain_block).where(target_type: 'EmailDomainBlock').find_each do |log|
|
||||
next if log.email_domain_block.nil?
|
||||
log.update(human_identifier: log.email_domain_block.domain)
|
||||
end
|
||||
|
||||
AdminActionLog.includes(:unavailable_domain).where(target_type: 'UnavailableDomain').find_each do |log|
|
||||
next if log.unavailable_domain.nil?
|
||||
log.update(human_identifier: log.unavailable_domain.domain)
|
||||
end
|
||||
|
||||
AdminActionLog.includes(status: :account).where(target_type: 'Status', human_identifier: nil).find_each do |log|
|
||||
next if log.status.nil?
|
||||
log.update(human_identifier: log.status.account.acct, permalink: log.status.uri)
|
||||
end
|
||||
|
||||
AdminActionLog.includes(account_warning: :account).where(target_type: 'AccountWarning', human_identifier: nil).find_each do |log|
|
||||
next if log.account_warning.nil?
|
||||
log.update(human_identifier: log.account_warning.account.acct)
|
||||
end
|
||||
|
||||
AdminActionLog.includes(:announcement).where(target_type: 'Announcement', human_identifier: nil).find_each do |log|
|
||||
next if log.announcement.nil?
|
||||
log.update(human_identifier: log.announcement.text)
|
||||
end
|
||||
|
||||
AdminActionLog.includes(:ip_block).where(target_type: 'IpBlock', human_identifier: nil).find_each do |log|
|
||||
next if log.ip_block.nil?
|
||||
log.update(human_identifier: "#{log.ip_block.ip}/#{log.ip_block.ip.prefix}")
|
||||
end
|
||||
|
||||
AdminActionLog.includes(:custom_emoji).where(target_type: 'CustomEmoji', human_identifier: nil).find_each do |log|
|
||||
next if log.custom_emoji.nil?
|
||||
log.update(human_identifier: log.custom_emoji.shortcode)
|
||||
end
|
||||
|
||||
AdminActionLog.includes(:canonical_email_block).where(target_type: 'CanonicalEmailBlock', human_identifier: nil).find_each do |log|
|
||||
next if log.canonical_email_block.nil?
|
||||
log.update(human_identifier: log.canonical_email_block.canonical_email_hash)
|
||||
end
|
||||
|
||||
AdminActionLog.includes(appeal: :account).where(target_type: 'Appeal', human_identifier: nil).find_each do |log|
|
||||
next if log.appeal.nil?
|
||||
log.update(human_identifier: log.appeal.account.acct, route_param: log.appeal.account_warning_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down; end
|
||||
end
|
98
db/schema.rb
98
db/schema.rb
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
ActiveRecord::Schema.define(version: 2022_11_04_133904) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -205,9 +205,11 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.string "action", default: "", null: false
|
||||
t.string "target_type"
|
||||
t.bigint "target_id"
|
||||
t.text "recorded_changes", default: "", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "human_identifier"
|
||||
t.string "route_param"
|
||||
t.string "permalink"
|
||||
t.index ["account_id"], name: "index_admin_action_logs_on_account_id"
|
||||
t.index ["target_type", "target_id"], name: "index_admin_action_logs_on_target_type_and_target_id"
|
||||
end
|
||||
@@ -294,7 +296,7 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
|
||||
create_table "canonical_email_blocks", force: :cascade do |t|
|
||||
t.string "canonical_email_hash", default: "", null: false
|
||||
t.bigint "reference_account_id", null: false
|
||||
t.bigint "reference_account_id"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["canonical_email_hash"], name: "index_canonical_email_blocks_on_canonical_email_hash", unique: true
|
||||
@@ -339,15 +341,32 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.index ["shortcode", "domain"], name: "index_custom_emojis_on_shortcode_and_domain", unique: true
|
||||
end
|
||||
|
||||
create_table "custom_filter_keywords", force: :cascade do |t|
|
||||
t.bigint "custom_filter_id", null: false
|
||||
t.text "keyword", default: "", null: false
|
||||
t.boolean "whole_word", default: true, null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["custom_filter_id"], name: "index_custom_filter_keywords_on_custom_filter_id"
|
||||
end
|
||||
|
||||
create_table "custom_filter_statuses", force: :cascade do |t|
|
||||
t.bigint "custom_filter_id", null: false
|
||||
t.bigint "status_id", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["custom_filter_id"], name: "index_custom_filter_statuses_on_custom_filter_id"
|
||||
t.index ["status_id"], name: "index_custom_filter_statuses_on_status_id"
|
||||
end
|
||||
|
||||
create_table "custom_filters", force: :cascade do |t|
|
||||
t.bigint "account_id"
|
||||
t.datetime "expires_at"
|
||||
t.text "phrase", default: "", null: false
|
||||
t.string "context", default: [], null: false, array: true
|
||||
t.boolean "irreversible", default: false, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "whole_word", default: true, null: false
|
||||
t.integer "action", default: 0, null: false
|
||||
t.index ["account_id"], name: "index_custom_filters_on_account_id"
|
||||
end
|
||||
|
||||
@@ -423,7 +442,8 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.datetime "last_status_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_featured_tags_on_account_id"
|
||||
t.string "name"
|
||||
t.index ["account_id", "tag_id"], name: "index_featured_tags_on_account_id_and_tag_id", unique: true
|
||||
t.index ["tag_id"], name: "index_featured_tags_on_tag_id"
|
||||
end
|
||||
|
||||
@@ -442,6 +462,7 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.boolean "show_reblogs", default: true, null: false
|
||||
t.string "uri"
|
||||
t.boolean "notify", default: false, null: false
|
||||
t.string "languages", array: true
|
||||
t.index ["account_id", "target_account_id"], name: "index_follow_requests_on_account_id_and_target_account_id", unique: true
|
||||
end
|
||||
|
||||
@@ -453,6 +474,7 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.boolean "show_reblogs", default: true, null: false
|
||||
t.string "uri"
|
||||
t.boolean "notify", default: false, null: false
|
||||
t.string "languages", array: true
|
||||
t.index ["account_id", "target_account_id"], name: "index_follows_on_account_id_and_target_account_id", unique: true
|
||||
t.index ["target_account_id"], name: "index_follows_on_target_account_id"
|
||||
end
|
||||
@@ -500,6 +522,7 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.inet "ip", default: "0.0.0.0", null: false
|
||||
t.integer "severity", default: 0, null: false
|
||||
t.text "comment", default: "", null: false
|
||||
t.index ["ip"], name: "index_ip_blocks_on_ip", unique: true
|
||||
end
|
||||
|
||||
create_table "list_accounts", force: :cascade do |t|
|
||||
@@ -714,6 +737,15 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.index ["domain"], name: "index_preview_card_providers_on_domain", unique: true
|
||||
end
|
||||
|
||||
create_table "preview_card_trends", force: :cascade do |t|
|
||||
t.bigint "preview_card_id", null: false
|
||||
t.float "score", default: 0.0, null: false
|
||||
t.integer "rank", default: 0, null: false
|
||||
t.boolean "allowed", default: false, null: false
|
||||
t.string "language"
|
||||
t.index ["preview_card_id"], name: "index_preview_card_trends_on_preview_card_id", unique: true
|
||||
end
|
||||
|
||||
create_table "preview_cards", force: :cascade do |t|
|
||||
t.string "url", default: "", null: false
|
||||
t.string "title", default: "", null: false
|
||||
@@ -836,6 +868,7 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.json "meta"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "blurhash"
|
||||
t.index ["var"], name: "index_site_uploads_on_var", unique: true
|
||||
end
|
||||
|
||||
@@ -873,6 +906,17 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.index ["status_id"], name: "index_status_stats_on_status_id", unique: true
|
||||
end
|
||||
|
||||
create_table "status_trends", force: :cascade do |t|
|
||||
t.bigint "status_id", null: false
|
||||
t.bigint "account_id", null: false
|
||||
t.float "score", default: 0.0, null: false
|
||||
t.integer "rank", default: 0, null: false
|
||||
t.boolean "allowed", default: false, null: false
|
||||
t.string "language"
|
||||
t.index ["account_id"], name: "index_status_trends_on_account_id"
|
||||
t.index ["status_id"], name: "index_status_trends_on_status_id", unique: true
|
||||
end
|
||||
|
||||
create_table "statuses", id: :bigint, default: -> { "timestamp_id('statuses'::text)" }, force: :cascade do |t|
|
||||
t.string "uri"
|
||||
t.text "text", default: "", null: false
|
||||
@@ -922,6 +966,15 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "tag_follows", force: :cascade do |t|
|
||||
t.bigint "tag_id", null: false
|
||||
t.bigint "account_id", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["account_id", "tag_id"], name: "index_tag_follows_on_account_id_and_tag_id", unique: true
|
||||
t.index ["tag_id"], name: "index_tag_follows_on_tag_id"
|
||||
end
|
||||
|
||||
create_table "tags", force: :cascade do |t|
|
||||
t.string "name", default: "", null: false
|
||||
t.datetime "created_at", null: false
|
||||
@@ -934,6 +987,7 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.datetime "last_status_at"
|
||||
t.float "max_score"
|
||||
t.datetime "max_score_at"
|
||||
t.string "display_name"
|
||||
t.index "lower((name)::text) text_pattern_ops", name: "index_tags_on_name_lower_btree", unique: true
|
||||
end
|
||||
|
||||
@@ -962,6 +1016,16 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.index ["user_id"], name: "index_user_invite_requests_on_user_id"
|
||||
end
|
||||
|
||||
create_table "user_roles", force: :cascade do |t|
|
||||
t.string "name", default: "", null: false
|
||||
t.string "color", default: "", null: false
|
||||
t.integer "position", default: 0, null: false
|
||||
t.bigint "permissions", default: 0, null: false
|
||||
t.boolean "highlighted", default: false, null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "email", default: "", null: false
|
||||
t.datetime "created_at", null: false
|
||||
@@ -985,7 +1049,6 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.boolean "otp_required_for_login", default: false, null: false
|
||||
t.datetime "last_emailed_at"
|
||||
t.string "otp_backup_codes", array: true
|
||||
t.string "filtered_languages", default: [], null: false, array: true
|
||||
t.bigint "account_id", null: false
|
||||
t.boolean "disabled", default: false, null: false
|
||||
t.boolean "moderator", default: false, null: false
|
||||
@@ -998,11 +1061,13 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.string "webauthn_id"
|
||||
t.inet "sign_up_ip"
|
||||
t.boolean "skip_sign_in_token"
|
||||
t.bigint "role_id"
|
||||
t.index ["account_id"], name: "index_users_on_account_id"
|
||||
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
||||
t.index ["created_by_application_id"], name: "index_users_on_created_by_application_id", where: "(created_by_application_id IS NOT NULL)"
|
||||
t.index ["email"], name: "index_users_on_email", unique: true
|
||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, opclass: :text_pattern_ops, where: "(reset_password_token IS NOT NULL)"
|
||||
t.index ["role_id"], name: "index_users_on_role_id", where: "(role_id IS NOT NULL)"
|
||||
end
|
||||
|
||||
create_table "web_push_subscriptions", force: :cascade do |t|
|
||||
@@ -1038,6 +1103,16 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
t.index ["user_id"], name: "index_webauthn_credentials_on_user_id"
|
||||
end
|
||||
|
||||
create_table "webhooks", force: :cascade do |t|
|
||||
t.string "url", null: false
|
||||
t.string "events", default: [], null: false, array: true
|
||||
t.string "secret", default: "", null: false
|
||||
t.boolean "enabled", default: true, null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["url"], name: "index_webhooks_on_url", unique: true
|
||||
end
|
||||
|
||||
add_foreign_key "account_aliases", "accounts", on_delete: :cascade
|
||||
add_foreign_key "account_conversations", "accounts", on_delete: :cascade
|
||||
add_foreign_key "account_conversations", "conversations", on_delete: :cascade
|
||||
@@ -1075,6 +1150,9 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
add_foreign_key "canonical_email_blocks", "accounts", column: "reference_account_id", on_delete: :cascade
|
||||
add_foreign_key "conversation_mutes", "accounts", name: "fk_225b4212bb", on_delete: :cascade
|
||||
add_foreign_key "conversation_mutes", "conversations", on_delete: :cascade
|
||||
add_foreign_key "custom_filter_keywords", "custom_filters", on_delete: :cascade
|
||||
add_foreign_key "custom_filter_statuses", "custom_filters", on_delete: :cascade
|
||||
add_foreign_key "custom_filter_statuses", "statuses", on_delete: :cascade
|
||||
add_foreign_key "custom_filters", "accounts", on_delete: :cascade
|
||||
add_foreign_key "devices", "accounts", on_delete: :cascade
|
||||
add_foreign_key "devices", "oauth_access_tokens", column: "access_token_id", on_delete: :cascade
|
||||
@@ -1118,6 +1196,7 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
add_foreign_key "poll_votes", "polls", on_delete: :cascade
|
||||
add_foreign_key "polls", "accounts", on_delete: :cascade
|
||||
add_foreign_key "polls", "statuses", on_delete: :cascade
|
||||
add_foreign_key "preview_card_trends", "preview_cards", on_delete: :cascade
|
||||
add_foreign_key "report_notes", "accounts", on_delete: :cascade
|
||||
add_foreign_key "report_notes", "reports", on_delete: :cascade
|
||||
add_foreign_key "reports", "accounts", column: "action_taken_by_account_id", name: "fk_bca45b75fd", on_delete: :nullify
|
||||
@@ -1132,17 +1211,22 @@ ActiveRecord::Schema.define(version: 2022_04_29_101850) do
|
||||
add_foreign_key "status_pins", "accounts", name: "fk_d4cb435b62", on_delete: :cascade
|
||||
add_foreign_key "status_pins", "statuses", on_delete: :cascade
|
||||
add_foreign_key "status_stats", "statuses", on_delete: :cascade
|
||||
add_foreign_key "status_trends", "accounts", on_delete: :cascade
|
||||
add_foreign_key "status_trends", "statuses", on_delete: :cascade
|
||||
add_foreign_key "statuses", "accounts", column: "in_reply_to_account_id", name: "fk_c7fa917661", on_delete: :nullify
|
||||
add_foreign_key "statuses", "accounts", name: "fk_9bda1543f7", on_delete: :cascade
|
||||
add_foreign_key "statuses", "statuses", column: "in_reply_to_id", on_delete: :nullify
|
||||
add_foreign_key "statuses", "statuses", column: "reblog_of_id", on_delete: :cascade
|
||||
add_foreign_key "statuses_tags", "statuses", on_delete: :cascade
|
||||
add_foreign_key "statuses_tags", "tags", name: "fk_3081861e21", on_delete: :cascade
|
||||
add_foreign_key "tag_follows", "accounts", on_delete: :cascade
|
||||
add_foreign_key "tag_follows", "tags", on_delete: :cascade
|
||||
add_foreign_key "tombstones", "accounts", on_delete: :cascade
|
||||
add_foreign_key "user_invite_requests", "users", on_delete: :cascade
|
||||
add_foreign_key "users", "accounts", name: "fk_50500f500d", on_delete: :cascade
|
||||
add_foreign_key "users", "invites", on_delete: :nullify
|
||||
add_foreign_key "users", "oauth_applications", column: "created_by_application_id", on_delete: :nullify
|
||||
add_foreign_key "users", "user_roles", column: "role_id", on_delete: :nullify
|
||||
add_foreign_key "web_push_subscriptions", "oauth_access_tokens", column: "access_token_id", on_delete: :cascade
|
||||
add_foreign_key "web_push_subscriptions", "users", on_delete: :cascade
|
||||
add_foreign_key "web_settings", "users", name: "fk_11910667b2", on_delete: :cascade
|
||||
|
12
db/seeds.rb
12
db/seeds.rb
@@ -1,11 +1,5 @@
|
||||
Doorkeeper::Application.create!(name: 'Web', superapp: true, redirect_uri: Doorkeeper.configuration.native_redirect_uri, scopes: 'read write follow push')
|
||||
# frozen_string_literal: true
|
||||
|
||||
domain = ENV['LOCAL_DOMAIN'] || Rails.configuration.x.local_domain
|
||||
account = Account.find_or_initialize_by(id: -99, actor_type: 'Application', locked: true, username: domain)
|
||||
account.save!
|
||||
|
||||
if Rails.env.development?
|
||||
admin = Account.where(username: 'admin').first_or_initialize(username: 'admin')
|
||||
admin.save(validate: false)
|
||||
User.where(email: "admin@#{domain}").first_or_initialize(email: "admin@#{domain}", password: 'mastodonadmin', password_confirmation: 'mastodonadmin', confirmed_at: Time.now.utc, admin: true, account: admin, agreement: true, approved: true).save!
|
||||
Dir[Rails.root.join('db', 'seeds', '*.rb')].sort.each do |seed|
|
||||
load seed
|
||||
end
|
||||
|
1
db/seeds/01_web_app.rb
Normal file
1
db/seeds/01_web_app.rb
Normal file
@@ -0,0 +1 @@
|
||||
Doorkeeper::Application.create_with(name: 'Web', redirect_uri: Doorkeeper.configuration.native_redirect_uri, scopes: 'read write follow push').find_or_create_by(superapp: true)
|
1
db/seeds/02_instance_actor.rb
Normal file
1
db/seeds/02_instance_actor.rb
Normal file
@@ -0,0 +1 @@
|
||||
Account.create_with(actor_type: 'Application', locked: true, username: ENV['LOCAL_DOMAIN'] || Rails.configuration.x.local_domain).find_or_create_by(id: -99)
|
9
db/seeds/03_roles.rb
Normal file
9
db/seeds/03_roles.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
# Pre-create base role
|
||||
UserRole.everyone
|
||||
|
||||
# Create default roles defined in config file
|
||||
default_roles = YAML.load_file(Rails.root.join('config', 'roles.yml'))
|
||||
|
||||
default_roles.each do |_, config|
|
||||
UserRole.create_with(position: config['position'], permissions_as_keys: config['permissions'], highlighted: true).find_or_create_by(name: config['name'])
|
||||
end
|
8
db/seeds/04_admin.rb
Normal file
8
db/seeds/04_admin.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
if Rails.env.development?
|
||||
domain = ENV['LOCAL_DOMAIN'] || Rails.configuration.x.local_domain
|
||||
|
||||
admin = Account.where(username: 'admin').first_or_initialize(username: 'admin')
|
||||
admin.save(validate: false)
|
||||
|
||||
User.where(email: "admin@#{domain}").first_or_initialize(email: "admin@#{domain}", password: 'mastodonadmin', password_confirmation: 'mastodonadmin', confirmed_at: Time.now.utc, role: UserRole.find_by(name: 'Owner'), account: admin, agreement: true, approved: true).save!
|
||||
end
|
Reference in New Issue
Block a user