mirror of https://github.com/mastodon/mastodon
Remove `thing_type` and `thing_id` columns from settings table (#31971)
parent
b82c791770
commit
17c02c9210
@ -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
|
@ -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
|
@ -1,5 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
Fabricator(:setting) do
|
||||
var 'var'
|
||||
var { sequence(:var) { |n| "var_#{n}" } }
|
||||
end
|
||||
|
Loading…
Reference in New Issue