Merge tag 'v2.7.0rc1' into instance_only_statuses
This commit is contained in:
12
db/migrate/20181116165755_create_account_stats.rb
Normal file
12
db/migrate/20181116165755_create_account_stats.rb
Normal file
@ -0,0 +1,12 @@
|
||||
class CreateAccountStats < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :account_stats do |t|
|
||||
t.belongs_to :account, null: false, foreign_key: { on_delete: :cascade }, index: { unique: true }
|
||||
t.bigint :statuses_count, null: false, default: 0
|
||||
t.bigint :following_count, null: false, default: 0
|
||||
t.bigint :followers_count, null: false, default: 0
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
54
db/migrate/20181116173541_copy_account_stats.rb
Normal file
54
db/migrate/20181116173541_copy_account_stats.rb
Normal file
@ -0,0 +1,54 @@
|
||||
class CopyAccountStats < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
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 >= 90500
|
||||
end
|
||||
|
||||
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|
|
||||
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
|
||||
Account.unscoped.select('id, statuses_count, following_count, followers_count, created_at, updated_at').find_each do |account|
|
||||
begin
|
||||
params = [[nil, account.id], [nil, account.statuses_count], [nil, account.following_count], [nil, account.followers_count], [nil, account.created_at], [nil, 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
|
||||
end
|
27
db/migrate/20181127130500_identity_id_to_bigint.rb
Normal file
27
db/migrate/20181127130500_identity_id_to_bigint.rb
Normal file
@ -0,0 +1,27 @@
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class IdentityIdToBigint < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
change_column_type_concurrently :identities, :id, :bigint
|
||||
cleanup_concurrent_column_type_change :identities, :id
|
||||
|
||||
change_column_type_concurrently :identities, :user_id, :bigint
|
||||
cleanup_concurrent_column_type_change :identities, :user_id
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
safety_assured do
|
||||
change_column_type_concurrently :identities, :id, :integer
|
||||
cleanup_concurrent_column_type_change :identities, :id
|
||||
|
||||
change_column_type_concurrently :identities, :user_id, :integer
|
||||
cleanup_concurrent_column_type_change :identities, :user_id
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,8 @@
|
||||
class CreateAccountsTagsJoinTable < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_join_table :accounts, :tags do |t|
|
||||
t.index [:account_id, :tag_id]
|
||||
t.index [:tag_id, :account_id], unique: true
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddDiscoverableToAccounts < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :accounts, :discoverable, :boolean
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddLastStatusAtToAccountStats < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :account_stats, :last_status_at, :datetime
|
||||
end
|
||||
end
|
11
db/migrate/20181204215309_create_account_tag_stats.rb
Normal file
11
db/migrate/20181204215309_create_account_tag_stats.rb
Normal file
@ -0,0 +1,11 @@
|
||||
class CreateAccountTagStats < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :account_tag_stats do |t|
|
||||
t.belongs_to :tag, null: false, foreign_key: { on_delete: :cascade }, index: { unique: true }
|
||||
t.bigint :accounts_count, default: 0, null: false
|
||||
t.boolean :hidden, default: false, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
15
db/migrate/20181207011115_downcase_custom_emoji_domains.rb
Normal file
15
db/migrate/20181207011115_downcase_custom_emoji_domains.rb
Normal file
@ -0,0 +1,15 @@
|
||||
class DowncaseCustomEmojiDomains < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
duplicates = CustomEmoji.connection.select_all('SELECT string_agg(id::text, \',\') AS ids FROM custom_emojis GROUP BY shortcode, lower(domain) HAVING count(*) > 1').to_hash
|
||||
|
||||
duplicates.each do |row|
|
||||
CustomEmoji.where(id: row['ids'].split(',')[0...-1]).destroy_all
|
||||
end
|
||||
|
||||
CustomEmoji.in_batches.update_all('domain = lower(domain)')
|
||||
end
|
||||
|
||||
def down; end
|
||||
end
|
12
db/migrate/20181213184704_create_account_warnings.rb
Normal file
12
db/migrate/20181213184704_create_account_warnings.rb
Normal file
@ -0,0 +1,12 @@
|
||||
class CreateAccountWarnings < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :account_warnings do |t|
|
||||
t.belongs_to :account, foreign_key: { on_delete: :nullify }
|
||||
t.belongs_to :target_account, foreign_key: { to_table: 'accounts', on_delete: :cascade }
|
||||
t.integer :action, null: false, default: 0
|
||||
t.text :text, null: false, default: ''
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,9 @@
|
||||
class CreateAccountWarningPresets < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :account_warning_presets do |t|
|
||||
t.text :text, null: false, default: ''
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,8 @@
|
||||
class AddCreatedByApplicationIdToUsers < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_reference :users, :created_by_application, foreign_key: { to_table: 'oauth_applications', on_delete: :nullify }, index: false
|
||||
add_index :users, :created_by_application_id, algorithm: :concurrently
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddAlsoKnownAsToAccounts < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :accounts, :also_known_as, :string, array: true
|
||||
end
|
||||
end
|
9
db/migrate/20190103124649_create_scheduled_statuses.rb
Normal file
9
db/migrate/20190103124649_create_scheduled_statuses.rb
Normal file
@ -0,0 +1,9 @@
|
||||
class CreateScheduledStatuses < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :scheduled_statuses do |t|
|
||||
t.belongs_to :account, foreign_key: { on_delete: :cascade }
|
||||
t.datetime :scheduled_at, index: true
|
||||
t.jsonb :params
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,8 @@
|
||||
class AddScheduledStatusIdToMediaAttachments < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_reference :media_attachments, :scheduled_status, foreign_key: { on_delete: :nullify }, index: false
|
||||
add_index :media_attachments, :scheduled_status_id, algorithm: :concurrently
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user