diff --git a/legacyworlds-server-data/db-structure/parts/030-data/170-events.sql b/legacyworlds-server-data/db-structure/parts/030-data/170-events.sql index 40350e8..dd76220 100644 --- a/legacyworlds-server-data/db-structure/parts/030-data/170-events.sql +++ b/legacyworlds-server-data/db-structure/parts/030-data/170-events.sql @@ -27,6 +27,12 @@ CREATE TABLE events.event_definitions( evdef_adjustable BOOLEAN NOT NULL ); +/* Unique index allowing the custom priorities table to reference only + * adjustable event types. + */ +CREATE UNIQUE INDEX idx_evdef_adjustables + ON events.event_definitions( evdef_id , evdef_adjustable ); + GRANT SELECT ON events.event_definitions TO :dbuser; @@ -161,6 +167,45 @@ ALTER TABLE events.field_definitions GRANT SELECT ON events.field_definitions TO :dbuser; +/* + * Custom event priorities + * ----------------------- + * + * This table stores player-defined event priority overrides. Only events + * with custom priorities may be present in this table. + */ +DROP TABLE IF EXISTS events.custom_priorities CASCADE; +CREATE TABLE events.custom_priorities( + /* Identifier of the event type */ + evdef_id VARCHAR(48) NOT NULL , + + /* Used in reference to the event types - forces this table to + * reference only events that *can* be customised. + */ + evdef_adjustable BOOLEAN NOT NULL DEFAULT TRUE + CHECK( evdef_adjustable ) , + + /* Account identifier */ + address_id INT NOT NULL , + + /* Custom priority */ + evcp_priority INT NOT NULL + CHECK( evcp_priority BETWEEN 0 AND 4 ) , + + /* Use the event identifier and "adjustable" set value as the primary + * key. The advantage is that we get an index on both fields. + */ + PRIMARY KEY( evdef_id , evdef_adjustable ) +); + +ALTER TABLE events.custom_priorities + ADD CONSTRAINT fk_evcp_evdef + FOREIGN KEY ( evdef_id , evdef_adjustable ) + REFERENCES events.event_definitions ( evdef_id , evdef_adjustable ); + +GRANT SELECT ON events.custom_priorities TO :dbuser; + + /* * Event identifier sequence * -------------------------