Skip to content

Commit

Permalink
add seed data and initial migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawken Rives committed May 20, 2024
1 parent 7dd7769 commit 4f59032
Show file tree
Hide file tree
Showing 34 changed files with 760 additions and 0 deletions.
22 changes: 22 additions & 0 deletions supabase/migrations/20240520215620_create_data_source.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
create table data_source (
id text not null primary key,
type text not null check (type in ('manual', 'automated-scrape', 'scrape')),
uri text check (
case
when type != 'manual' then uri is not null
end
)
);

comment on table data_source is 'the authoritative list of data sources, including manual data entry';

comment on column data_source.type is 'what type of source is this?';

comment on column data_source.uri is 'where did we start this scrape from?';

alter table data_source enable row level security;

create policy "data_source are viewable by everyone" on data_source for
select
to authenticated,
anon using (true);
24 changes: 24 additions & 0 deletions supabase/migrations/20240520215621_create_link.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
create table link
(
source text not null references data_source (id) on update cascade on delete cascade,
type text not null check (type in
('a-z', 'webcam', 'help', 'transit', 'contact', 'definition',
'app-link', 'app-faq', 'app-tool')),
uri text not null default '',
title text not null check (length(title) < 1024),
sort_title text null check (length(sort_title) < 1024),
subtitle text not null default '' check (length(subtitle) < 1024),
description text not null default '' check (length(description) < 65536),
tint_color text not null default '#fff',
text_color text not null default '#000',
image_uri text,
sort_group text not null default '',
primary key (type, title)
);

alter table link enable row level security;

create policy "link are viewable by everyone"
on link for select
to authenticated, anon
using ( true );
21 changes: 21 additions & 0 deletions supabase/migrations/20240520215622_create_dictionary.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
create table dictionary
(
id uuid not null default uuid_generate_v4() primary key,
source text not null references data_source (id) on update cascade on delete cascade,
uri text not null default '',
title text not null check (length(title) < 1024),
sort_title text null check (length(sort_title) < 1024),
subtitle text not null default '' check (length(subtitle) < 1024),
description text not null default '' check (length(description) < 65536),
tint_color text not null default '#fff',
text_color text not null default '#000',
image_uri text,
sort_group text not null generated always as ( left(upper(sort_title), 1) ) stored
);

alter table dictionary enable row level security;

create policy "dictionary is viewable by everyone"
on dictionary for select
to authenticated, anon
using ( true );
14 changes: 14 additions & 0 deletions supabase/migrations/20240520215623_create_metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
create table metadata
(
source text not null references data_source (id) on update cascade on delete cascade,
key text not null check (key in ('app-version', 'color-printer')),
value text not null default '' check (length(value) < 1024),
primary key (key, value)
);

alter table metadata enable row level security;

create policy "metadata is viewable by everyone"
on metadata for select
to authenticated, anon
using ( true );
14 changes: 14 additions & 0 deletions supabase/migrations/20240520215624_create_location_category.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
create table location_category
(
id uuid not null default uuid_generate_v4() primary key,
title text not null unique check (length(title) between 0 and 256),
sort_title text unique check (length(sort_title) between 0 and 256),
source text not null references data_source (id) on update cascade on delete cascade
);

alter table location_category enable row level security;

create policy "location_category is viewable by everyone"
on location_category for select
to authenticated, anon
using ( true );
26 changes: 26 additions & 0 deletions supabase/migrations/20240520215625_create_location.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
create table location
(
id uuid not null default uuid_generate_v4() primary key,
source text not null default 'manual',
within uuid references location (id) on update cascade on delete restrict,
category uuid not null references location_category (id) on update cascade on delete restrict, -- TODO: keep as 1-1, or allow multiple?
title text not null default '',
subtitle text not null default '',
abbreviation text not null default '',
room_number text not null default '',
outline_shape jsonb not null default '[]'::jsonb, -- geojson
coordinates jsonb not null default '[]'::jsonb,
-- todo: keep these?
banner_uri text not null default '',
icon_uri text not null default '',
website_uri text not null default '',
phone text not null default '',
email text not null default ''
);

alter table location enable row level security;

create policy "location is viewable by everyone"
on location for select
to authenticated, anon
using ( true );
24 changes: 24 additions & 0 deletions supabase/migrations/20240520215626_create_location_schedule.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
create table location_schedule
(
id uuid not null default uuid_generate_v4() primary key,
source text not null references data_source (id) on update cascade on delete cascade,
parent_schedule uuid null references location_schedule (id) on update cascade on delete cascade,
location_category uuid null references location_category (id),
location uuid null references location (id),
title text not null,
status text not null default 'open' check (status in ('open', 'closed')),
message text null check (case when status != 'open' then message is not null end),
active_from timestamptz not null,
active_until timestamptz null,
audience text not null default '*' check (audience in ('*', 'students', 'seniors', 'facstaff')),
constraint category_or_location check (case
when location_category is not null then location is null
when location is null then location_category is not null end)
);

alter table location_schedule enable row level security;

create policy "location_schedule is viewable by everyone"
on location_schedule for select
to authenticated, anon
using ( true );
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
create table location_schedule_timetable
(
id uuid not null default uuid_generate_v4() primary key,
source text not null references data_source (id),
location_schedule_id uuid not null references location_schedule (id),
days text not null,
open_at time not null,
open_for interval minute not null
);

alter table location_schedule_timetable enable row level security;

create policy "location_schedule_timetable is viewable by everyone"
on location_schedule_timetable for select
to authenticated, anon
using ( true );
25 changes: 25 additions & 0 deletions supabase/migrations/20240520215628_create_directory_entry.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
create table directory_entry
(
id uuid not null default uuid_generate_v4() primary key,
source text not null references data_source (id) on update cascade on delete cascade,
name text not null,
sort_name text not null,
-- todo: do we need this field?
type text not null check (type in ('individual', 'department', 'organization')),
phone text,
email text,
pronouns text,
profile_uri text,
profile_text text,
title text,
photo text,
office_hours text,
specialties text
);

alter table directory_entry enable row level security;

create policy "directory_entry is viewable by everyone"
on directory_entry for select
to authenticated, anon
using ( true );
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- TODO: what is this for, again?
create table directory_entry_category
(
directory_entry uuid references directory_entry (id) on update cascade on delete cascade,
category text not null check (length(trim(category)) > 0)
);

alter table directory_entry_category enable row level security;

create policy "directory_entry_category is viewable by everyone"
on directory_entry_category for select
to authenticated, anon
using ( true );
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
create table directory_entry_location
(
directory_entry uuid not null references directory_entry (id) on update cascade on delete cascade,
location uuid not null references location (id) on update cascade on delete cascade,
source text not null references data_source (id) on update cascade on delete cascade,
title text,
email text,
phone text,
fax text,
hours text, -- can we use a schedule record for this? probably not...
description text
);

alter table directory_entry_location enable row level security;

create policy "directory_entry_location is viewable by everyone"
on directory_entry_location for select
to authenticated, anon
using ( true );
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
create table directory_entry_organization
(
directory_entry uuid not null references directory_entry (id) on update cascade on delete cascade,
directory_organization uuid not null references directory_entry (id) on update cascade on delete cascade,
source text not null references data_source (id) on update cascade on delete cascade,
role text, -- not sure if needed, or if can be replaced with title
title text,
email text,
phone text,
fax text,
hours text, -- can we use a schedule record for this? probably not...
description text
);

alter table directory_entry_organization enable row level security;

create policy "directory_entry_organization is viewable by everyone"
on directory_entry_organization for select
to authenticated, anon
using ( true );
13 changes: 13 additions & 0 deletions supabase/migrations/20240520215632_create_content_category.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
create table content_category
(
id uuid not null default uuid_generate_v4() primary key,
title text not null unique check (length(title) between 0 and 256),
sort_title text null unique check (length(sort_title) between 0 and 256)
);

alter table content_category enable row level security;

create policy "content_category is viewable by everyone"
on content_category for select
to authenticated, anon
using ( true );
23 changes: 23 additions & 0 deletions supabase/migrations/20240520215633_create_calendar_event.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
create table calendar_event
(
id uuid not null default uuid_generate_v4() primary key,
source text not null references data_source (id) on update cascade on delete cascade,
recurrence_of_event_id uuid null references calendar_event (id) on update cascade on delete cascade,
start_time timestamptz not null,
end_time timestamptz not null check (end_time >= start_time),
title text not null check (length(title) > 0),
description text not null default '',
thumbnail_uri text null,
banner_uri text null,
sponsoring_entity uuid null references directory_entry (id) on update cascade on delete set null,
campus_location_id uuid null references location (id) on update cascade on delete set null,
textual_location text null,
constraint only_one_location check ( case when campus_location_id is not null then textual_location is null end )
);

alter table calendar_event enable row level security;

create policy "calendar_event is viewable by everyone"
on calendar_event for select
to authenticated, anon
using ( true );
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
create table calendar_event_category
(
calendar_event_id uuid not null references calendar_event (id) on update cascade on delete cascade,
category_id uuid not null references content_category (id) on update cascade on delete cascade,
source text not null references data_source (id) on update cascade on delete cascade,
primary key (calendar_event_id, category_id)
);

alter table calendar_event_category enable row level security;

create policy "calendar_event_category is viewable by everyone"
on calendar_event_category for select
to authenticated, anon
using ( true );
17 changes: 17 additions & 0 deletions supabase/migrations/20240520215635_create_calendar_event_link.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
create table calendar_event_link
(
calendar_event_id uuid not null references calendar_event (id) on update cascade on delete cascade,
source text not null references data_source (id) on update cascade on delete cascade,
href text not null,
title text not null,
content_type text,
link_mode text not null check (link_mode in ('a', 'stream')),
primary key (calendar_event_id, href)
);

alter table calendar_event_link enable row level security;

create policy "calendar_event_link is viewable by everyone"
on calendar_event_link for select
to authenticated, anon
using ( true );
14 changes: 14 additions & 0 deletions supabase/migrations/20240520215636_create_feed.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
create table feed
(
source text not null references data_source (id) on update cascade on delete cascade,
title text not null check (length(title) > 0),
uri text not null,
primary key (uri)
);

alter table feed enable row level security;

create policy "feed is viewable by everyone"
on feed for select
to authenticated, anon
using ( true );
22 changes: 22 additions & 0 deletions supabase/migrations/20240520215637_create_feed_article.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
create table feed_article
(
id uuid not null default uuid_generate_v4() primary key,
source text not null references data_source (id) on update cascade on delete cascade,
published_at timestamptz not null,
updated_at timestamptz null,
title text not null check (length(title) > 0),
body text not null default '',
thumbnail_uri text null,
banner_uri text null,
sponsoring_entity uuid null references directory_entry (id) on update cascade on delete set null,
campus_location_id uuid null references location (id) on update cascade on delete set null,
textual_location text null,
constraint only_one_location check ( case when campus_location_id is not null then textual_location is null end )
);

alter table feed_article enable row level security;

create policy "feed_article is viewable by everyone"
on feed_article for select
to authenticated, anon
using ( true );
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
create table feed_article_category
(
feed_article_id uuid not null references feed_article (id) on update cascade on delete cascade,
category_id uuid not null references content_category (id) on update cascade on delete cascade,
primary key (feed_article_id, category_id)
);

alter table feed_article_category enable row level security;

create policy "feed_article_category is viewable by everyone"
on feed_article_category for select
to authenticated, anon
using ( true );
21 changes: 21 additions & 0 deletions supabase/migrations/20240520215639_create_app_notice.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
create table app_notice
(
id uuid not null default uuid_generate_v4() primary key,
source text not null references data_source (id) on update cascade on delete cascade,
created_at timestamptz not null default current_timestamp,
title text not null,
subtitle text null,
body text null,
severity text not null check (severity in ('stop', 'note', 'caution', 'plain')), -- taken from https://developer.apple.com/documentation/corefoundation/1534483-alert_levels
active_from timestamptz null,
active_until timestamptz null,
app_version text null,
platform text null
);

alter table app_notice enable row level security;

create policy "app_notice is viewable by everyone"
on app_notice for select
to authenticated, anon
using ( true );
Loading

0 comments on commit 4f59032

Please sign in to comment.