diff options
author | ThibG <thib@sitedethib.com> | 2018-07-10 10:52:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-10 10:52:18 +0200 |
commit | e6647ccf6d13030a91c7e635526e1e40a059ce31 (patch) | |
tree | eda07c40c934ab9a55d7847afe4af3e54bce86b8 /db | |
parent | c699b2d141d7aa910bd81ae5fe881ecec7039395 (diff) | |
parent | 402da8065c2b378cca6361f2c7252bd766f25dde (diff) |
Merge pull request #557 from ThibG/glitch-soc/tentative-merge
Merge upstream changes
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20180628181026_create_custom_filters.rb | 13 | ||||
-rw-r--r-- | db/migrate/20180707154237_add_whole_word_to_custom_filter.rb | 17 | ||||
-rw-r--r-- | db/migrate/20180707193142_migrate_filters.rb | 54 | ||||
-rw-r--r-- | db/schema.rb | 26 |
4 files changed, 98 insertions, 12 deletions
diff --git a/db/migrate/20180628181026_create_custom_filters.rb b/db/migrate/20180628181026_create_custom_filters.rb new file mode 100644 index 000000000..d19cf2e9d --- /dev/null +++ b/db/migrate/20180628181026_create_custom_filters.rb @@ -0,0 +1,13 @@ +class CreateCustomFilters < ActiveRecord::Migration[5.2] + def change + create_table :custom_filters do |t| + t.belongs_to :account, foreign_key: { on_delete: :cascade } + t.datetime :expires_at + t.text :phrase, null: false, default: '' + t.string :context, array: true, null: false, default: [] + t.boolean :irreversible, null: false, default: false + + t.timestamps + end + end +end diff --git a/db/migrate/20180707154237_add_whole_word_to_custom_filter.rb b/db/migrate/20180707154237_add_whole_word_to_custom_filter.rb new file mode 100644 index 000000000..63ecb8741 --- /dev/null +++ b/db/migrate/20180707154237_add_whole_word_to_custom_filter.rb @@ -0,0 +1,17 @@ +require Rails.root.join('lib', 'mastodon', 'migration_helpers') + +class AddWholeWordToCustomFilter < ActiveRecord::Migration[5.2] + include Mastodon::MigrationHelpers + + disable_ddl_transaction! + + def change + safety_assured do + add_column_with_default :custom_filters, :whole_word, :boolean, default: true, allow_null: false + end + end + + def down + remove_column :custom_filters, :whole_word + end +end diff --git a/db/migrate/20180707193142_migrate_filters.rb b/db/migrate/20180707193142_migrate_filters.rb new file mode 100644 index 000000000..455ce71ed --- /dev/null +++ b/db/migrate/20180707193142_migrate_filters.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index b3ff84965..cf42e80e9 100644 --- a/db/schema.rb +++ b/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_06_17_162849) 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" @@ -153,6 +153,18 @@ ActiveRecord::Schema.define(version: 2018_06_17_162849) do t.index ["shortcode", "domain"], name: "index_custom_emojis_on_shortcode_and_domain", unique: true end + create_table "custom_filters", force: :cascade do |t| + t.bigint "account_id" + t.datetime "expires_at" + t.text "phrase", default: "", null: false + t.string "context", default: [], null: false, array: true + t.boolean "irreversible", default: false, null: false + t.boolean "whole_word", default: true, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["account_id"], name: "index_custom_filters_on_account_id" + end + create_table "domain_blocks", force: :cascade do |t| t.string "domain", default: "", null: false t.datetime "created_at", null: false @@ -199,16 +211,6 @@ ActiveRecord::Schema.define(version: 2018_06_17_162849) 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 @@ -584,13 +586,13 @@ ActiveRecord::Schema.define(version: 2018_06_17_162849) do add_foreign_key "bookmarks", "statuses", on_delete: :cascade add_foreign_key "conversation_mutes", "accounts", name: "fk_225b4212bb", on_delete: :cascade add_foreign_key "conversation_mutes", "conversations", on_delete: :cascade + add_foreign_key "custom_filters", "accounts", on_delete: :cascade add_foreign_key "favourites", "accounts", name: "fk_5eb6c2b873", on_delete: :cascade add_foreign_key "favourites", "statuses", name: "fk_b0e856845e", on_delete: :cascade add_foreign_key "follow_requests", "accounts", column: "target_account_id", name: "fk_9291ec025d", on_delete: :cascade 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 |