mirror of
https://github.com/mastodon/mastodon.git
synced 2024-10-02 21:01:06 +02:00
Remove thing_type
and thing_id
columns from settings
table
This commit is contained in:
parent
6801afa12f
commit
14237476d8
@ -7,10 +7,8 @@
|
|||||||
# id :bigint(8) not null, primary key
|
# id :bigint(8) not null, primary key
|
||||||
# var :string not null
|
# var :string not null
|
||||||
# value :text
|
# value :text
|
||||||
# thing_type :string
|
|
||||||
# created_at :datetime
|
# created_at :datetime
|
||||||
# updated_at :datetime
|
# updated_at :datetime
|
||||||
# thing_id :bigint(8)
|
|
||||||
#
|
#
|
||||||
|
|
||||||
# This file is derived from a fork of the `rails-settings-cached` gem available at
|
# This file is derived from a fork of the `rails-settings-cached` gem available at
|
||||||
@ -46,10 +44,10 @@ class Setting < ApplicationRecord
|
|||||||
after_commit :rewrite_cache, on: %i(create update)
|
after_commit :rewrite_cache, on: %i(create update)
|
||||||
after_commit :expire_cache, on: %i(destroy)
|
after_commit :expire_cache, on: %i(destroy)
|
||||||
|
|
||||||
# Settings are server-wide settings only, but they were previously
|
self.ignored_columns += %w(
|
||||||
# used for users too. This can be dropped later with a database
|
thing_type
|
||||||
# migration dropping any scoped setting.
|
thing_id
|
||||||
default_scope { where(thing_type: nil, thing_id: nil) }
|
)
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
# get or set a variable with the variable as the called method
|
# get or set a variable with the variable as the called method
|
||||||
|
@ -13,6 +13,13 @@ class MigrateHideNetworkPreference < ActiveRecord::Migration[6.1]
|
|||||||
belongs_to :account
|
belongs_to :account
|
||||||
end
|
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
|
def up
|
||||||
Account.reset_column_information
|
Account.reset_column_information
|
||||||
|
|
||||||
|
19
db/post_migrate/20240918170954_remove_settings_thing.rb
Normal file
19
db/post_migrate/20240918170954_remove_settings_thing.rb
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class RemoveSettingsThing < ActiveRecord::Migration[7.1]
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
def change
|
||||||
|
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
|
||||||
|
end
|
@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.1].define(version: 2024_09_16_190140) do
|
ActiveRecord::Schema[7.1].define(version: 2024_09_18_170954) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
@ -935,11 +935,9 @@ ActiveRecord::Schema[7.1].define(version: 2024_09_16_190140) do
|
|||||||
create_table "settings", force: :cascade do |t|
|
create_table "settings", force: :cascade do |t|
|
||||||
t.string "var", null: false
|
t.string "var", null: false
|
||||||
t.text "value"
|
t.text "value"
|
||||||
t.string "thing_type"
|
|
||||||
t.datetime "created_at", precision: nil
|
t.datetime "created_at", precision: nil
|
||||||
t.datetime "updated_at", precision: nil
|
t.datetime "updated_at", precision: nil
|
||||||
t.bigint "thing_id"
|
t.index ["var"], name: "index_settings_on_var", unique: true
|
||||||
t.index ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "severed_relationships", force: :cascade do |t|
|
create_table "severed_relationships", force: :cascade do |t|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
Fabricator(:setting) do
|
Fabricator(:setting) do
|
||||||
var 'var'
|
var { sequence(:var) { |n| "var_#{n}" } }
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user