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
|
13
db/post_migrate/20181116184611_copy_account_stats_cleanup.rb
Normal file
13
db/post_migrate/20181116184611_copy_account_stats_cleanup.rb
Normal file
@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CopyAccountStatsCleanup < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
safety_assured do
|
||||
remove_column :accounts, :statuses_count, :integer, default: 0, null: false
|
||||
remove_column :accounts, :following_count, :integer, default: 0, null: false
|
||||
remove_column :accounts, :followers_count, :integer, default: 0, null: false
|
||||
end
|
||||
end
|
||||
end
|
76
db/schema.rb
76
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: 2018_10_26_034033) do
|
||||
ActiveRecord::Schema.define(version: 2019_01_03_124754) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -56,6 +56,43 @@ ActiveRecord::Schema.define(version: 2018_10_26_034033) do
|
||||
t.index ["target_account_id"], name: "index_account_pins_on_target_account_id"
|
||||
end
|
||||
|
||||
create_table "account_stats", force: :cascade do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "statuses_count", default: 0, null: false
|
||||
t.bigint "following_count", default: 0, null: false
|
||||
t.bigint "followers_count", default: 0, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "last_status_at"
|
||||
t.index ["account_id"], name: "index_account_stats_on_account_id", unique: true
|
||||
end
|
||||
|
||||
create_table "account_tag_stats", force: :cascade do |t|
|
||||
t.bigint "tag_id", null: false
|
||||
t.bigint "accounts_count", default: 0, null: false
|
||||
t.boolean "hidden", default: false, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["tag_id"], name: "index_account_tag_stats_on_tag_id", unique: true
|
||||
end
|
||||
|
||||
create_table "account_warning_presets", force: :cascade do |t|
|
||||
t.text "text", default: "", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "account_warnings", force: :cascade do |t|
|
||||
t.bigint "account_id"
|
||||
t.bigint "target_account_id"
|
||||
t.integer "action", default: 0, null: false
|
||||
t.text "text", default: "", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_account_warnings_on_account_id"
|
||||
t.index ["target_account_id"], name: "index_account_warnings_on_target_account_id"
|
||||
end
|
||||
|
||||
create_table "accounts", force: :cascade do |t|
|
||||
t.string "username", default: "", null: false
|
||||
t.string "domain"
|
||||
@ -85,9 +122,6 @@ ActiveRecord::Schema.define(version: 2018_10_26_034033) do
|
||||
t.boolean "suspended", default: false, null: false
|
||||
t.boolean "locked", default: false, null: false
|
||||
t.string "header_remote_url", default: "", null: false
|
||||
t.integer "statuses_count", default: 0, null: false
|
||||
t.integer "followers_count", default: 0, null: false
|
||||
t.integer "following_count", default: 0, null: false
|
||||
t.datetime "last_webfingered_at"
|
||||
t.string "inbox_url", default: "", null: false
|
||||
t.string "outbox_url", default: "", null: false
|
||||
@ -99,6 +133,8 @@ ActiveRecord::Schema.define(version: 2018_10_26_034033) do
|
||||
t.string "featured_collection_url"
|
||||
t.jsonb "fields"
|
||||
t.string "actor_type"
|
||||
t.boolean "discoverable"
|
||||
t.string "also_known_as", array: true
|
||||
t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
|
||||
t.index "lower((username)::text), lower((domain)::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
|
||||
t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id"
|
||||
@ -106,6 +142,13 @@ ActiveRecord::Schema.define(version: 2018_10_26_034033) do
|
||||
t.index ["url"], name: "index_accounts_on_url"
|
||||
end
|
||||
|
||||
create_table "accounts_tags", id: false, force: :cascade do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "tag_id", null: false
|
||||
t.index ["account_id", "tag_id"], name: "index_accounts_tags_on_account_id_and_tag_id"
|
||||
t.index ["tag_id", "account_id"], name: "index_accounts_tags_on_tag_id_and_account_id", unique: true
|
||||
end
|
||||
|
||||
create_table "admin_action_logs", force: :cascade do |t|
|
||||
t.bigint "account_id"
|
||||
t.string "action", default: "", null: false
|
||||
@ -228,12 +271,12 @@ ActiveRecord::Schema.define(version: 2018_10_26_034033) do
|
||||
t.index ["target_account_id"], name: "index_follows_on_target_account_id"
|
||||
end
|
||||
|
||||
create_table "identities", id: :serial, force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
create_table "identities", force: :cascade do |t|
|
||||
t.string "provider", default: "", null: false
|
||||
t.string "uid", default: "", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.bigint "user_id"
|
||||
t.index ["user_id"], name: "index_identities_on_user_id"
|
||||
end
|
||||
|
||||
@ -293,7 +336,9 @@ ActiveRecord::Schema.define(version: 2018_10_26_034033) do
|
||||
t.json "file_meta"
|
||||
t.bigint "account_id"
|
||||
t.text "description"
|
||||
t.bigint "scheduled_status_id"
|
||||
t.index ["account_id"], name: "index_media_attachments_on_account_id"
|
||||
t.index ["scheduled_status_id"], name: "index_media_attachments_on_scheduled_status_id"
|
||||
t.index ["shortcode"], name: "index_media_attachments_on_shortcode", unique: true
|
||||
t.index ["status_id"], name: "index_media_attachments_on_status_id"
|
||||
end
|
||||
@ -444,6 +489,14 @@ ActiveRecord::Schema.define(version: 2018_10_26_034033) do
|
||||
t.index ["target_account_id"], name: "index_reports_on_target_account_id"
|
||||
end
|
||||
|
||||
create_table "scheduled_statuses", force: :cascade do |t|
|
||||
t.bigint "account_id"
|
||||
t.datetime "scheduled_at"
|
||||
t.jsonb "params"
|
||||
t.index ["account_id"], name: "index_scheduled_statuses_on_account_id"
|
||||
t.index ["scheduled_at"], name: "index_scheduled_statuses_on_scheduled_at"
|
||||
end
|
||||
|
||||
create_table "session_activations", force: :cascade do |t|
|
||||
t.string "session_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
@ -596,8 +649,10 @@ ActiveRecord::Schema.define(version: 2018_10_26_034033) do
|
||||
t.bigint "invite_id"
|
||||
t.string "remember_token"
|
||||
t.string "chosen_languages", array: true
|
||||
t.bigint "created_by_application_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"
|
||||
t.index ["email"], name: "index_users_on_email", unique: true
|
||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||
end
|
||||
@ -630,6 +685,10 @@ ActiveRecord::Schema.define(version: 2018_10_26_034033) do
|
||||
add_foreign_key "account_moderation_notes", "accounts", column: "target_account_id"
|
||||
add_foreign_key "account_pins", "accounts", column: "target_account_id", on_delete: :cascade
|
||||
add_foreign_key "account_pins", "accounts", on_delete: :cascade
|
||||
add_foreign_key "account_stats", "accounts", on_delete: :cascade
|
||||
add_foreign_key "account_tag_stats", "tags", on_delete: :cascade
|
||||
add_foreign_key "account_warnings", "accounts", column: "target_account_id", on_delete: :cascade
|
||||
add_foreign_key "account_warnings", "accounts", on_delete: :nullify
|
||||
add_foreign_key "accounts", "accounts", column: "moved_to_account_id", on_delete: :nullify
|
||||
add_foreign_key "admin_action_logs", "accounts", on_delete: :cascade
|
||||
add_foreign_key "backups", "users", on_delete: :nullify
|
||||
@ -644,7 +703,7 @@ ActiveRecord::Schema.define(version: 2018_10_26_034033) do
|
||||
add_foreign_key "follow_requests", "accounts", name: "fk_76d644b0e7", on_delete: :cascade
|
||||
add_foreign_key "follows", "accounts", column: "target_account_id", name: "fk_745ca29eac", on_delete: :cascade
|
||||
add_foreign_key "follows", "accounts", name: "fk_32ed1b5560", on_delete: :cascade
|
||||
add_foreign_key "identities", "users", on_delete: :cascade
|
||||
add_foreign_key "identities", "users", name: "fk_bea040f377", on_delete: :cascade
|
||||
add_foreign_key "imports", "accounts", name: "fk_6db1b6e408", on_delete: :cascade
|
||||
add_foreign_key "invites", "users", on_delete: :cascade
|
||||
add_foreign_key "list_accounts", "accounts", on_delete: :cascade
|
||||
@ -652,6 +711,7 @@ ActiveRecord::Schema.define(version: 2018_10_26_034033) do
|
||||
add_foreign_key "list_accounts", "lists", on_delete: :cascade
|
||||
add_foreign_key "lists", "accounts", on_delete: :cascade
|
||||
add_foreign_key "media_attachments", "accounts", name: "fk_96dd81e81b", on_delete: :nullify
|
||||
add_foreign_key "media_attachments", "scheduled_statuses", on_delete: :nullify
|
||||
add_foreign_key "media_attachments", "statuses", on_delete: :nullify
|
||||
add_foreign_key "mentions", "accounts", name: "fk_970d43f9d1", on_delete: :cascade
|
||||
add_foreign_key "mentions", "statuses", on_delete: :cascade
|
||||
@ -670,6 +730,7 @@ ActiveRecord::Schema.define(version: 2018_10_26_034033) do
|
||||
add_foreign_key "reports", "accounts", column: "assigned_account_id", on_delete: :nullify
|
||||
add_foreign_key "reports", "accounts", column: "target_account_id", name: "fk_eb37af34f0", on_delete: :cascade
|
||||
add_foreign_key "reports", "accounts", name: "fk_4b81f7522c", on_delete: :cascade
|
||||
add_foreign_key "scheduled_statuses", "accounts", on_delete: :cascade
|
||||
add_foreign_key "session_activations", "oauth_access_tokens", column: "access_token_id", name: "fk_957e5bda89", on_delete: :cascade
|
||||
add_foreign_key "session_activations", "users", name: "fk_e5fda67334", on_delete: :cascade
|
||||
add_foreign_key "status_pins", "accounts", name: "fk_d4cb435b62", on_delete: :cascade
|
||||
@ -685,6 +746,7 @@ ActiveRecord::Schema.define(version: 2018_10_26_034033) do
|
||||
add_foreign_key "subscriptions", "accounts", name: "fk_9847d1cbb5", 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 "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
|
||||
|
@ -4,5 +4,5 @@ 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, admin: true, account: admin).save!
|
||||
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).save!
|
||||
end
|
||||
|
Reference in New Issue
Block a user