-
-
Notifications
You must be signed in to change notification settings - Fork 563
feat(core,schemas): add user_social_identity_ids table #7459
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
base: master
Are you sure you want to change the base?
feat(core,schemas): add user_social_identity_ids table #7459
Conversation
COMPARE TO
|
Name | Diff |
---|---|
packages/core/src/queries/user-social-identity-relations.ts | 📈 +1.17 KB |
packages/core/src/routes/admin-user/social.ts | 📈 +811 Bytes |
packages/core/src/routes/swagger/utils/general.ts | 📈 +311 Bytes |
packages/core/src/tenants/Queries.ts | 📈 +190 Bytes |
packages/integration-tests/src/api/admin-user.ts | 📈 +216 Bytes |
packages/integration-tests/src/tests/api/admin-user.identities.test.ts | 📈 +5.49 KB |
packages/integration-tests/src/tests/api/admin-user.test.ts | 📈 +3.45 KB |
packages/schemas/alterations/next-1750063177-add-user-social-identity-relations-table.ts | 📈 +3.71 KB |
packages/schemas/tables/user_social_identity_relations.sql | 📈 +2.51 KB |
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.
Pull Request Overview
This PR adds a dedicated index table (user_social_identity_ids) for fast lookup of social identity data and synchronizes its content with the users.identities JSONB column via a database trigger.
- Introduces a new SQL migration file and associated trigger function for syncing social identity records.
- Provides an alteration script written in TypeScript to manage the table creation, trigger setup, and rollback.
- Updates integration tests and core API queries to expose the new user social identity IDs.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
packages/schemas/tables/user-social-identitiy-ids.sql | Creates the user_social_identity_ids table and trigger function for syncing. |
packages/schemas/alterations/next-1750063177-add-user-social-identity-ids-table.ts | Adds the alteration script for table creation and trigger integration. |
packages/integration-tests (various files) | Updates tests to cover creation, update, query, and deletion workflows for social identities. |
packages/core (various files) | Integrates the new table with queries and exposes API routes for identity IDs. |
packages/schemas/alterations/next-1750063177-add-user-social-identity-ids-table.ts
Outdated
Show resolved
Hide resolved
9c2813e
to
3c8a695
Compare
"api/users/:userId/identity-ids": { | ||
"get": { | ||
"tags": ["Dev feature"], | ||
"parameters": [], | ||
"responses": { | ||
"200": { | ||
"description": "A list of social identity IDs of the user." | ||
} | ||
}, | ||
"summary": "Get social identity IDs of user", | ||
"description": "Get all social identity IDs of the user." | ||
} |
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.
it may be not practical to only fetch IDs? how about api/users/:userId/identities
and return identity objects?
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.
Removed this API doc. This API is temporarily used for integration testing only since we have no place to check the synced user identity relation status.
This API is guarded by the isIntegrationTest
guard.
@@ -0,0 +1,69 @@ | |||
/* init_order = 2 */ | |||
|
|||
create table user_social_identity_ids ( |
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.
create table user_social_identity_ids ( | |
create table user_social_identity_relations ( |
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.
updated
unique (tenant_id, target, identity_id) | ||
); | ||
|
||
create function sync_user_social_identity_ids() |
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.
better add some comments to explain the purpose
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.
comments added
add user_social_identity_relations table
059590f
to
078d83c
Compare
fix the alteration script
fix swagger check
* Important: This table should only be queried for reading data. Any write operations | ||
* should be performed on the `Users` table instead, as the trigger will handle the synchronization. |
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.
nit: we can limit update/delete operation for this table when we apply RLS policy?
Summary
Add
user_social_identity_ids
index table for social identity lookup.user_social_identity_ids
users.identities
JSONB column onINSERT
orUPDATE
Why
Our existing implementation stores social identity information as a
JSONB
object in the users table. While this design centralizes identity data, it presents several limitations:To address these issues, we’ve introduced a dedicated index table to enable fast and reliable lookups and joins.
Design Notes
Testing
user_id
,target
,identity_id
)users.identities
field — that remains the single source of truth (SSOT) for social identity detailsusers.identities
afterINSERT
orUPDATE
operationsChecklist
.changeset