# frozen_string_literal: true

# This is a composite of the migrations generated by the gem Noticed
# with `rails noticed:install:migrations`. They are as per version 3.0
# of the gem: https://github.com/excid3/noticed/tree/v3.0.0/db/migrate,
# plus some tweaks to remove unnecessary code.
class CreateNoticedTables < ActiveRecord::Migration[8.1]
  def change
    create_table :noticed_events do |t|
      t.string :type
      t.belongs_to :record, :polymorphic => true
      t.integer :notifications_count

      if t.respond_to?(:jsonb)
        t.jsonb :params
      else
        t.json :params
      end

      t.timestamps
    end

    create_table :noticed_notifications do |t|
      t.string :type
      t.belongs_to :event, :null => false
      t.belongs_to :recipient, :polymorphic => true, :null => false
      t.datetime :read_at
      t.datetime :seen_at

      t.timestamps
    end
  end
end
