Skip to content

Commit 639fad5

Browse files
authored
Correct sql spacing. (#313)
SQRuff issue [1786](quarylabs/sqruff#1786) was solved in sqruff 2.9.1 Re-enable rule LT01 accordingly, and re-apply linting to schema files. Indicate the minimum version in the readme.
1 parent 3a24c90 commit 639fad5

7 files changed

Lines changed: 41 additions & 41 deletions

File tree

packages/database/.sqruff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[sqruff]
22
dialect = postgres
33
# Exclude LT01 until https://github.com/quarylabs/sqruff/issues/1786 is solved.
4-
exclude_rules = CP05,LT05,LT01
4+
exclude_rules = CP05,LT05
55

66
[sqruff:indentation]
77
indent_unit = space

packages/database/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It does mean you will have a fresh database with minimal data.
1111

1212
1. Install [Docker](https://www.docker.com)
1313
2. Set the `SUPABASE_WORKDIR` in your environment to the absolute path of the `packages/database` directory.
14-
3. Install [sqruff](https://github.com/quarylabs/sqruff)
14+
3. Install [sqruff](https://github.com/quarylabs/sqruff), version >= 0.29.1
1515

1616
### General usage:
1717

packages/database/supabase/schemas/access_token.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ REVOKE TRIGGER ON TABLE "public"."access_token" FROM "anon";
3737
GRANT SELECT ON TABLE "public"."access_token" TO "anon";
3838
GRANT INSERT ON TABLE "public"."access_token" TO "anon";
3939

40-
ALTER TABLE public.access_token ENABLE ROW LEVEL SECURITY ;
40+
ALTER TABLE public.access_token ENABLE ROW LEVEL SECURITY;
4141

42-
DROP POLICY IF EXISTS access_token_policy ON public.access_token ;
43-
CREATE POLICY access_token_policy ON public.access_token FOR ALL USING (public.my_account(platform_account_id)) ;
42+
DROP POLICY IF EXISTS access_token_policy ON public.access_token;
43+
CREATE POLICY access_token_policy ON public.access_token FOR ALL USING (public.my_account(platform_account_id));

packages/database/supabase/schemas/account.sql

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ AS $$
142142
SELECT dg_account = auth.uid() FROM public."PlatformAccount" WHERE id=account_id;
143143
$$;
144144

145-
COMMENT ON FUNCTION public.my_account IS 'security utility: is this my own account?' ;
145+
COMMENT ON FUNCTION public.my_account IS 'security utility: is this my own account?';
146146

147147
CREATE OR REPLACE FUNCTION public.in_space(space_id BIGINT) RETURNS boolean
148148
STABLE SECURITY DEFINER
@@ -154,20 +154,20 @@ AS $$
154154
WHERE sa.space_id = $1 AND pa.dg_account = auth.uid();
155155
$$;
156156

157-
COMMENT ON FUNCTION public.in_space IS 'security utility: does current user have access to this space?' ;
157+
COMMENT ON FUNCTION public.in_space IS 'security utility: does current user have access to this space?';
158158

159159

160-
CREATE OR REPLACE FUNCTION public.account_in_shared_space (p_account_id BIGINT) RETURNS boolean
160+
CREATE OR REPLACE FUNCTION public.account_in_shared_space(p_account_id BIGINT) RETURNS boolean
161161
STABLE SECURITY DEFINER
162162
SET search_path = ''
163163
LANGUAGE sql AS $$
164164
SELECT COUNT(*) > 0 FROM public."PlatformAccount" AS my_account
165165
JOIN public."SpaceAccess" AS my_access ON (my_account.id=my_access.account_id)
166166
JOIN public."SpaceAccess" AS their_access ON (their_access.space_id = my_access.space_id AND their_access.account_id=p_account_id)
167167
WHERE my_account.dg_account = auth.uid();
168-
$$ ;
168+
$$;
169169

170-
CREATE OR REPLACE FUNCTION public.unowned_account_in_shared_space (p_account_id BIGINT) RETURNS boolean
170+
CREATE OR REPLACE FUNCTION public.unowned_account_in_shared_space(p_account_id BIGINT) RETURNS boolean
171171
STABLE SECURITY DEFINER
172172
SET search_path = ''
173173
LANGUAGE sql AS $$
@@ -176,52 +176,52 @@ LANGUAGE sql AS $$
176176
JOIN public."SpaceAccess" AS their_access ON (their_access.space_id = my_access.space_id AND their_access.account_id=p_account_id)
177177
JOIN public."PlatformAccount" AS their_account ON (their_access.account_id = their_account.id AND their_account.id=p_account_id)
178178
WHERE my_account.dg_account = auth.uid() AND COALESCE(their_account.dg_account, auth.uid()) = auth.uid();
179-
$$ ;
179+
$$;
180180

181-
COMMENT ON FUNCTION public.unowned_account_in_shared_space IS 'security utility: does current user share a space with this account? And is this an un-owned account (other than mine)?' ;
181+
COMMENT ON FUNCTION public.unowned_account_in_shared_space IS 'security utility: does current user share a space with this account? And is this an un-owned account (other than mine)?';
182182

183183

184184
-- Space: Allow anyone to insert, but only users who are members of the space can update or select
185185

186-
ALTER TABLE public."Space" ENABLE ROW LEVEL SECURITY ;
186+
ALTER TABLE public."Space" ENABLE ROW LEVEL SECURITY;
187187

188-
DROP POLICY IF EXISTS space_policy ON public."Space" ;
189-
CREATE POLICY space_policy ON public."Space" FOR ALL USING (public.in_space(id)) ;
188+
DROP POLICY IF EXISTS space_policy ON public."Space";
189+
CREATE POLICY space_policy ON public."Space" FOR ALL USING (public.in_space(id));
190190

191-
DROP POLICY IF EXISTS space_insert_policy ON public."Space" ;
192-
CREATE POLICY space_insert_policy ON public."Space" FOR INSERT WITH CHECK (true) ;
191+
DROP POLICY IF EXISTS space_insert_policy ON public."Space";
192+
CREATE POLICY space_insert_policy ON public."Space" FOR INSERT WITH CHECK (true);
193193

194194
-- PlatformAccount: Access to anyone sharing a space with you to create an account, to allow editing authors
195195
-- Once the account is claimed by a user, only allow this user to modify it.
196196
-- Eventually: Allow platform admin to modify?
197197

198-
ALTER TABLE public."PlatformAccount" ENABLE ROW LEVEL SECURITY ;
198+
ALTER TABLE public."PlatformAccount" ENABLE ROW LEVEL SECURITY;
199199

200-
DROP POLICY IF EXISTS platform_account_policy ON public."PlatformAccount" ;
201-
CREATE POLICY platform_account_policy ON public."PlatformAccount" FOR ALL USING (dg_account = (SELECT auth.uid()) OR (dg_account IS null AND public.unowned_account_in_shared_space(id))) ;
200+
DROP POLICY IF EXISTS platform_account_policy ON public."PlatformAccount";
201+
CREATE POLICY platform_account_policy ON public."PlatformAccount" FOR ALL USING (dg_account = (SELECT auth.uid()) OR (dg_account IS null AND public.unowned_account_in_shared_space(id)));
202202

203-
DROP POLICY IF EXISTS platform_account_select_policy ON public."PlatformAccount" ;
204-
CREATE POLICY platform_account_select_policy ON public."PlatformAccount" FOR SELECT USING (dg_account = (SELECT auth.uid()) OR public.account_in_shared_space(id)) ;
203+
DROP POLICY IF EXISTS platform_account_select_policy ON public."PlatformAccount";
204+
CREATE POLICY platform_account_select_policy ON public."PlatformAccount" FOR SELECT USING (dg_account = (SELECT auth.uid()) OR public.account_in_shared_space(id));
205205

206206
-- SpaceAccess: Created through the create_account_in_space and the Space create route, both of which bypass RLS.
207207
-- Can be updated by a space peer for now, unless claimed by a user.
208208
-- Eventually: Allow space admin to modify?
209209

210-
ALTER TABLE public."SpaceAccess" ENABLE ROW LEVEL SECURITY ;
210+
ALTER TABLE public."SpaceAccess" ENABLE ROW LEVEL SECURITY;
211211

212-
DROP POLICY IF EXISTS space_access_policy ON public."SpaceAccess" ;
213-
CREATE POLICY space_access_policy ON public."SpaceAccess" FOR ALL USING (public.unowned_account_in_shared_space(account_id)) ;
212+
DROP POLICY IF EXISTS space_access_policy ON public."SpaceAccess";
213+
CREATE POLICY space_access_policy ON public."SpaceAccess" FOR ALL USING (public.unowned_account_in_shared_space(account_id));
214214

215-
DROP POLICY IF EXISTS space_access_select_policy ON public."SpaceAccess" ;
216-
CREATE POLICY space_access_select_policy ON public."SpaceAccess" FOR ALL USING (public.in_space(space_id)) ;
215+
DROP POLICY IF EXISTS space_access_select_policy ON public."SpaceAccess";
216+
CREATE POLICY space_access_select_policy ON public."SpaceAccess" FOR ALL USING (public.in_space(space_id));
217217

218218
-- AgentIdentifier: Allow space members to do anything, to allow editing authors.
219219
-- Eventually: Once the account is claimed by a user, only allow this user to modify it.
220220

221-
ALTER TABLE public."AgentIdentifier" ENABLE ROW LEVEL SECURITY ;
221+
ALTER TABLE public."AgentIdentifier" ENABLE ROW LEVEL SECURITY;
222222

223-
DROP POLICY IF EXISTS agent_identifier_policy ON public."AgentIdentifier" ;
224-
CREATE POLICY agent_identifier_policy ON public."AgentIdentifier" FOR ALL USING (public.unowned_account_in_shared_space(account_id)) ;
223+
DROP POLICY IF EXISTS agent_identifier_policy ON public."AgentIdentifier";
224+
CREATE POLICY agent_identifier_policy ON public."AgentIdentifier" FOR ALL USING (public.unowned_account_in_shared_space(account_id));
225225

226-
DROP POLICY IF EXISTS agent_identifier_select_policy ON public."AgentIdentifier" ;
227-
CREATE POLICY agent_identifier_select_policy ON public."AgentIdentifier" FOR SELECT USING (public.account_in_shared_space(account_id)) ;
226+
DROP POLICY IF EXISTS agent_identifier_select_policy ON public."AgentIdentifier";
227+
CREATE POLICY agent_identifier_select_policy ON public."AgentIdentifier" FOR SELECT USING (public.account_in_shared_space(account_id));

packages/database/supabase/schemas/concept.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ BEGIN
254254
END;
255255
$$;
256256

257-
CREATE OR REPLACE FUNCTION public.concept_in_space (concept_id BIGINT) RETURNS boolean
257+
CREATE OR REPLACE FUNCTION public.concept_in_space(concept_id BIGINT) RETURNS boolean
258258
STABLE
259259
SET search_path = ''
260260
LANGUAGE sql

packages/database/supabase/schemas/content.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ $$;
496496

497497
COMMENT ON FUNCTION public.upsert_content IS 'batch content upsert';
498498

499-
CREATE OR REPLACE FUNCTION public.content_in_space (content_id BIGINT) RETURNS boolean
499+
CREATE OR REPLACE FUNCTION public.content_in_space(content_id BIGINT) RETURNS boolean
500500
STABLE
501501
SET search_path = ''
502502
LANGUAGE sql
@@ -506,7 +506,7 @@ $$;
506506

507507
COMMENT ON FUNCTION public.content_in_space IS 'security utility: does current user have access to this content''s space?';
508508

509-
CREATE OR REPLACE FUNCTION public.document_in_space (document_id BIGINT) RETURNS boolean
509+
CREATE OR REPLACE FUNCTION public.document_in_space(document_id BIGINT) RETURNS boolean
510510
STABLE
511511
SET search_path = ''
512512
LANGUAGE sql

packages/database/supabase/schemas/sync.sql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ GRANT ALL ON FUNCTION public.get_nodes_needing_sync(nodes_from_roam jsonb) TO "a
263263
GRANT ALL ON FUNCTION public.get_nodes_needing_sync(nodes_from_roam jsonb) TO "service_role";
264264

265265

266-
CREATE OR REPLACE FUNCTION public.generic_entity_access (target_id BIGINT, target_type public."EntityType") RETURNS boolean
266+
CREATE OR REPLACE FUNCTION public.generic_entity_access(target_id BIGINT, target_type public."EntityType") RETURNS boolean
267267
STABLE SECURITY DEFINER
268268
SET search_path = ''
269269
LANGUAGE sql AS $$
@@ -275,16 +275,16 @@ LANGUAGE sql AS $$
275275
WHEN target_type = 'PlatformAccount' THEN public.account_in_shared_space(target_id)
276276
ELSE false
277277
END;
278-
$$ ;
278+
$$;
279279

280-
COMMENT ON FUNCTION public.generic_entity_access IS 'security utility: does current user have access to this generic entity?' ;
280+
COMMENT ON FUNCTION public.generic_entity_access IS 'security utility: does current user have access to this generic entity?';
281281

282282

283-
ALTER TABLE public.sync_info ENABLE ROW LEVEL SECURITY ;
283+
ALTER TABLE public.sync_info ENABLE ROW LEVEL SECURITY;
284284

285285
-- Assuming the sync target is a always a space for now
286286

287-
DROP POLICY IF EXISTS sync_info_policy ON public.sync_info ;
288-
CREATE POLICY sync_info_policy ON public.sync_info FOR ALL USING (public.generic_entity_access(sync_target, target_type)) ;
287+
DROP POLICY IF EXISTS sync_info_policy ON public.sync_info;
288+
CREATE POLICY sync_info_policy ON public.sync_info FOR ALL USING (public.generic_entity_access(sync_target, target_type));
289289

290290
RESET ALL;

0 commit comments

Comments
 (0)