-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat: wrap multi-resource database operations in transactions #16
base: main
Are you sure you want to change the base?
Conversation
- Add transaction helper to db/index.ts - Wrap all multi-resource operations in transactions - Keep Inngest events outside transaction scope - Add proper error handling and rollbacks Co-Authored-By: [email protected] <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
We don't need a custom wrapper around Drizzle's await db.transaction(async (tx) => {
await tx.update(accounts).set({ balance: sql`${accounts.balance} - 100.00` }).where(eq(users.name, 'Dan'));
await tx.update(accounts).set({ balance: sql`${accounts.balance} + 100.00` }).where(eq(users.name, 'Andrew'));
}); Do not delete any existing comments. Do not add any new comments. Do not move blocks of code unnecessarily. Add transactions whenever we query something and use the result in a subsequent update. For example, there should be a transaction in |
.where(and(eq(schema.users.clerkOrganizationId, clerkOrganizationId), eq(schema.users.id, record.userId))); | ||
} | ||
|
||
// Keep Inngest event outside transaction |
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.
don't add this comment
.where(and(eq(schema.users.clerkOrganizationId, clerkOrganizationId), eq(schema.users.id, record.userId))); | ||
} | ||
|
||
// Keep Inngest event outside transaction |
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.
don't add this comment
|
||
// sync the record user status with the new status |
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.
don't delete this comment
}); | ||
} catch (error) { | ||
console.error(error); | ||
// Keep Inngest event outside transaction |
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.
don't add this comment
Co-Authored-By: [email protected] <[email protected]>
This PR adds transaction support to all multi-resource database operations in the services folder, ensuring atomic updates when related records are modified together.
Key changes:
Examples of operations now wrapped in transactions:
Link to Devin run: https://app.devin.ai/sessions/a4f676cc74194cd2906fbecf2537cc10
Requested by: [email protected]