Skip to content

Commit

Permalink
final schema fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
saerdnaer committed Dec 24, 2021
1 parent 163f51e commit 06d40ba
Show file tree
Hide file tree
Showing 4 changed files with 394 additions and 796 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MigrationBuilder } from 'node-pg-migrate';
import fs from 'fs';

export const up = (pgm: MigrationBuilder) => {
pgm.sql(fs.readFileSync('schema/computed_properties/days.pgsql', { encoding: 'utf8' }));
pgm.sql(fs.readFileSync('schema/computed_properties/events.pgsql', { encoding: 'utf8' }));
};

Expand Down
16 changes: 13 additions & 3 deletions c3d-core/schema/computed_properties/days.pgsql
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
CREATE OR REPLACE FUNCTION days_date(d days) RETURNS date
LANGUAGE sql
STABLE
AS $$ SELECT d.start_date::date $$;
LANGUAGE sql STABLE
AS $$ SELECT d.start_date::date $$;
ALTER FUNCTION days_date(d days) OWNER TO graphql;

CREATE OR REPLACE FUNCTION days_events(d days) RETURNS events
LANGUAGE sql STABLE
AS $$
SELECT e.*
FROM events e
WHERE d.conference_id = e.conference_id
AND e.start_date BETWEEN d.start_date AND d.end_date
ORDER BY e.start_date;
$$;
ALTER FUNCTION days_events(d days) OWNER TO graphql;
67 changes: 34 additions & 33 deletions c3d-core/schema/computed_properties/events.pgsql
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
CREATE OR REPLACE FUNCTION events_persons(e events, roles event_role[])
RETURNS SETOF people
LANGUAGE sql
STABLE
LANGUAGE sql STABLE
AS $$
SELECT p.* FROM people p, event_people ep
WHERE e.id = ep.event_id AND ep.person_id = p.id AND ep.event_role IN( SELECT
SELECT p.* FROM people p, event_people ep
WHERE e.guid = ep.event_id AND ep.person_guid = p.guid AND ep.event_role IN(
SELECT
unnest( CASE WHEN roles IS NULL
THEN ARRAY['speaker', 'moderator']::event_role[]
ELSE roles
END
)::event_role
)
)
$$;
ALTER FUNCTION events_persons(e events, roles event_role[]) OWNER TO graphql;


CREATE OR REPLACE FUNCTION events_start_time(e events) RETURNS text
LANGUAGE sql
STABLE
AS $$ SELECT to_char(e.start_date, 'HH24:MI') $$;


CREATE OR REPLACE FUNCTION events_duration_time(e events) RETURNS text
LANGUAGE sql
STABLE
AS $$ SELECT to_char(e.duration, 'HH24:MI') $$;


CREATE OR REPLACE FUNCTION events_day(e events) RETURNS days
LANGUAGE sql
STABLE
CREATE OR REPLACE FUNCTION events_day(e events)
RETURNS days
LANGUAGE sql STABLE
AS $$
SELECT d.*
FROM days d
WHERE d.conference_id = e.conference_id
AND e.start_date BETWEEN d.start_date AND d.end_date
ORDER BY d.index DESC
LIMIT 1;
SELECT d.*
FROM days d
WHERE d.conference_id = e.conference_id
AND e.start_date BETWEEN d.start_date AND d.end_date
ORDER BY d.index DESC
LIMIT 1;
$$;
ALTER FUNCTION events_day(e events) OWNER TO graphql;

CREATE OR REPLACE FUNCTION events_day_index(e events) RETURNS smallint
LANGUAGE sql
STABLE
CREATE OR REPLACE FUNCTION events_day_index(e events)
RETURNS smallint
LANGUAGE sql STABLE
AS $$
SELECT d.index AS day
FROM days d
Expand All @@ -49,15 +39,26 @@ AS $$
ORDER BY day DESC
LIMIT 1;
$$;
ALTER FUNCTION events_day_index(e events) OWNER TO graphql;

CREATE OR REPLACE FUNCTION events_duration_time(e events) RETURNS text
LANGUAGE sql STABLE
AS $$ SELECT to_char(e.duration, 'HH24:MI') $$;
ALTER FUNCTION events_duration_time(e events) OWNER TO graphql;


CREATE OR REPLACE FUNCTION events_room_name(e events) RETURNS text
LANGUAGE sql
STABLE
CREATE OR REPLACE FUNCTION events_room_name(e events)
RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT r.name
FROM rooms r
WHERE r.conference_id = e.conference_id
AND r.id = e.room_id
AND r.guid = e.room_id
$$;
ALTER FUNCTION events_room_name(e events) OWNER TO graphql;

CREATE OR REPLACE FUNCTION events_start_time(e events) RETURNS text
LANGUAGE sql STABLE
AS $$ SELECT to_char(e.start_date, 'HH24:MI') $$;
ALTER FUNCTION events_start_time(e events) OWNER TO graphql;
Loading

0 comments on commit 06d40ba

Please sign in to comment.