Merge remote-tracking branch 'parent/main' into upstream-20241206

This commit is contained in:
KMY 2024-12-06 12:17:45 +09:00
commit 3c3ee557d0
187 changed files with 1105 additions and 537 deletions

View file

@ -13,6 +13,13 @@ class MigrateHideNetworkPreference < ActiveRecord::Migration[6.1]
belongs_to :account
end
class Setting < ApplicationRecord
# Mirror the behavior of the `Setting` model at this point in db history
def value
YAML.safe_load(self[:value], permitted_classes: [ActiveSupport::HashWithIndifferentAccess, Symbol]) if self[:value].present?
end
end
def up
Account.reset_column_information

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
class CreateTagTrends < ActiveRecord::Migration[7.2]
def change
create_table :tag_trends do |t| # rubocop:disable Rails/CreateTableWithTimestamps
t.references :tag, null: false, foreign_key: { on_delete: :cascade }, index: false
t.float :score, null: false, default: 0
t.integer :rank, null: false, default: 0
t.boolean :allowed, null: false, default: false
t.string :language, null: false, default: ''
end
add_index :tag_trends, [:tag_id, :language], unique: true
end
end

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
class RemoveLegacyUserSettingsData < ActiveRecord::Migration[7.2]
def up
connection.execute(<<~SQL.squish)
DELETE FROM settings
WHERE
thing_type IS NOT NULL
AND thing_id IS NOT NULL
SQL
end
def down
raise ActiveRecord::IrreversibleMigration
end
end

View file

@ -0,0 +1,21 @@
# frozen_string_literal: true
class MoveTagTrendsToTable < ActiveRecord::Migration[7.2]
include Redisable
disable_ddl_transaction!
def up
redis.zrange('trending_tags:all', 0, -1, with_scores: true).each_slice(1_000) do |data|
TagTrend.upsert_all(data.map { |(tag_id, score)| { tag_id: tag_id, score: score, language: '', allowed: redis.zscore('trending_tags:allowed', tag_id).present? } }, unique_by: %w(tag_id language))
end
TagTrend.recalculate_ordered_rank
redis.del('trending_tags:allowed', 'trending_tags:all')
end
def down
raise ActiveRecord::IrreversibleMigration
end
end

View file

@ -0,0 +1,30 @@
# frozen_string_literal: true
class RemoveLegacyUserSettingsColumns < ActiveRecord::Migration[7.2]
disable_ddl_transaction!
def up
# In normal usage this should not find anything to delete
# Deletion here is already done in RemoveLegacyUserSettingsData migration
# and no data like this should be created from app at this point
# Deleting again out of caution
connection.execute(<<~SQL.squish)
DELETE FROM settings
WHERE
thing_type IS NOT NULL
AND thing_id IS NOT NULL
SQL
add_index :settings, :var, unique: true, algorithm: :concurrently
remove_index :settings, [:thing_type, :thing_id, :var], name: :index_settings_on_thing_type_and_thing_id_and_var, unique: true
safety_assured do
remove_column :settings, :thing_type, :string
remove_column :settings, :thing_id, :bigint
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.2].define(version: 2024_11_04_082851) do
ActiveRecord::Schema[7.2].define(version: 2024_12_05_135925) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -1267,11 +1267,9 @@ ActiveRecord::Schema[7.2].define(version: 2024_11_04_082851) do
create_table "settings", force: :cascade do |t|
t.string "var", null: false
t.text "value"
t.string "thing_type"
t.datetime "created_at", precision: nil
t.datetime "updated_at", precision: nil
t.bigint "thing_id"
t.index ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true
t.index ["var"], name: "index_settings_on_var", unique: true
end
create_table "severed_relationships", force: :cascade do |t|
@ -1449,6 +1447,15 @@ ActiveRecord::Schema[7.2].define(version: 2024_11_04_082851) do
t.index ["tag_id"], name: "index_tag_follows_on_tag_id"
end
create_table "tag_trends", force: :cascade do |t|
t.bigint "tag_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", default: "", null: false
t.index ["tag_id", "language"], name: "index_tag_trends_on_tag_id_and_language", unique: true
end
create_table "tags", force: :cascade do |t|
t.string "name", default: "", null: false
t.datetime "created_at", precision: nil, null: false
@ -1745,6 +1752,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_11_04_082851) do
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 "tag_trends", "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