-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migration file for study_fitbit_credentials table
- Loading branch information
1 parent
9a80f8e
commit 5f5b2b4
Showing
3 changed files
with
112 additions
and
35 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
-- | ||
-- Name: study_fitbit_credentials; Type: TABLE; Schema: public; Owner: postgres | ||
-- | ||
|
||
CREATE TABLE public.study_fitbit_credentials ( | ||
study_id uuid NOT NULL PRIMARY KEY, | ||
fitbit_credentials jsonb NOT NULL | ||
); | ||
|
||
ALTER TABLE public.study_fitbit_credentials OWNER TO postgres; | ||
|
||
COMMENT ON TABLE public.study_fitbit_credentials IS 'Fitbit credentials for studies'; | ||
|
||
-- | ||
-- Name: "Enable read access for study participants for fitbit credentials and owners"; Type: POLICY; Schema: public; Owner: postgres | ||
-- | ||
|
||
CREATE POLICY "Enable read access for study participants for fitbit credentials and owners" | ||
ON public.study_fitbit_credentials | ||
FOR SELECT | ||
USING ( | ||
( | ||
SELECT public.can_edit(auth.uid(), study) | ||
FROM public.study | ||
WHERE study.id = study_fitbit_credentials.study_id | ||
) | ||
OR public.is_study_subject_of(auth.uid(), study_fitbit_credentials.study_id) | ||
); | ||
|
||
-- | ||
-- Name: "Study owners can manage their own fitbit credentials"; Type: POLICY; Schema: public; Owner: postgres | ||
-- | ||
|
||
CREATE POLICY "Study owners can manage their own fitbit credentials" | ||
ON public.study_fitbit_credentials | ||
FOR ALL | ||
USING ( | ||
( | ||
SELECT public.can_edit(auth.uid(), study) | ||
FROM public.study | ||
WHERE study.id = study_fitbit_credentials.study_id | ||
) | ||
) | ||
WITH CHECK ( | ||
( | ||
SELECT public.can_edit(auth.uid(), study) | ||
FROM public.study | ||
WHERE study.id = study_fitbit_credentials.study_id | ||
) | ||
); | ||
|
||
-- | ||
-- Name: study_fitbit_credentials study_fitbit_credentials_studyId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres | ||
-- | ||
|
||
ALTER TABLE ONLY public.study_fitbit_credentials | ||
ADD CONSTRAINT "study_fitbit_credentials_studyId_fkey" | ||
FOREIGN KEY (study_id) REFERENCES public.study(id) ON DELETE CASCADE; | ||
|
||
-- | ||
-- Name: study_fitbit_credentials; Type: ROW SECURITY; Schema: public; Owner: postgres | ||
-- | ||
|
||
ALTER TABLE public.study_fitbit_credentials ENABLE ROW LEVEL SECURITY; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters