Laying out a database schema for a calendar application

I have been struggling with the same problem, and I was actually toying with the “cache table” idea suggested above, but then I came across an alternative (suggested here) that doesn’t seem to have been represented yet.

Build a table containing all events

EventID (primary key)
Description
StartDate
PeriodType - days, weeks, months, years
PeriodFreq - # of days, weeks, etc between events
EndDate
... other attributes that can be modified

Then add a table for exceptions to these events. This table uses a composite key, made up of the EventID that maps to the event table, and an instance ID to pick the particular event in the series.

EventID (key)
InstanceID (key)
InstanceDate - the modified date of the exception 
IsCancelled - a flag to skip this date when traversing the series
... other attributes that can be modified

It seems to keep the event table normalised, and avoids splitting up series to handle exceptions.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)