Skip to content

Commit

Permalink
create indexes for foreign keys
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkrives committed May 24, 2024
1 parent 910cc59 commit dcddde2
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 22 deletions.
2 changes: 2 additions & 0 deletions supabase/migrations/20240520215621_create_link.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ create table link
primary key (type, title)
);

create index on link(source);

alter table link
enable row level security;

Expand Down
2 changes: 2 additions & 0 deletions supabase/migrations/20240520215622_create_dictionary.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ create table dictionary
sort_group text not null generated always as ( left(upper(sort_title), 1) ) stored
);

create index on dictionary(source);

alter table dictionary
enable row level security;

Expand Down
2 changes: 2 additions & 0 deletions supabase/migrations/20240520215623_create_metadata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ create table metadata
primary key (key, value)
);

create index on metadata(source);

alter table metadata
enable row level security;

Expand Down
10 changes: 8 additions & 2 deletions supabase/migrations/20240520215625_create_location.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ create table location
email text not null default ''
);

create index on location (source);
create index on location (within);

alter table location
enable row level security;

Expand All @@ -30,10 +33,12 @@ create table location_category
(
id uuid not null default gen_random_uuid() 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),
sort_title text null check (length(sort_title) between 0 and 256),
source text not null references data_source (id) on update cascade on delete cascade
);

create index on location_category (source);

alter table location_category
enable row level security;

Expand All @@ -46,7 +51,8 @@ create policy "Enable read access for all users"
create table location_category_mapping
(
location_id uuid not null references location (id),
location_category_id uuid not null references location_category (id)
location_category_id uuid not null references location_category (id),
primary key (location_id, location_category_id)
);

alter table location_category_mapping
Expand Down
20 changes: 14 additions & 6 deletions supabase/migrations/20240520215626_create_location_schedule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ create table location_schedule
when location is null then location_category is not null end)
);

create index on location_schedule (source);
create index on location_schedule (location);
create index on location_schedule (location_category);
create index on location_schedule (parent_schedule);

alter table location_schedule
enable row level security;

Expand All @@ -27,14 +32,17 @@ create policy "Enable read access for all users"

create table location_schedule_timetable
(
id uuid not null default gen_random_uuid() 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
id uuid not null default gen_random_uuid() primary key,
source text not null references data_source (id),
location_schedule uuid not null references location_schedule (id),
days text not null,
open_at time not null,
open_for interval minute not null
);

create index on location_schedule_timetable (source);
create index on location_schedule_timetable (location_schedule);

alter table location_schedule_timetable
enable row level security;

Expand Down
12 changes: 12 additions & 0 deletions supabase/migrations/20240520215628_create_directory_entry.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ create table directory_entry
specialties text
);

create index on directory_entry (source);

alter table directory_entry
enable row level security;

Expand All @@ -32,6 +34,8 @@ create table directory_entry_category
category text not null check (length(trim(category)) > 0)
);

create index on directory_entry_category (directory_entry);

alter table directory_entry_category
enable row level security;

Expand All @@ -54,6 +58,10 @@ create table directory_entry_location
description text
);

create index on directory_entry_location (directory_entry);
create index on directory_entry_location (location);
create index on directory_entry_location (source);

alter table directory_entry_location
enable row level security;

Expand All @@ -77,6 +85,10 @@ create table directory_entry_organization
description text
);

create index on directory_entry_organization (directory_entry);
create index on directory_entry_organization (directory_organization);
create index on directory_entry_organization (source);

alter table directory_entry_organization
enable row level security;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ create table content_category
(
id uuid not null default gen_random_uuid() 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)
sort_title text null check (length(sort_title) between 0 and 256)
);

alter table content_category
Expand Down
10 changes: 10 additions & 0 deletions supabase/migrations/20240520215633_create_calendar_event.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ create table calendar_event
constraint only_one_location check ( case when campus_location_id is not null then textual_location is null end )
);

create index on calendar_event (source);
create index on calendar_event (recurrence_of_event_id);
create index on calendar_event (sponsoring_entity);
create index on calendar_event (campus_location_id);

alter table calendar_event
enable row level security;

Expand All @@ -32,6 +37,9 @@ create table calendar_event_category
primary key (calendar_event_id, category_id)
);

create index on calendar_event_category (category_id);
create index on calendar_event_category (source);

alter table calendar_event_category
enable row level security;

Expand All @@ -52,6 +60,8 @@ create table calendar_event_link
primary key (calendar_event_id, href)
);

create index on calendar_event_link (source);

alter table calendar_event_link
enable row level security;

Expand Down
8 changes: 8 additions & 0 deletions supabase/migrations/20240520215636_create_feed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ create table feed
primary key (uri)
);

create index on feed (source);

alter table feed
enable row level security;

Expand All @@ -31,6 +33,10 @@ create table feed_article
constraint only_one_location check ( case when campus_location_id is not null then textual_location is null end )
);

create index on feed_article (source);
create index on feed_article (campus_location_id);
create index on feed_article (sponsoring_entity);

alter table feed_article
enable row level security;

Expand All @@ -53,3 +59,5 @@ alter table feed_article_category
create policy "Enable read access for all users"
on feed_article_category for select
to public using (true);

create index on feed_article_category (category_id);
3 changes: 3 additions & 0 deletions supabase/migrations/20240520215639_create_app_notice.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ create table app_notice
platform text null
);

create index on app_notice (source);
create index on app_notice (active_until) where (active_until is not null);

alter table app_notice
enable row level security;

Expand Down
27 changes: 15 additions & 12 deletions supabase/migrations/20240520215640_create_livestream.sql
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
create table livestream
(
id uuid not null default gen_random_uuid() primary key,
source text not null references data_source (id) on update cascade on delete cascade,
title text not null,
subtitle text not null,
stream_uri text not null,
tint_color text null,
text_color text null,
logo_uri text null,
calendar_source text null references data_source (id) on update cascade on delete restrict,
phone text null,
email text null,
website text null
id uuid not null default gen_random_uuid() primary key,
source text not null references data_source (id) on update cascade on delete cascade,
title text not null,
subtitle text not null,
stream_uri text not null,
tint_color text null,
text_color text null,
logo_uri text null,
calendar_event_id text null references calendar_event (id) on update cascade on delete cascade,
phone text null,
email text null,
website text null
);

create index on livestream (source);
create index on livestream (calendar_event_id);

alter table livestream
enable row level security;

Expand Down
13 changes: 12 additions & 1 deletion supabase/migrations/20240520215641_create_bus_route.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ create table bus_route
title text not null
);

create index on bus_route (source);

alter table bus_route
enable row level security;

Expand All @@ -20,9 +22,11 @@ create table bus_route_stop
id uuid not null default gen_random_uuid() primary key,
source text not null references data_source (id) on update cascade on delete cascade,
name text not null,
coordinates jsonb not null default '[]'::jsonb
coordinates point not null default 'POINT(0 0)'::point
);

create index on bus_route_stop (source);

alter table bus_route_stop
enable row level security;

Expand All @@ -44,6 +48,10 @@ create table bus_route_timetable
constraint outbound_time_if_stop check (case when outbound_stop is not null then outbound_time is not null end)
);

create index on bus_route_timetable (source);
create index on bus_route_timetable (inbound_stop);
create index on bus_route_timetable (outbound_stop);

alter table bus_route_timetable
enable row level security;

Expand All @@ -62,6 +70,9 @@ create table bus_route_schedule
active_until timestamptz null
);

create index on bus_route_schedule (timetable_id);
create index on bus_route_schedule (source);

alter table bus_route_schedule
enable row level security;

Expand Down
14 changes: 14 additions & 0 deletions supabase/migrations/20240520215645_create_cafe.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ create table cafe
location uuid null references location (id)
);

create index on cafe (source);
create index on cafe (location);

alter table cafe
enable row level security;

Expand Down Expand Up @@ -44,6 +47,8 @@ create table cafe_item
nutrition jsonb not null default '{}'::jsonb -- TODO: expand this into a table
);

create index on cafe_item (source);

alter table cafe_item
enable row level security;

Expand All @@ -60,6 +65,8 @@ create table cafe_item_variation
description text
);

create index on cafe_item_variation (cafe_item_id);

alter table cafe_item_variation
enable row level security;

Expand All @@ -76,6 +83,8 @@ create table cafe_item_cor
primary key (cafe_item_id, cafe_cor_id)
);

create index on cafe_item_cor (cafe_cor_id);

alter table cafe_item_cor
enable row level security;

Expand All @@ -97,6 +106,9 @@ create table cafe_station_menu
is_featured bool not null default false
);

create index on cafe_station_menu (source);
create index on cafe_station_menu (item_id);

alter table cafe_station_menu
enable row level security;

Expand All @@ -113,6 +125,8 @@ create table cafe_menu_schedule
primary key (schedule_id, station_id)
);

create index on cafe_menu_schedule (station_id);

alter table cafe_menu_schedule
enable row level security;

Expand Down
3 changes: 3 additions & 0 deletions supabase/migrations/20240520215652_create_student_work.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ create table student_work
when department_name is null then department_id is not null end)
);

create index on student_work (source);
create index on student_work (department_id);

alter table student_work
enable row level security;

Expand Down

0 comments on commit dcddde2

Please sign in to comment.