Added event definition tables

* New events.event_definitions table
* New events.field_definitions table
* New types for event field type specification
This commit is contained in:
Emmanuel BENOîT 2012-06-28 12:40:47 +02:00
parent 071257786c
commit ff78c6a2d6

View file

@ -1,12 +1,170 @@
-- LegacyWorlds Beta 6 -- LegacyWorlds Beta 6
-- PostgreSQL database scripts -- PostgreSQL database scripts
-- --
-- Storage of events (internal messages) -- Storage of events
-- --
-- Copyright(C) 2004-2010, DeepClone Development -- Copyright(C) 2004-2012, DeepClone Development
-- -------------------------------------------------------- -- --------------------------------------------------------
/*
* Event type definitions
* -----------------------
*
* This table stores the "root" of event type definitions. Each definition is
* uniquely identifier by a short string.
*/
DROP TABLE IF EXISTS events.event_definitions CASCADE;
CREATE TABLE events.event_definitions(
/* The event definition identifier */
evdef_id VARCHAR( 48 ) NOT NULL PRIMARY KEY ,
/* The default priority of the events of this type */
evdef_priority INT NOT NULL
CHECK( evdef_priority BETWEEN 0 AND 4 ) ,
/* Whether the priority for this type of event may be adjusted */
evdef_adjustable BOOLEAN NOT NULL
);
GRANT SELECT ON events.event_definitions TO :dbuser;
/*
* General event field types
* --------------------------
*/
DROP TYPE IF EXISTS events.field_type CASCADE;
CREATE TYPE events.field_type AS ENUM(
/* A numeric event field */
'NUMERIC' ,
/* A raw text event field */
'TEXT' ,
/* A boolean event field */
'BOOL' ,
/* An internationalised text field */
'I18N' ,
/* A field which links to another game entity */
'ENTITY'
);
/*
* Entity field sub-types
* -----------------------
*
* FIXME: no message sub-type for now
*/
DROP TYPE IF EXISTS events.entity_field_type CASCADE;
CREATE TYPE events.entity_field_type AS ENUM(
/* An empire */
'EMP' ,
/* A planet */
'PLN' ,
/* A fleet */
'FLT' ,
/* A battle */
'BAT' ,
/* An administrator */
'ADM' ,
/* A bug report */
'BUG'
);
/*
* Event field definition
* -----------------------
*
* An event field definition can be associated with an event definition to
* specify which fields an event will possess.
*/
DROP TABLE IF EXISTS events.field_definitions CASCADE;
CREATE TABLE events.field_definitions (
/* Identifier of the event type definition */
evdef_id VARCHAR( 48 ) NOT NULL ,
/* Identifier of the field itself */
efdef_id VARCHAR( 48 ) NOT NULL ,
/* Whether the field is optional or mandatory */
efdef_optional BOOLEAN NOT NULL ,
/* General type of the event field */
efdef_type events.field_type NOT NULL ,
/* Entity type if the field is an entity */
efdef_entity events.entity_field_type ,
/* Whether the field should contain an integer or a real number, if the
* field is numeric.
*/
efdef_integer BOOLEAN ,
/* Minimal value or length of the field if it is either a numeric field or
* a text field.
*/
efdef_min NUMERIC ,
/* Maximal value or length of the field if it is either a numeric field or
* a text field.
*/
efdef_max NUMERIC ,
/* Use both the event type identifier and the field identifier as
* the primary key
*/
PRIMARY KEY( evdef_id , efdef_id ) ,
/* Entity type is NULL unless the field is an entity field */
CONSTRAINT ck_efdef_entity CHECK( CASE
WHEN efdef_type = 'ENTITY' THEN
efdef_entity IS NOT NULL
ELSE
efdef_entity IS NULL
END ) ,
/* Make sure the integer flag is set only when the field is numeric */
CONSTRAINT ck_efdef_numtype CHECK( CASE
WHEN efdef_type = 'NUMERIC' THEN
efdef_integer IS NOT NULL
ELSE
efdef_integer IS NULL
END ) ,
/* Minimal / maximal values only allowed for numerics and raw strings */
CONSTRAINT ck_efdef_hasminmax CHECK( CASE
WHEN efdef_type IN ( 'NUMERIC' , 'TEXT' ) THEN
TRUE
ELSE
efdef_min IS NULL AND efdef_max IS NULL
END ) ,
/* If both a minimal and maximal values are present, minimal must be lower
* than maximal.
*/
CONSTRAINT ck_efdef_minmaxvalues CHECK( CASE
WHEN efdef_min IS NULL OR efdef_max IS NULL THEN
TRUE
ELSE
efdef_min < efdef_max
END )
);
ALTER TABLE events.field_definitions
ADD CONSTRAINT fk_efdef_evdef
FOREIGN KEY ( evdef_id ) REFERENCES events.event_definitions
ON DELETE CASCADE;
GRANT SELECT ON events.field_definitions TO :dbuser;
/*
* OLD B6M1 CODE BELOW!
*/
CREATE TYPE event_type CREATE TYPE event_type
AS ENUM ( 'QUEUE' , 'EMPIRE' , 'FLEETS' , 'PLANET', 'ALLIANCE', 'ADMIN' , 'BUGS' ); AS ENUM ( 'QUEUE' , 'EMPIRE' , 'FLEETS' , 'PLANET', 'ALLIANCE', 'ADMIN' , 'BUGS' );