diff options
Diffstat (limited to 'db/migrate')
-rw-r--r-- | db/migrate/046_add_last_event_id_to_alert_table.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/db/migrate/046_add_last_event_id_to_alert_table.rb b/db/migrate/046_add_last_event_id_to_alert_table.rb new file mode 100644 index 000000000..4e67fee5b --- /dev/null +++ b/db/migrate/046_add_last_event_id_to_alert_table.rb @@ -0,0 +1,13 @@ +class AddLastEventIdToAlertTable < ActiveRecord::Migration + def self.up + add_column :user_info_request_sent_alerts, :info_request_event_id, :integer, :default => nil + execute "ALTER TABLE user_info_request_sent_alerts ADD CONSTRAINT fk_user_info_request_sent_alert_info_request_event FOREIGN KEY (info_request_event_id) REFERENCES info_request_events(id)" + # The coalesce is because null values are considred not equal in SQL, and we want them + # to be considered equal for the purposes of this index. + execute "create unique index user_info_request_sent_alerts_unique_index on user_info_request_sent_alerts (user_id, info_request_id, alert_type, coalesce(info_request_event_id, -1))" + end + + def self.down + remove_column :user_info_request_sent_alerts, :info_request_event_id + end +end |