4.2.0-Beta2 test update
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddShortcodeToMediaAttachments < ActiveRecord::Migration[5.0]
|
||||
class MigrationMediaAttachment < ApplicationRecord
|
||||
self.table_name = :media_attachments
|
||||
scope :local, -> { where(remote_url: '') }
|
||||
end
|
||||
|
||||
def up
|
||||
add_column :media_attachments, :shortcode, :string, null: true, default: nil
|
||||
add_index :media_attachments, :shortcode, unique: true
|
||||
|
||||
MigrationMediaAttachment.reset_column_information
|
||||
|
||||
# Migrate old links
|
||||
MediaAttachment.local.update_all('shortcode = id')
|
||||
MigrationMediaAttachment.local.update_all('shortcode = id')
|
||||
end
|
||||
|
||||
def down
|
||||
|
@@ -1,11 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddTypeToMediaAttachments < ActiveRecord::Migration[5.0]
|
||||
class MigrationMediaAttachment < ApplicationRecord
|
||||
self.table_name = :media_attachments
|
||||
enum type: [:image, :gifv, :video]
|
||||
IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'].freeze
|
||||
VIDEO_MIME_TYPES = ['video/webm', 'video/mp4'].freeze
|
||||
end
|
||||
|
||||
def up
|
||||
add_column :media_attachments, :type, :integer, default: 0, null: false
|
||||
|
||||
MediaAttachment.where(file_content_type: MediaAttachment::IMAGE_MIME_TYPES).update_all(type: MediaAttachment.types[:image])
|
||||
MediaAttachment.where(file_content_type: MediaAttachment::VIDEO_MIME_TYPES).update_all(type: MediaAttachment.types[:video])
|
||||
MigrationMediaAttachment.reset_column_information
|
||||
|
||||
MigrationMediaAttachment
|
||||
.where(file_content_type: MigrationMediaAttachment::IMAGE_MIME_TYPES)
|
||||
.update_all(type: MigrationMediaAttachment.types[:image])
|
||||
MigrationMediaAttachment
|
||||
.where(file_content_type: MigrationMediaAttachment::VIDEO_MIME_TYPES)
|
||||
.update_all(type: MigrationMediaAttachment.types[:video])
|
||||
end
|
||||
|
||||
def down
|
||||
|
@@ -7,9 +7,29 @@ class MigrateAccountConversations < ActiveRecord::Migration[5.2]
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
class Mention < ApplicationRecord
|
||||
belongs_to :account, inverse_of: :mentions
|
||||
belongs_to :status, -> { unscope(where: :deleted_at) }
|
||||
class MigrationAccount < ApplicationRecord
|
||||
self.table_name = :accounts
|
||||
has_many :mentions, inverse_of: :account, dependent: :destroy, class_name: 'MigrationMention', foreign_key: :account_id
|
||||
end
|
||||
|
||||
class MigrationConversation < ApplicationRecord
|
||||
self.table_name = :conversations
|
||||
end
|
||||
|
||||
class MigrationStatus < ApplicationRecord
|
||||
self.table_name = :statuses
|
||||
belongs_to :account, class_name: 'MigrationAccount'
|
||||
has_many :mentions, dependent: :destroy, inverse_of: :status, class_name: 'MigrationMention', foreign_key: :status_id
|
||||
scope :local, -> { where(local: true).or(where(uri: nil)) }
|
||||
enum visibility: { public: 0, unlisted: 1, private: 2, direct: 3, limited: 4 }, _suffix: :visibility
|
||||
has_many :active_mentions, -> { active }, class_name: 'MigrationMention', inverse_of: :status, foreign_key: :status_id
|
||||
end
|
||||
|
||||
class MigrationMention < ApplicationRecord
|
||||
self.table_name = :mentions
|
||||
belongs_to :account, inverse_of: :mentions, class_name: 'MigrationAccount'
|
||||
belongs_to :status, -> { unscope(where: :deleted_at) }, class_name: 'MigrationStatus'
|
||||
scope :active, -> { where(silent: false) }
|
||||
|
||||
delegate(
|
||||
:username,
|
||||
@@ -19,22 +39,24 @@ class MigrateAccountConversations < ActiveRecord::Migration[5.2]
|
||||
)
|
||||
end
|
||||
|
||||
class Notification < ApplicationRecord
|
||||
belongs_to :account, optional: true
|
||||
class MigrationNotification < ApplicationRecord
|
||||
self.table_name = :notifications
|
||||
belongs_to :account, optional: true, class_name: 'MigrationAccount'
|
||||
belongs_to :activity, polymorphic: true, optional: true
|
||||
|
||||
belongs_to :status, foreign_key: 'activity_id', optional: true
|
||||
belongs_to :mention, foreign_key: 'activity_id', optional: true
|
||||
belongs_to :status, foreign_key: 'activity_id', optional: true, class_name: 'MigrationStatus'
|
||||
belongs_to :mention, foreign_key: 'activity_id', optional: true, class_name: 'MigrationMention'
|
||||
|
||||
def target_status
|
||||
mention&.status
|
||||
end
|
||||
end
|
||||
|
||||
class AccountConversation < ApplicationRecord
|
||||
belongs_to :account
|
||||
belongs_to :conversation
|
||||
belongs_to :last_status, -> { unscope(where: :deleted_at) }, class_name: 'Status'
|
||||
class MigrationAccountConversation < ApplicationRecord
|
||||
self.table_name = :account_conversations
|
||||
belongs_to :account, class_name: 'MigrationAccount'
|
||||
belongs_to :conversation, class_name: 'MigrationConversation'
|
||||
belongs_to :last_status, -> { unscope(where: :deleted_at) }, class_name: 'MigrationStatus'
|
||||
|
||||
before_validation :set_last_status
|
||||
|
||||
@@ -74,7 +96,7 @@ class MigrateAccountConversations < ActiveRecord::Migration[5.2]
|
||||
last_time = Time.zone.now
|
||||
|
||||
local_direct_statuses.includes(:account, mentions: :account).find_each do |status|
|
||||
AccountConversation.add_status(status.account, status)
|
||||
MigrationAccountConversation.add_status(status.account, status)
|
||||
migrated += 1
|
||||
|
||||
if Time.zone.now - last_time > 1
|
||||
@@ -84,7 +106,7 @@ class MigrateAccountConversations < ActiveRecord::Migration[5.2]
|
||||
end
|
||||
|
||||
notifications_about_direct_statuses.includes(:account, mention: { status: [:account, mentions: :account] }).find_each do |notification|
|
||||
AccountConversation.add_status(notification.account, notification.target_status)
|
||||
MigrationAccountConversation.add_status(notification.account, notification.target_status)
|
||||
migrated += 1
|
||||
|
||||
if Time.zone.now - last_time > 1
|
||||
@@ -103,10 +125,10 @@ class MigrateAccountConversations < ActiveRecord::Migration[5.2]
|
||||
end
|
||||
|
||||
def local_direct_statuses
|
||||
Status.unscoped.local.where(visibility: :direct)
|
||||
MigrationStatus.unscoped.local.where(visibility: :direct)
|
||||
end
|
||||
|
||||
def notifications_about_direct_statuses
|
||||
Notification.joins('INNER JOIN mentions ON mentions.id = notifications.activity_id INNER JOIN statuses ON statuses.id = mentions.status_id').where(activity_type: 'Mention', statuses: { visibility: :direct })
|
||||
MigrationNotification.joins('INNER JOIN mentions ON mentions.id = notifications.activity_id INNER JOIN statuses ON statuses.id = mentions.status_id').where(activity_type: 'Mention', statuses: { visibility: :direct })
|
||||
end
|
||||
end
|
||||
|
@@ -3,6 +3,10 @@
|
||||
class CopyAccountStats < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
class MigrationAccount < ApplicationRecord
|
||||
self.table_name = :accounts
|
||||
end
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
if supports_upsert?
|
||||
@@ -27,7 +31,7 @@ class CopyAccountStats < ActiveRecord::Migration[5.2]
|
||||
def up_fast
|
||||
say 'Upsert is available, importing counters using the fast method'
|
||||
|
||||
Account.unscoped.select('id').find_in_batches(batch_size: 5_000) do |accounts|
|
||||
MigrationAccount.unscoped.select('id').find_in_batches(batch_size: 5_000) do |accounts|
|
||||
execute <<-SQL.squish
|
||||
INSERT INTO account_stats (account_id, statuses_count, following_count, followers_count, created_at, updated_at)
|
||||
SELECT id, statuses_count, following_count, followers_count, created_at, updated_at
|
||||
@@ -44,7 +48,7 @@ class CopyAccountStats < ActiveRecord::Migration[5.2]
|
||||
|
||||
# We cannot use bulk INSERT or overarching transactions here because of possible
|
||||
# uniqueness violations that we need to skip over
|
||||
Account.unscoped.select('id, statuses_count, following_count, followers_count, created_at, updated_at').find_each do |account|
|
||||
MigrationAccount.unscoped.select('id, statuses_count, following_count, followers_count, created_at, updated_at').find_each do |account|
|
||||
params = [account.id, account[:statuses_count], account[:following_count], account[:followers_count], account.created_at, account.updated_at]
|
||||
exec_insert('INSERT INTO account_stats (account_id, statuses_count, following_count, followers_count, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6)', nil, params)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
|
62
db/migrate/20181116173541_copy_account_stats.rb.orig
Normal file
62
db/migrate/20181116173541_copy_account_stats.rb.orig
Normal file
@@ -0,0 +1,62 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CopyAccountStats < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
class MigrationAccount < ApplicationRecord
|
||||
self.table_name = :accounts
|
||||
end
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
if supports_upsert?
|
||||
up_fast
|
||||
else
|
||||
up_slow
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
# Nothing
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def supports_upsert?
|
||||
version = select_one("SELECT current_setting('server_version_num') AS v")['v'].to_i
|
||||
version >= 90_500
|
||||
end
|
||||
|
||||
def up_fast
|
||||
say 'Upsert is available, importing counters using the fast method'
|
||||
|
||||
MigrationAccount.unscoped.select('id').find_in_batches(batch_size: 5_000) do |accounts|
|
||||
execute <<-SQL.squish
|
||||
INSERT INTO account_stats (account_id, statuses_count, following_count, followers_count, created_at, updated_at)
|
||||
SELECT id, statuses_count, following_count, followers_count, created_at, updated_at
|
||||
FROM accounts
|
||||
WHERE id IN (#{accounts.map(&:id).join(', ')})
|
||||
ON CONFLICT (account_id) DO UPDATE
|
||||
SET statuses_count = EXCLUDED.statuses_count, following_count = EXCLUDED.following_count, followers_count = EXCLUDED.followers_count
|
||||
SQL
|
||||
end
|
||||
end
|
||||
|
||||
def up_slow
|
||||
say 'Upsert is not available in PostgreSQL below 9.5, falling back to slow import of counters'
|
||||
|
||||
# We cannot use bulk INSERT or overarching transactions here because of possible
|
||||
# uniqueness violations that we need to skip over
|
||||
<<<<<<< HEAD
|
||||
Account.unscoped.select('id, statuses_count, following_count, followers_count, created_at, updated_at').find_each do |account|
|
||||
=======
|
||||
MigrationAccount.unscoped.select('id, statuses_count, following_count, followers_count, created_at, updated_at').find_each do |account|
|
||||
>>>>>>> upstream/main
|
||||
params = [account.id, account[:statuses_count], account[:following_count], account[:followers_count], account.created_at, account.updated_at]
|
||||
exec_insert('INSERT INTO account_stats (account_id, statuses_count, following_count, followers_count, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6)', nil, params)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddImageDescriptionToPreviewCards < ActiveRecord::Migration[7.0]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { add_column_with_default :preview_cards, :image_description, :string, default: '', allow_null: false }
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :preview_cards, :image_description
|
||||
end
|
||||
end
|
17
db/migrate/20230814223300_add_indexable_to_accounts.rb
Normal file
17
db/migrate/20230814223300_add_indexable_to_accounts.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddIndexableToAccounts < ActiveRecord::Migration[7.0]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { add_column_with_default :accounts, :indexable, :boolean, default: false, allow_null: false }
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :accounts, :indexable
|
||||
end
|
||||
end
|
@@ -0,0 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CreateGlobalFollowRecommendations < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_view :global_follow_recommendations, materialized: { no_data: true }
|
||||
safety_assured { add_index :global_follow_recommendations, :account_id, unique: true }
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user