Add index to `notifications.type` and make it non-nullable
This commit is contained in:
parent
b534dc0bb8
commit
7b831875b0
|
@ -3,6 +3,7 @@
|
|||
class AddTypeToNotifications < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
add_column :notifications, :type, :string
|
||||
add_index :notifications, :type
|
||||
|
||||
execute "UPDATE notifications SET type = 'Notification::Commented' WHERE target_type = 'Comment'"
|
||||
execute "UPDATE notifications SET type = 'Notification::QuestionAnswered' WHERE target_type = 'Answer'"
|
||||
|
@ -14,9 +15,12 @@ class AddTypeToNotifications < ActiveRecord::Migration[6.1]
|
|||
AND target_id IN (SELECT id FROM appendables WHERE type = 'Appendable::Reaction' AND parent_type = 'Answer');
|
||||
SQUIRREL
|
||||
execute "UPDATE notifications SET type = 'Notification::CommentSmiled' WHERE type IS NULL"
|
||||
|
||||
change_column_null :notifications, :type, false
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :notifications, :type
|
||||
remove_column :notifications, :type
|
||||
end
|
||||
end
|
||||
|
|
|
@ -116,9 +116,10 @@ ActiveRecord::Schema.define(version: 2022_07_20_190421) do
|
|||
t.boolean "new"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "type"
|
||||
t.string "type", null: false
|
||||
t.index ["new"], name: "index_notifications_on_new"
|
||||
t.index ["recipient_id"], name: "index_notifications_on_recipient_id"
|
||||
t.index ["type"], name: "index_notifications_on_type"
|
||||
end
|
||||
|
||||
create_table "profiles", force: :cascade do |t|
|
||||
|
|
Loading…
Reference in New Issue