-- Add up migration script here

-- Calendars
-- 1 - Cottage
-- 2 - Family tree
create table calendar (
    id integer not null primary key autoincrement,
    created_at integer not null default CURRENT_TIMESTAMP,
    created_by integer not null default 0,
    updated_at integer null default CURRENT_TIMESTAMP,
    updated_by integer not null default 0,
    name varchar(255) not null
)

-- Event types
-- 1 - Rental
-- 2 - Life event
create table calendar_event_types (
    id integer not null primary key autoincrement,
    created_at integer not null default CURRENT_TIMESTAMP,
    created_by integer not null default 0,
    updated_at integer null default CURRENT_TIMESTAMP,
    updated_by integer not null default 0,
    name varchar(255) not null
)

create table calendar_events (
    id integer not null primary key autoincrement,
    created_at integer not null default CURRENT_TIMESTAMP,
    created_by integer not null default 0,
    updated_at integer null default CURRENT_TIMESTAMP,
    updated_by integer not null default 0,
    calendar_id integer not null,
    event_type_id integer not null,
    title varchar(255) not null,
    description varchar(255) null,
    start_time integer null,
    end_time integer null,
    repeat_type integer not null default 0, -- 0 - None, 1 - Daily, 2 - Weekly, 3 - Monthly, 4 - Yearly, 5 - Day of week, 6 - Day of month
    repeat_interval integer not null default 0,
    celebrate boolean not null default 0

    foreign key (calendar_id) references calendar(id),
    foreign key (event_type_id) references calendar_event_types(id)
)
