Clean notification model [SCI-9384]

This commit is contained in:
Anton 2023-10-12 11:47:29 +02:00
parent 726ff5e238
commit 2434cca42c
3 changed files with 6 additions and 6 deletions

View file

@ -1,7 +1,6 @@
# frozen_string_literal: true
class Notification < ApplicationRecord
has_many :user_notifications, inverse_of: :notification, dependent: :destroy
include Noticed::Model
belongs_to :recipient, polymorphic: true

View file

@ -5,8 +5,7 @@ class MigrateNotificationToNoticed < ActiveRecord::Migration[7.0]
add_column :notifications, :params, :jsonb, default: {}, null: false
add_column :notifications, :type, :string
add_column :notifications, :read_at, :datetime
add_column :notifications, :recipient_id, :bigint
add_column :notifications, :recipient_type, :string
add_reference :notifications, :recipient, polymorphic: true
type_mapping = {
0 => 'ActivityNotification',
@ -27,7 +26,7 @@ class MigrateNotificationToNoticed < ActiveRecord::Migration[7.0]
}
params[:error] = notification.type_of == 7 if new_type == 'DeliveryNotification'
notification.update(
notification.update!(
params: params,
type: new_type,
read_at: (user_notification.updated_at if user_notification.checked),
@ -38,7 +37,8 @@ class MigrateNotificationToNoticed < ActiveRecord::Migration[7.0]
)
end
Notification.where(type: nil).destroy_all
UserNotification.delete_all
Notification.where(type: nil).delete_all
change_column_null :notifications, :type, false

View file

@ -382,9 +382,10 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_11_103114) do
t.jsonb "params", default: {}, null: false
t.string "type", null: false
t.datetime "read_at"
t.bigint "recipient_id"
t.string "recipient_type"
t.bigint "recipient_id"
t.index ["created_at"], name: "index_notifications_on_created_at"
t.index ["recipient_type", "recipient_id"], name: "index_notifications_on_recipient"
end
create_table "oauth_access_grants", force: :cascade do |t|