Migrate glitch-soc keyword mutes to Mastodon's
Completely remove glitch-soc's Keyword Mutes, migrate existing database records to CustomFilters. Handling of client-side filters is still not implemented in the glitch-soc front-end.
This commit is contained in:
54
db/migrate/20180707193142_migrate_filters.rb
Normal file
54
db/migrate/20180707193142_migrate_filters.rb
Normal file
@ -0,0 +1,54 @@
|
||||
class MigrateFilters < ActiveRecord::Migration[5.2]
|
||||
class GlitchKeywordMute < ApplicationRecord
|
||||
# Dummy class, as we removed Glitch::KeywordMute
|
||||
belongs_to :account, required: true
|
||||
validates_presence_of :keyword
|
||||
end
|
||||
|
||||
class CustomFilter < ApplicationRecord
|
||||
# Dummy class, in case CustomFilter gets altered in the future
|
||||
belongs_to :account
|
||||
validates :phrase, :context, presence: true
|
||||
|
||||
before_validation :clean_up_contexts
|
||||
|
||||
private
|
||||
|
||||
def clean_up_contexts
|
||||
self.context = Array(context).map(&:strip).map(&:presence).compact
|
||||
end
|
||||
end
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
GlitchKeywordMute.find_each do |filter|
|
||||
filter.account.custom_filters.create!(
|
||||
phrase: filter.keyword,
|
||||
context: filter.apply_to_mentions ? %w(home public notifications) : %w(home public),
|
||||
whole_word: filter.whole_word,
|
||||
irreversible: true)
|
||||
end
|
||||
|
||||
drop_table :glitch_keyword_mutes
|
||||
end
|
||||
|
||||
def down
|
||||
create_table "glitch_keyword_mutes" do |t|
|
||||
t.references :account, null: false
|
||||
t.string :keyword, null: false
|
||||
t.boolean :whole_word, default: true, null: false
|
||||
t.boolean :apply_to_mentions, default: true, null: false
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_foreign_key :glitch_keyword_mutes, :accounts, on_delete: :cascade
|
||||
|
||||
CustomFilter.where(irreversible: true).find_each do |filter|
|
||||
GlitchKeywordMute.where(account: filter.account).create!(
|
||||
keyword: filter.phrase,
|
||||
whole_word: filter.whole_word,
|
||||
apply_to_mentions: filter.context.include?('notifications'))
|
||||
end
|
||||
end
|
||||
end
|
13
db/schema.rb
13
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_07_07_154237) do
|
||||
ActiveRecord::Schema.define(version: 2018_07_07_193142) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -211,16 +211,6 @@ ActiveRecord::Schema.define(version: 2018_07_07_154237) do
|
||||
t.index ["account_id", "target_account_id"], name: "index_follows_on_account_id_and_target_account_id", unique: true
|
||||
end
|
||||
|
||||
create_table "glitch_keyword_mutes", force: :cascade do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.string "keyword", null: false
|
||||
t.boolean "whole_word", default: true, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "apply_to_mentions", default: true, null: false
|
||||
t.index ["account_id"], name: "index_glitch_keyword_mutes_on_account_id"
|
||||
end
|
||||
|
||||
create_table "identities", id: :serial, force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.string "provider", default: "", null: false
|
||||
@ -603,7 +593,6 @@ ActiveRecord::Schema.define(version: 2018_07_07_154237) 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 "glitch_keyword_mutes", "accounts", on_delete: :cascade
|
||||
add_foreign_key "identities", "users", on_delete: :cascade
|
||||
add_foreign_key "imports", "accounts", name: "fk_6db1b6e408", on_delete: :cascade
|
||||
add_foreign_key "invites", "users", on_delete: :cascade
|
||||
|
Reference in New Issue
Block a user