diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f34465..dce8650 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## [1.3.2] - 2024-11-13 +#### [@rickypid](https://github.com/rickypid) + +Improve documentations + +### Fixed + +* Fixed schema `chats` permission after view creation + ## [1.3.1] - 2024-11-12 #### [@rickypid](https://github.com/rickypid) diff --git a/doc/docs/guides/supabse-indexes.md b/doc/docs/guides/supabse-indexes.md index b1bdfb6..0e16001 100644 --- a/doc/docs/guides/supabse-indexes.md +++ b/doc/docs/guides/supabse-indexes.md @@ -3,6 +3,8 @@ id: supabase-indexes title: Database Indexes --- +## `chats.messages` indexes + These indexes are added to improve the performance of foreign keys in database tables: ```sql diff --git a/doc/docs/guides/supabse-trigges.md b/doc/docs/guides/supabse-trigges.md index 4fa69ec..6b2af28 100644 --- a/doc/docs/guides/supabse-trigges.md +++ b/doc/docs/guides/supabse-trigges.md @@ -3,7 +3,9 @@ id: supabase-triggers title: Database Triggers --- -This is an example of a triggers that sets room's `lastMessages` to the most recent message sent once recieved in Supabase. +## Update room last message + +This is a trigger that sets room's `lastMessages` to the most recent message sent once recieved in Supabase. ```sql CREATE OR REPLACE FUNCTION chats.update_last_messages() @@ -29,6 +31,8 @@ CREATE TRIGGER update_last_messages_trigger EXECUTE FUNCTION chats.update_last_messages(); ``` +## Set message status to sent + "This trigger, on the other hand, is responsible for setting the message status to `sent` when it is added to the `messages` table: ```sql @@ -48,6 +52,8 @@ CREATE TRIGGER update_status_before_insert FOR EACH ROW EXECUTE FUNCTION chats.set_message_status_to_sent(); ``` +## Handle new user from `auth.users` + "This trigger, is responsible for replicate `auth.users` table rows in `chats.users` table, this is to avoid exposing user data : ```sql diff --git a/doc/docs/guides/supabse-views.md b/doc/docs/guides/supabse-views.md new file mode 100644 index 0000000..d4e7b7c --- /dev/null +++ b/doc/docs/guides/supabse-views.md @@ -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; +``` diff --git a/doc/package.json b/doc/package.json index 627bb16..e082f83 100644 --- a/doc/package.json +++ b/doc/package.json @@ -1,6 +1,6 @@ { "name": "flutter-supabase-chat-core", - "version": "1.3.1", + "version": "1.3.2", "private": true, "scripts": { "docusaurus": "docusaurus", diff --git a/doc/sidebars.ts b/doc/sidebars.ts index 047a68d..fb83bc6 100644 --- a/doc/sidebars.ts +++ b/doc/sidebars.ts @@ -33,6 +33,7 @@ const sidebars: SidebarsConfig = { 'guides/supabase-usage', 'guides/supabase-security', 'guides/supabase-triggers', + 'guides/supabase-views', 'guides/supabase-indexes', ], }, diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 6d8cbbd..7deacd4 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,7 +2,7 @@ name: example description: A new Flutter project. publish_to: 'none' -version: 1.3.1 +version: 1.3.2 environment: sdk: '>=3.4.0 <4.0.0' diff --git a/pubspec.yaml b/pubspec.yaml index 27062c0..27703c7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: flutter_supabase_chat_core description: > Actively maintained, community-driven Supabase BaaS for chat applications with an optional chat UI. -version: 1.3.1 +version: 1.3.2 homepage: https://flutter-supabase-chat-core.insideapp.it repository: https://github.com/insideapp-srl/flutter_supabase_chat_core