We have a java backend application which stores events in a mysql database. The frontend…
- User
We have a java backend application which stores events in a mysql database. The frontend can get a list of events via a REST API. Now we want to implement recurring events. e.g. daily or weekly events. What is the best way to do it. Can you recommend a data schema and maybe some standards or libraries?
- Assistant
Designing a system for recurring events involves a few considerations. Here's a general approach you can take:
-
Data Schema: You can maintain two tables:
eventsandevent_occurrences.-
eventstable: This table stores the base event information such as event name, description, start date, end date, recurrence type (daily, weekly, monthly, yearly), recurrence interval (every 2 days, every 3 weeks, etc.), and end recurrence rule (never, after n occurrences, on a specific date).
-
-
- User
scheduling is not part of our use case. We just have to be able to return in the API response all the recurrence instances for a given time frame.
- Assistant
If scheduling is not part of your use case and you only need to return all recurrence instances for a given time frame, you can simplify the design as follows:
-
Data Schema: Maintain a single
eventstable with the following columns:event_id(unique identifier for the event)event_namedescriptionstart_time(start time of the first occurrence)end_time(end time of the first occurrence)recurrence_type(daily, weekly, monthly, yearly)recurrence_interval(number of recurrence units between occurrences)recurrence_unit(day, week, month, year)
-
- User
can you show me the code if we use the ICAL format for storing the recurrence rule.
And also show me the code if we want to use the "lib-recur" library
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.