Event database access

Added tables that store event access interfaces and event states per
interface, as well as functions which allow events to be retrieved:
 * events.interfaces lists access interfaces,
 * events.unprocessed_events lists events which haven't been processed
for each type of interface, with a "pre-processed" flag
 * events.ep_read() is a set of function variants which will read events
 * events.ep_access() is a set of function variants which read events
then update their states.
This commit is contained in:
Emmanuel BENOîT 2012-07-03 10:32:15 +02:00
parent d7b14e3de9
commit d246f221f0
2 changed files with 784 additions and 0 deletions
legacyworlds-server-data/db-structure/parts/030-data

View file

@ -402,6 +402,66 @@ ALTER TABLE events.field_values
GRANT SELECT ON events.field_values TO :dbuser;
/*
* Event viewing interfaces
* ------------------------
*
* This table stores the list of interfaces which can be used to access the
* events. It allows the system to handle multiple types of event viewing or
* processing: for example the web interface and email notifications.
*/
CREATE TABLE events.interfaces(
/* A short string that identifies the interface */
evi_id VARCHAR(8) NOT NULL PRIMARY KEY ,
/* A description of the interface */
evi_descr TEXT NOT NULL
);
/* Directly insert interface types */
INSERT INTO events.interfaces( evi_id , evi_descr ) VALUES
( 'game' , 'The game''s main interface' ) ,
( 'mail' , 'The e-mail notifications system' );
/*
* Events to process
* -----------------
*
* This table stores the list of events which need to be processed for each
* interface.
*/
CREATE TABLE events.unprocessed_events(
/* The event's identifier */
event_id BIGINT NOT NULL ,
/* The interface's identifier */
evi_id VARCHAR(8) NOT NULL ,
/* Whether the interface has pre-processed the event, but not displayed
* or sent it yet. This is used with e.g. the email notification system,
* which waits for more events once a first event is ready. When the
* server restarts, the field is set back to FALSE.
*/
upe_preprocessed BOOLEAN NOT NULL
DEFAULT FALSE ,
/* Use both the event and interface as the primary key */
PRIMARY KEY( event_id , evi_id )
);
CREATE INDEX idx_unprocessed_interface
ON events.unprocessed_events( evi_id );
ALTER TABLE events.unprocessed_events
ADD CONSTRAINT fk_unprocessed_event
FOREIGN KEY ( event_id ) REFERENCES events.events_v2 ( event_id )
ON DELETE CASCADE ,
ADD CONSTRAINT fk_unprocessed_interface
FOREIGN KEY ( evi_id ) REFERENCES events.interfaces ( evi_id );
/*
* OLD B6M1 CODE BELOW!