Skip to content

Commit

Permalink
do edits in the schema :D
Browse files Browse the repository at this point in the history
  • Loading branch information
YazeedAlKhalaf committed Oct 27, 2024
1 parent 1fc7fea commit 73b261a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
16 changes: 16 additions & 0 deletions falak/pkg/store/migrations/000002_calendar_o_calendar.down.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
DROP INDEX IF EXISTS idx_calendar_account;
DROP INDEX IF EXISTS idx_event_calendar;
DROP INDEX IF EXISTS idx_event_dtstart;
DROP INDEX IF EXISTS idx_event_dtend;
DROP INDEX IF EXISTS idx_exception_event;
DROP INDEX IF EXISTS idx_alarm_event;

DROP TRIGGER IF EXISTS update_valarm_updated_at ON valarm;
DROP TABLE IF EXISTS valarm;

DROP TRIGGER IF EXISTS update_vevent_exception_updated_at ON vevent_exception;
DROP TABLE IF EXISTS vevent_exception;

DROP TRIGGER IF EXISTS update_vevent_updated_at ON vevent;
DROP TABLE IF EXISTS vevent;

DROP TRIGGER IF EXISTS update_vcalendar_updated_at ON vcalendar;
DROP TABLE IF EXISTS vcalendar;

DROP TRIGGER IF EXISTS update_calendar_accounts_updated_at ON calendar_accounts;
DROP TABLE IF EXISTS calendar_accounts;
29 changes: 13 additions & 16 deletions falak/pkg/store/migrations/000002_calendar_o_calendar.up.sql
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
-- 1. Calendar Accounts
CREATE TABLE calendar_accounts (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
customer_id UUID NOT NULL REFERENCES customer(id) ON DELETE CASCADE,
provider VARCHAR NOT NULL CHECK (provider IN ('local', 'caldav')),
-- CalDAV specific (NULL for local accounts)
url VARCHAR,
username VARCHAR,
credentials BYTEA,

created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),

CONSTRAINT unique_customer_provider UNIQUE (customer_id, provider, url)
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TRIGGER update_calendar_accounts_updated_at
BEFORE UPDATE ON calendar_accounts
FOR EACH ROW
EXECUTE FUNCTION update_modified_column();

-- 2. Calendars
CREATE TABLE vcalendar (
uid VARCHAR PRIMARY KEY,
account_id UUID NOT NULL REFERENCES calendar_accounts(id) ON DELETE CASCADE,

-- Required iCal fields
prodid VARCHAR NOT NULL,
version VARCHAR NOT NULL DEFAULT '2.0',
calscale VARCHAR DEFAULT 'GREGORIAN',

-- Calendar properties
display_name VARCHAR NOT NULL,
description TEXT,
color VARCHAR(7),
timezone VARCHAR DEFAULT 'UTC',
-- Sync metadata
sync_token VARCHAR,
sequence INTEGER DEFAULT 0,

created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
Expand All @@ -43,25 +35,31 @@ CREATE TRIGGER update_vcalendar_updated_at
FOR EACH ROW
EXECUTE FUNCTION update_modified_column();

-- 3. Events
CREATE TABLE vevent (
uid VARCHAR PRIMARY KEY,
calendar_uid VARCHAR NOT NULL REFERENCES vcalendar(uid) ON DELETE CASCADE,

-- Timing fields
dtstamp TIMESTAMPTZ NOT NULL,
dtstart TIMESTAMPTZ NOT NULL,
dtend TIMESTAMPTZ,
duration VARCHAR,

-- Event details
summary VARCHAR NOT NULL,
description TEXT,
location VARCHAR,

-- Event properties
status VARCHAR CHECK (status IN ('CONFIRMED', 'TENTATIVE', 'CANCELLED')),
classification VARCHAR CHECK (classification IN ('PUBLIC', 'PRIVATE', 'CONFIDENTIAL')),
transp VARCHAR CHECK (transp IN ('OPAQUE', 'TRANSPARENT')),

-- Recurrence fields
rrule VARCHAR,
rdate JSONB,
exdate JSONB,
sequence INTEGER DEFAULT 0,
etag VARCHAR,

created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
Expand All @@ -71,11 +69,12 @@ CREATE TRIGGER update_vevent_updated_at
FOR EACH ROW
EXECUTE FUNCTION update_modified_column();

-- 4. Event Exceptions
CREATE TABLE vevent_exception (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
event_uid VARCHAR NOT NULL REFERENCES vevent(uid) ON DELETE CASCADE,
recurrence_id TIMESTAMPTZ NOT NULL,

-- Overridable fields
summary VARCHAR,
description TEXT,
location VARCHAR,
Expand All @@ -93,7 +92,6 @@ CREATE TRIGGER update_vevent_exception_updated_at
FOR EACH ROW
EXECUTE FUNCTION update_modified_column();

-- 5. Alarms
CREATE TABLE valarm (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
event_uid VARCHAR NOT NULL REFERENCES vevent(uid) ON DELETE CASCADE,
Expand All @@ -113,7 +111,6 @@ CREATE TRIGGER update_valarm_updated_at
FOR EACH ROW
EXECUTE FUNCTION update_modified_column();

-- Indexes
CREATE INDEX idx_calendar_account ON vcalendar(account_id);
CREATE INDEX idx_event_calendar ON vevent(calendar_uid);
CREATE INDEX idx_event_dtstart ON vevent(dtstart);
Expand Down
15 changes: 5 additions & 10 deletions falak/pkg/store/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 73b261a

Please sign in to comment.