I want to understand if my thesis is right about storing complex data as jsonb vs using columns to store the various keys inside the jsonb. My thesis is that with jsonb, eventually we have different versions of data. Adding an extra column should be more rigid, but we will not have an older version of jsonb which can lead to undexpected data.
example, I was building how to store recurring events of a Google Calendar.
A simple approach is to use this data structure:
CREATE TABLE recurring_events (
id SERIAL PRIMARY KEY,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
recurrence_start_time TIME,
recurrence_end_time TIME,
recurrence_type VARCHAR(20),
recurrence_info JSONB,
recurrence_end TIMESTAMP
);
while following my thesis I revamped into this:
-- Table for storing recurring events
CREATE TABLE recurring_events (
id SERIAL PRIMARY KEY,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
recurrence_start_time TIME,
recurrence_end_time TIME,
recurrence_type VARCHAR(20),-- Type of recurrence (e.g., weekly, monthly, custom)
recurrence_interval INTEGER,-- Interval for custom recurrence (e.g., every 2 weeks)
recurrence_week_number INTEGER, -- Week number for monthly recurrence
recurrence_day_of_week VARCHAR(9), -- Day of the week for weekly recurrence
recurrence_day_of_month INTEGER,-- Day of the month for monthly recurrence
recurrence_month INTEGER, -- Month for yearly recurrence
recurrence_end TIMESTAMP
);