--
-- IMS-LD Package Data Model for Level C
--
-- @author jopez@inv.it.uc3m.es
-- @creation-date oct-2006
--

create table imsld_notifications (
    notification_id     integer  
                        constraint imsld_notif_id_fk
                        references cr_revisions  
                        on delete cascade
                        constraint imsld_notif_id_pk
                        primary key, 
    imsld_id            integer
                        constraint imsld_notif_ii_fk
                        references cr_items     --imsld_imslds
                        not null,
    activity_id         integer
                        constraint imsld_notif_act_fk
                        references cr_items     --imsld_learning_activities/imsld_support_activities
                        not null,
    subject             text
);

create index imsld_notif_ii_idx on imsld_notifications(imsld_id);
create index imsld_notif_act_idx on imsld_notifications(activity_id);

comment on table imsld_notifications is '
Notifications of the on_completion elements are stored in this table. The rest of notificacions are stored along with the XML which contains them and dealed with in the running stage.';

create table imsld_notifications_history (
    run_id              integer
                        references imsld_runs,
    from_user_id        integer
                        references parties,
    notification_date   timestamptz,
    target_activity_id  integer
                        references cr_revisions,
    to_user_id          integer
                        references parties
);

comment on table imsld_notifications_history is '
Table used to keep track of the notifications';

