-
Notifications
You must be signed in to change notification settings - Fork 168
Add organization_id to review_suggestion_snippets #1525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NoritakaIkeda
merged 6 commits into
main
from
devin/1745585764-add-organization-id-review-suggestion-snippets
May 1, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c0976a2
feat: add organization_id to review_suggestion_snippets
devin-ai-integration[bot] e588b20
feat: remove unnecessary service role policies from review_suggestion…
NoritakaIkeda 346619c
Merge branch 'devin/1745585143-add-organization-id-review-feedbacks' …
NoritakaIkeda 197a638
feat: add organization_id to review_suggestion_snippets and implement…
NoritakaIkeda 7077f5c
Merge branch 'devin/1745585143-add-organization-id-review-feedbacks' …
NoritakaIkeda c511a74
Merge branch 'main' into devin/1745585764-add-organization-id-review-…
NoritakaIkeda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
14 changes: 14 additions & 0 deletions
14
frontend/packages/db/src/types/supabase-overrides/review_suggestion_snippets.ts
This file contains hidden or 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,14 @@ | ||
export interface ReviewSuggestionSnippetsOverride { | ||
public: { | ||
Tables: { | ||
review_suggestion_snippets: { | ||
Insert: { | ||
organization_id?: string | null | ||
} | ||
Update: { | ||
organization_id?: string | null | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or 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
59 changes: 59 additions & 0 deletions
59
.../supabase/migrations/20250426000000_add_organization_id_to_review_suggestion_snippets.sql
This file contains hidden or 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,59 @@ | ||
BEGIN; | ||
|
||
ALTER TABLE "public"."review_suggestion_snippets" ADD COLUMN "organization_id" UUID; | ||
|
||
UPDATE "public"."review_suggestion_snippets" rss | ||
SET "organization_id" = ( | ||
SELECT rf."organization_id" | ||
FROM "public"."review_feedbacks" rf | ||
WHERE rf."id" = rss."review_feedback_id" | ||
LIMIT 1 | ||
); | ||
|
||
ALTER TABLE "public"."review_suggestion_snippets" | ||
ALTER COLUMN "organization_id" SET NOT NULL; | ||
|
||
ALTER TABLE "public"."review_suggestion_snippets" | ||
ADD CONSTRAINT "review_suggestion_snippets_organization_id_fkey" | ||
FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") | ||
ON UPDATE CASCADE ON DELETE RESTRICT; | ||
|
||
CREATE OR REPLACE FUNCTION "public"."set_review_suggestion_snippets_organization_id"() RETURNS "trigger" | ||
LANGUAGE "plpgsql" SECURITY DEFINER | ||
AS $$ | ||
BEGIN | ||
NEW.organization_id := ( | ||
SELECT "organization_id" | ||
FROM "public"."review_feedbacks" | ||
WHERE "id" = NEW.review_feedback_id | ||
); | ||
RETURN NEW; | ||
END; | ||
$$; | ||
|
||
CREATE TRIGGER "set_review_suggestion_snippets_organization_id_trigger" | ||
BEFORE INSERT OR UPDATE ON "public"."review_suggestion_snippets" | ||
FOR EACH ROW | ||
EXECUTE FUNCTION "public"."set_review_suggestion_snippets_organization_id"(); | ||
|
||
ALTER TABLE "public"."review_suggestion_snippets" ENABLE ROW LEVEL SECURITY; | ||
|
||
CREATE POLICY "authenticated_users_can_select_org_review_suggestion_snippets" | ||
ON "public"."review_suggestion_snippets" | ||
FOR SELECT TO "authenticated" | ||
USING (("organization_id" IN ( | ||
SELECT "organization_members"."organization_id" | ||
FROM "public"."organization_members" | ||
WHERE ("organization_members"."user_id" = "auth"."uid"()) | ||
))); | ||
|
||
COMMENT ON POLICY "authenticated_users_can_select_org_review_suggestion_snippets" | ||
ON "public"."review_suggestion_snippets" | ||
IS 'Authenticated users can only view review suggestion snippets belonging to organizations they are members of'; | ||
|
||
CREATE POLICY "service_role_can_insert_all_review_suggestion_snippets" | ||
ON "public"."review_suggestion_snippets" | ||
FOR INSERT TO "service_role" | ||
WITH CHECK (true); | ||
|
||
COMMIT; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're curious where this table is used, try grepping for
.from('review_suggestion_snippets')
in the codebase.