33 lines
1.2 KiB
SQL
33 lines
1.2 KiB
SQL
-- migrate:up
|
|
|
|
-- Personal calendars, apart from the courses and associations. Their events are not
|
|
-- tasks: nothing to check, only something happening at a time, maybe somewhere.
|
|
CREATE TABLE calendars (
|
|
id SERIAL PRIMARY KEY,
|
|
"name" TEXT NOT NULL,
|
|
-- Hex color of the events, e.g. `#2563eb`
|
|
color TEXT NOT NULL CHECK (color ~ '^#[0-9a-fA-F]{6}$')
|
|
);
|
|
|
|
-- An event of a personal calendar: a time range, or a single moment (a deadline, a
|
|
-- reminder) when `ends_at` is null. An all-day event goes from the midnight of its
|
|
-- first day to the midnight after its last one, in the time zone of the user.
|
|
CREATE TABLE events (
|
|
id SERIAL PRIMARY KEY,
|
|
calendar_id INTEGER NOT NULL REFERENCES calendars (id) ON DELETE CASCADE,
|
|
title TEXT NOT NULL,
|
|
"location" TEXT,
|
|
description TEXT,
|
|
starts_at TIMESTAMPTZ NOT NULL,
|
|
ends_at TIMESTAMPTZ,
|
|
all_day BOOLEAN NOT NULL DEFAULT FALSE,
|
|
CHECK (ends_at IS NULL OR ends_at > starts_at),
|
|
CHECK (NOT all_day OR ends_at IS NOT NULL)
|
|
);
|
|
|
|
CREATE INDEX events_starts_at_idx ON events (starts_at);
|
|
CREATE INDEX events_calendar_id_idx ON events (calendar_id);
|
|
|
|
-- migrate:down
|
|
DROP TABLE IF EXISTS events;
|
|
DROP TABLE IF EXISTS calendars;
|