Skip to content

Conversation

@sthelemann
Copy link
Contributor

@sthelemann sthelemann commented Aug 1, 2025

In the table friendship the columns a_account_id and b_account_idwere renamed to
account_idand friend_account_id, a new column is_close_friend was added,
the policies were updated. Several friendship related functions were added.
Test scripts were updated accordingly.

@sthelemann sthelemann requested a review from dargmuesli August 1, 2025 14:18
@sthelemann sthelemann changed the title feat(friendship)!: redesign table friendship feat(friendship)!: redesign and extend Aug 1, 2025
In the table `friendship` the columns `a_account_id` and  `b_account_id`were renamed to `account_id`and `friend_account_id`, a new column `is_close_friend` was added, the policies were updated. Several friendship related functions were added. Test scripts were updated accordingly.
@sthelemann sthelemann force-pushed the feat/friendship-redesign branch from fe052dc to aee2cde Compare August 3, 2025 21:30
There is a new table `friendship_request` holding a single row per friendship request. If the request is accepted then 2 records will be inserted into table `friendship` and the row in `friendship_request` will be deleted. If the request is rejected then the row in `friendship_request`will also be deleted deleted. This makes the enum type `friendship_status` superfluous and also allows policies on table `friendship` in order to hide information about friendship closeness as set by other users.
If an account A marks account B as a close friend, B can now see this information. An account C cannot select any friendship in which C is not involved.
@sthelemann sthelemann changed the title feat(friendship)!: redesign and extend feat(friendship)!: redesign and extend friendship management Aug 12, 2025
In the table `friendship` the columns `a_account_id` and  `b_account_id`were renamed to `account_id`and `friend_account_id`, a new column `is_close_friend` was added, the policies were updated. Several friendship related functions were added. Test scripts were updated accordingly.
There is a new table `friendship_request` holding a single row per friendship request. If the request is accepted then 2 records will be inserted into table `friendship` and the row in `friendship_request` will be deleted. If the request is rejected then the row in `friendship_request`will also be deleted deleted. This makes the enum type `friendship_status` superfluous and also allows policies on table `friendship` in order to hide information about friendship closeness as set by other users.
If an account A marks account B as a close friend, B can now see this information. An account C cannot select any friendship in which C is not involved.

-- create notification for a request

CREATE FUNCTION vibetype.friendship_notify_request(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a separate function for this? I only see it ever to be called in a single place.


In general: every new function is a new object to maintain regarding access permissions, testing, etc. It can broaden the api surface more than it benefits, which in turn increases security complexity. My aim is to keep the code concise so that any maintainer can feel confident that no unexpected loopholes exist. Each added function or table makes that harder.
For example, what keeps a user from directly inserting into the friendship table right now instead of using friendship_accept?
Before, I could review about 80 lines; now it's 140 plus 180 for the functions. I understand that splitting logic makes each piece easier to digest on its own, but from an auditing perspective, checking 1 table, 3 policies and 1 enum feels more manageable than reviewing 6 functions, 9 policies, and 2 tables; 5 objects vs. 17.

Maybe you can walk me through on Discord which scenarios the previous implementation couldn’t represent (excluding close friends). If the feature set hasn’t changed much, it might be worth sticking with fewer moving parts.

The newly added tests really help though, they'll prevent regressions for coming changes.

Comment on lines +28 to +33
CREATE POLICY friendship_request_select ON vibetype.friendship_request FOR SELECT
USING (
account_id = vibetype.invoker_account_id()
OR
friend_account_id = vibetype.invoker_account_id()
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was confirmed that friendships should stay public

Friendships are visible to any account.
Only the account that declared closeness to another account can see this information.
Function `friendship.request`reads the language from the account's own contact.
The default language is null (in case the value is null in the contact).
Base automatically changed from beta to main December 20, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants