-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed schema
chats
permission after view creation
- Loading branch information
riccardocucia
committed
Nov 13, 2024
1 parent
cf55421
commit 7d400cc
Showing
8 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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,34 @@ | ||
--- | ||
id: supabase-views | ||
title: Database Views | ||
--- | ||
|
||
## Rooms view | ||
|
||
This is a view of `rooms` table, this view allows you to obtain the name of the sender of the message dynamically in direct rooms, based on the logged-in user the name of the correspondent is displayed. | ||
|
||
```sql | ||
DROP VIEW IF EXISTS chats.rooms_l; | ||
create view chats.rooms_l | ||
WITH (security_invoker='on') as | ||
select | ||
r.id, | ||
r."imageUrl", | ||
r.metadata, | ||
case | ||
when r.type = 'direct' and auth.uid() is not null then | ||
(select coalesce(u."firstName", '') || ' ' || coalesce(u."lastName", '') | ||
from chats.users u | ||
where u.id = any(r."userIds") and u.id <> auth.uid() | ||
limit 1) | ||
else | ||
r.name | ||
end as name, | ||
r.type, | ||
r."userIds", | ||
r."lastMessages", | ||
r."userRoles", | ||
r."createdAt", | ||
r."updatedAt" | ||
from chats.rooms r; | ||
``` |
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
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
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
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