Revamp notification policy options (#31343)
This commit is contained in:
parent
e29c401f77
commit
cbdd8edf68
16 changed files with 442 additions and 109 deletions
11
db/migrate/20240808114841_add_new_notification_policies.rb
Normal file
11
db/migrate/20240808114841_add_new_notification_policies.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddNewNotificationPolicies < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :notification_policies, :for_not_following, :integer, default: 0, null: false
|
||||
add_column :notification_policies, :for_not_followers, :integer, default: 0, null: false
|
||||
add_column :notification_policies, :for_new_accounts, :integer, default: 0, null: false
|
||||
add_column :notification_policies, :for_private_mentions, :integer, default: 1, null: false
|
||||
add_column :notification_policies, :for_limited_accounts, :integer, default: 1, null: false
|
||||
end
|
||||
end
|
26
db/migrate/20240808124338_migrate_notifications_policy_v2.rb
Normal file
26
db/migrate/20240808124338_migrate_notifications_policy_v2.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MigrateNotificationsPolicyV2 < ActiveRecord::Migration[7.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
# Dummy classes, to make migration possible across version changes
|
||||
class NotificationPolicy < ApplicationRecord; end
|
||||
|
||||
def up
|
||||
NotificationPolicy.in_batches.update_all(<<~SQL.squish)
|
||||
for_not_following = CASE filter_not_following WHEN true THEN 1 ELSE 0 END,
|
||||
for_not_followers = CASE filter_not_following WHEN true THEN 1 ELSE 0 END,
|
||||
for_new_accounts = CASE filter_new_accounts WHEN true THEN 1 ELSE 0 END,
|
||||
for_private_mentions = CASE filter_private_mentions WHEN true THEN 1 ELSE 0 END
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
NotificationPolicy.in_batches.update_all(<<~SQL.squish)
|
||||
filter_not_following = CASE for_not_following WHEN 0 THEN false ELSE true END,
|
||||
filter_not_following = CASE for_not_followers WHEN 0 THEN false ELSE true END,
|
||||
filter_new_accounts = CASE for_new_accounts WHEN 0 THEN false ELSE true END,
|
||||
filter_private_mentions = CASE for_private_mentions WHEN 0 THEN false ELSE true END
|
||||
SQL
|
||||
end
|
||||
end
|
|
@ -0,0 +1,26 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class PostDeploymentMigrateNotificationsPolicyV2 < ActiveRecord::Migration[7.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
# Dummy classes, to make migration possible across version changes
|
||||
class NotificationPolicy < ApplicationRecord; end
|
||||
|
||||
def up
|
||||
NotificationPolicy.in_batches.update_all(<<~SQL.squish)
|
||||
for_not_following = CASE filter_not_following WHEN true THEN 1 ELSE 0 END,
|
||||
for_not_followers = CASE filter_not_following WHEN true THEN 1 ELSE 0 END,
|
||||
for_new_accounts = CASE filter_new_accounts WHEN true THEN 1 ELSE 0 END,
|
||||
for_private_mentions = CASE filter_private_mentions WHEN true THEN 1 ELSE 0 END
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
NotificationPolicy.in_batches.update_all(<<~SQL.squish)
|
||||
filter_not_following = CASE for_not_following WHEN 0 THEN false ELSE true END,
|
||||
filter_not_following = CASE for_not_followers WHEN 0 THEN false ELSE true END,
|
||||
filter_new_accounts = CASE for_new_accounts WHEN 0 THEN false ELSE true END,
|
||||
filter_private_mentions = CASE for_private_mentions WHEN 0 THEN false ELSE true END
|
||||
SQL
|
||||
end
|
||||
end
|
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DropOldPoliciesFromNotificationsPolicy < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
safety_assured do
|
||||
remove_column :notification_policies, :filter_not_following, :boolean, default: false, null: false
|
||||
remove_column :notification_policies, :filter_not_followers, :boolean, default: false, null: false
|
||||
remove_column :notification_policies, :filter_new_accounts, :boolean, default: false, null: false
|
||||
remove_column :notification_policies, :filter_private_mentions, :boolean, default: true, null: false
|
||||
end
|
||||
end
|
||||
end
|
11
db/schema.rb
11
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_07_24_181224) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_08_08_125420) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
@ -692,12 +692,13 @@ ActiveRecord::Schema[7.1].define(version: 2024_07_24_181224) do
|
|||
|
||||
create_table "notification_policies", force: :cascade do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.boolean "filter_not_following", default: false, null: false
|
||||
t.boolean "filter_not_followers", default: false, null: false
|
||||
t.boolean "filter_new_accounts", default: false, null: false
|
||||
t.boolean "filter_private_mentions", default: true, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "for_not_following", default: 0, null: false
|
||||
t.integer "for_not_followers", default: 0, null: false
|
||||
t.integer "for_new_accounts", default: 0, null: false
|
||||
t.integer "for_private_mentions", default: 1, null: false
|
||||
t.integer "for_limited_accounts", default: 1, null: false
|
||||
t.index ["account_id"], name: "index_notification_policies_on_account_id", unique: true
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue