|
| 1 | +class CreateNotifications < ActiveRecord::Migration[7.1] |
| 2 | + def change |
| 3 | + create_table :notifications, id: :uuid do |t| |
| 4 | + t.references :user, type: :uuid, null: false, foreign_key: true |
| 5 | + |
| 6 | + t.string :title, limit: 200, null: false |
| 7 | + t.text :message, null: false |
| 8 | + t.string :type, null: false |
| 9 | + |
| 10 | + # Linking |
| 11 | + t.text :link_url |
| 12 | + t.string :link_type, limit: 20 |
| 13 | + t.uuid :link_id |
| 14 | + |
| 15 | + # Status |
| 16 | + t.boolean :is_read, default: false |
| 17 | + t.timestamp :read_at |
| 18 | + |
| 19 | + # Delivery channels |
| 20 | + t.text :channels, array: true, default: ['in_app'] |
| 21 | + t.boolean :email_sent, default: false |
| 22 | + t.boolean :discord_sent, default: false |
| 23 | + |
| 24 | + t.jsonb :metadata, default: {} |
| 25 | + |
| 26 | + t.timestamps null: false |
| 27 | + end |
| 28 | + |
| 29 | + add_index :notifications, :user_id |
| 30 | + add_index :notifications, :is_read |
| 31 | + add_index :notifications, :created_at, order: { created_at: :desc } |
| 32 | + |
| 33 | + # Add check constraint for notification type |
| 34 | + execute <<-SQL |
| 35 | + ALTER TABLE notifications |
| 36 | + ADD CONSTRAINT notifications_type_check |
| 37 | + CHECK (type IN ('info', 'success', 'warning', 'error', 'match', 'schedule', 'system')); |
| 38 | + SQL |
| 39 | + end |
| 40 | +end |
0 commit comments