Skip to content

Commit 4ed4f57

Browse files
committed
Update schema after bug fixes
1 parent 0345ee6 commit 4ed4f57

File tree

2 files changed

+27
-41
lines changed

2 files changed

+27
-41
lines changed

data/schema.sql

+26-40
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
-- PostgreSQL database dump
33
--
44

5-
-- Dumped from database version 10.4
6-
-- Dumped by pg_dump version 10.4
5+
-- Dumped from database version 11.2
6+
-- Dumped by pg_dump version 11.2
77

88
SET statement_timeout = 0;
99
SET lock_timeout = 0;
@@ -36,20 +36,6 @@ CREATE SCHEMA app_private;
3636
CREATE SCHEMA app_public;
3737

3838

39-
--
40-
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
41-
--
42-
43-
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
44-
45-
46-
--
47-
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
48-
--
49-
50-
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
51-
52-
5339
--
5440
-- Name: citext; Type: EXTENSION; Schema: -; Owner: -
5541
--
@@ -384,7 +370,7 @@ COMMENT ON COLUMN app_public.users.is_admin IS 'If true, the user has elevated p
384370

385371
CREATE FUNCTION app_private.link_or_register_user(f_user_id integer, f_service character varying, f_identifier character varying, f_profile json, f_auth_details json) RETURNS app_public.users
386372
LANGUAGE plpgsql SECURITY DEFINER
387-
SET search_path TO "$user", public
373+
SET search_path TO '$user', 'public'
388374
AS $$
389375
declare
390376
v_matched_user_id int;
@@ -474,7 +460,7 @@ COMMENT ON FUNCTION app_private.link_or_register_user(f_user_id integer, f_servi
474460

475461
CREATE FUNCTION app_private.login(username text, password text) RETURNS app_public.users
476462
LANGUAGE plpgsql STRICT SECURITY DEFINER
477-
SET search_path TO "$user", public
463+
SET search_path TO '$user', 'public'
478464
AS $$
479465
declare
480466
v_user app_public.users;
@@ -550,7 +536,7 @@ COMMENT ON FUNCTION app_private.login(username text, password text) IS 'Returns
550536

551537
CREATE FUNCTION app_private.really_create_user(username text, email text, email_is_verified boolean, name text, avatar_url text, password text DEFAULT NULL::text) RETURNS app_public.users
552538
LANGUAGE plpgsql
553-
SET search_path TO "$user", public
539+
SET search_path TO '$user', 'public'
554540
AS $$
555541
declare
556542
v_user app_public.users;
@@ -619,7 +605,7 @@ COMMENT ON FUNCTION app_private.really_create_user(username text, email text, em
619605

620606
CREATE FUNCTION app_private.register_user(f_service character varying, f_identifier character varying, f_profile json, f_auth_details json, f_email_is_verified boolean DEFAULT false) RETURNS app_public.users
621607
LANGUAGE plpgsql SECURITY DEFINER
622-
SET search_path TO "$user", public
608+
SET search_path TO '$user', 'public'
623609
AS $$
624610
declare
625611
v_user app_public.users;
@@ -668,7 +654,7 @@ COMMENT ON FUNCTION app_private.register_user(f_service character varying, f_ide
668654

669655
CREATE FUNCTION app_private.tg__add_job_for_row() RETURNS trigger
670656
LANGUAGE plpgsql
671-
SET search_path TO "$user", public
657+
SET search_path TO '$user', 'public'
672658
AS $$
673659
begin
674660
perform app_jobs.add_job(tg_argv[0], json_build_object('id', NEW.id));
@@ -690,11 +676,11 @@ COMMENT ON FUNCTION app_private.tg__add_job_for_row() IS 'Useful shortcut to cre
690676

691677
CREATE FUNCTION app_private.tg__update_timestamps() RETURNS trigger
692678
LANGUAGE plpgsql
693-
SET search_path TO "$user", public
679+
SET search_path TO '$user', 'public'
694680
AS $$
695681
begin
696682
NEW.created_at = (case when TG_OP = 'INSERT' then NOW() else OLD.created_at end);
697-
NEW.updated_at = (case when TG_OP = 'UPDATE' and OLD.updated_at <= NOW() then OLD.updated_at + interval '1 millisecond' else NOW() end);
683+
NEW.updated_at = (case when TG_OP = 'UPDATE' and OLD.updated_at >= NOW() then OLD.updated_at + interval '1 millisecond' else NOW() end);
698684
return NEW;
699685
end;
700686
$$;
@@ -713,7 +699,7 @@ COMMENT ON FUNCTION app_private.tg__update_timestamps() IS 'This trigger should
713699

714700
CREATE FUNCTION app_private.tg_user_email_secrets__insert_with_user_email() RETURNS trigger
715701
LANGUAGE plpgsql
716-
SET search_path TO "$user", public
702+
SET search_path TO '$user', 'public'
717703
AS $$
718704
declare
719705
v_verification_token text;
@@ -740,7 +726,7 @@ COMMENT ON FUNCTION app_private.tg_user_email_secrets__insert_with_user_email()
740726

741727
CREATE FUNCTION app_private.tg_user_secrets__insert_with_user() RETURNS trigger
742728
LANGUAGE plpgsql
743-
SET search_path TO "$user", public
729+
SET search_path TO '$user', 'public'
744730
AS $$
745731
begin
746732
insert into app_private.user_secrets(user_id) values(NEW.id);
@@ -762,7 +748,7 @@ COMMENT ON FUNCTION app_private.tg_user_secrets__insert_with_user() IS 'Ensures
762748

763749
CREATE FUNCTION app_private.tg_users__make_first_user_admin() RETURNS trigger
764750
LANGUAGE plpgsql
765-
SET search_path TO "$user", public
751+
SET search_path TO '$user', 'public'
766752
AS $$
767753
begin
768754
if not exists(select 1 from app_public.users) then
@@ -779,7 +765,7 @@ $$;
779765

780766
CREATE FUNCTION app_public."current_user"() RETURNS app_public.users
781767
LANGUAGE sql STABLE
782-
SET search_path TO "$user", public
768+
SET search_path TO '$user', 'public'
783769
AS $$
784770
select users.* from app_public.users where id = app_public.current_user_id();
785771
$$;
@@ -791,7 +777,7 @@ $$;
791777

792778
CREATE FUNCTION app_public.current_user_id() RETURNS integer
793779
LANGUAGE sql STABLE
794-
SET search_path TO "$user", public
780+
SET search_path TO '$user', 'public'
795781
AS $$
796782
select nullif(current_setting('jwt.claims.user_id', true), '')::int;
797783
$$;
@@ -811,7 +797,7 @@ Handy method to get the current user ID for use in RLS policies, etc; in GraphQL
811797

812798
CREATE FUNCTION app_public.current_user_is_admin() RETURNS boolean
813799
LANGUAGE sql STABLE
814-
SET search_path TO "$user", public
800+
SET search_path TO '$user', 'public'
815801
AS $$
816802
-- We're using exists here because it guarantees true/false rather than true/false/null
817803
select exists(
@@ -834,7 +820,7 @@ Handy method to determine if the current user is an admin, for use in RLS polici
834820

835821
CREATE FUNCTION app_public.forgot_password(email text) RETURNS boolean
836822
LANGUAGE plpgsql STRICT SECURITY DEFINER
837-
SET search_path TO "$user", public
823+
SET search_path TO '$user', 'public'
838824
AS $$
839825
declare
840826
v_user_email app_public.user_emails;
@@ -982,7 +968,7 @@ COMMENT ON FUNCTION app_public.random_number() IS 'Chosen by fair dice roll. Gua
982968

983969
CREATE FUNCTION app_public.reset_password(user_id integer, reset_token text, new_password text) RETURNS app_public.users
984970
LANGUAGE plpgsql STRICT SECURITY DEFINER
985-
SET search_path TO "$user", public
971+
SET search_path TO '$user', 'public'
986972
AS $$
987973
declare
988974
v_user app_public.users;
@@ -1091,7 +1077,7 @@ COMMENT ON COLUMN app_public.topics.body IS 'The body of the `Topic`, which Post
10911077

10921078
CREATE FUNCTION app_public.topics_body_summary(t app_public.topics, max_length integer DEFAULT 30) RETURNS text
10931079
LANGUAGE sql STABLE
1094-
SET search_path TO "$user", public
1080+
SET search_path TO '$user', 'public'
10951081
AS $$
10961082
select case
10971083
when length(t.body) > max_length
@@ -1672,42 +1658,42 @@ CREATE TRIGGER _900_notify_worker AFTER INSERT ON app_jobs.jobs FOR EACH STATEME
16721658
-- Name: users _100_timestamps; Type: TRIGGER; Schema: app_public; Owner: -
16731659
--
16741660

1675-
CREATE TRIGGER _100_timestamps AFTER INSERT OR UPDATE ON app_public.users FOR EACH ROW EXECUTE PROCEDURE app_private.tg__update_timestamps();
1661+
CREATE TRIGGER _100_timestamps BEFORE INSERT OR UPDATE ON app_public.users FOR EACH ROW EXECUTE PROCEDURE app_private.tg__update_timestamps();
16761662

16771663

16781664
--
16791665
-- Name: user_emails _100_timestamps; Type: TRIGGER; Schema: app_public; Owner: -
16801666
--
16811667

1682-
CREATE TRIGGER _100_timestamps AFTER INSERT OR UPDATE ON app_public.user_emails FOR EACH ROW EXECUTE PROCEDURE app_private.tg__update_timestamps();
1668+
CREATE TRIGGER _100_timestamps BEFORE INSERT OR UPDATE ON app_public.user_emails FOR EACH ROW EXECUTE PROCEDURE app_private.tg__update_timestamps();
16831669

16841670

16851671
--
16861672
-- Name: user_authentications _100_timestamps; Type: TRIGGER; Schema: app_public; Owner: -
16871673
--
16881674

1689-
CREATE TRIGGER _100_timestamps AFTER INSERT OR UPDATE ON app_public.user_authentications FOR EACH ROW EXECUTE PROCEDURE app_private.tg__update_timestamps();
1675+
CREATE TRIGGER _100_timestamps BEFORE INSERT OR UPDATE ON app_public.user_authentications FOR EACH ROW EXECUTE PROCEDURE app_private.tg__update_timestamps();
16901676

16911677

16921678
--
16931679
-- Name: forums _100_timestamps; Type: TRIGGER; Schema: app_public; Owner: -
16941680
--
16951681

1696-
CREATE TRIGGER _100_timestamps AFTER INSERT OR UPDATE ON app_public.forums FOR EACH ROW EXECUTE PROCEDURE app_private.tg__update_timestamps();
1682+
CREATE TRIGGER _100_timestamps BEFORE INSERT OR UPDATE ON app_public.forums FOR EACH ROW EXECUTE PROCEDURE app_private.tg__update_timestamps();
16971683

16981684

16991685
--
17001686
-- Name: topics _100_timestamps; Type: TRIGGER; Schema: app_public; Owner: -
17011687
--
17021688

1703-
CREATE TRIGGER _100_timestamps AFTER INSERT OR UPDATE ON app_public.topics FOR EACH ROW EXECUTE PROCEDURE app_private.tg__update_timestamps();
1689+
CREATE TRIGGER _100_timestamps BEFORE INSERT OR UPDATE ON app_public.topics FOR EACH ROW EXECUTE PROCEDURE app_private.tg__update_timestamps();
17041690

17051691

17061692
--
17071693
-- Name: posts _100_timestamps; Type: TRIGGER; Schema: app_public; Owner: -
17081694
--
17091695

1710-
CREATE TRIGGER _100_timestamps AFTER INSERT OR UPDATE ON app_public.posts FOR EACH ROW EXECUTE PROCEDURE app_private.tg__update_timestamps();
1696+
CREATE TRIGGER _100_timestamps BEFORE INSERT OR UPDATE ON app_public.posts FOR EACH ROW EXECUTE PROCEDURE app_private.tg__update_timestamps();
17111697

17121698

17131699
--
@@ -2176,8 +2162,8 @@ GRANT SELECT,USAGE ON SEQUENCE app_public.users_id_seq TO graphiledemo_visitor;
21762162
-- Name: DEFAULT PRIVILEGES FOR SEQUENCES; Type: DEFAULT ACL; Schema: app_public; Owner: -
21772163
--
21782164

2179-
ALTER DEFAULT PRIVILEGES FOR ROLE graphiledemo IN SCHEMA app_public REVOKE ALL ON SEQUENCES FROM graphiledemo;
2180-
ALTER DEFAULT PRIVILEGES FOR ROLE graphiledemo IN SCHEMA app_public GRANT SELECT,USAGE ON SEQUENCES TO graphiledemo_visitor;
2165+
ALTER DEFAULT PRIVILEGES FOR ROLE benjiegillam IN SCHEMA app_public REVOKE ALL ON SEQUENCES FROM benjiegillam;
2166+
ALTER DEFAULT PRIVILEGES FOR ROLE benjiegillam IN SCHEMA app_public GRANT SELECT,USAGE ON SEQUENCES TO graphiledemo_visitor;
21812167

21822168

21832169
--

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"scripts": {
3-
"db:reset": "psql -X1v ON_ERROR_STOP=1 graphiledemo -f ./db/schema.sql",
3+
"db:reset": "psql -X1v ON_ERROR_STOP=1 graphiledemo -f ./db/reset.sql",
44
"lint": "eslint .",
55
"client:react": "cd client-react; npm start",
66
"server:koa2": "cd server-koa2; npm start",

0 commit comments

Comments
 (0)