Skip to content
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

fix: tenants update on conflict handling #298

Merged
merged 1 commit into from
Feb 1, 2024
Merged

Conversation

geekbrother
Copy link
Contributor

Description

We have rare errors where the client tries to create tenants with the same id that causes the following errors:

"duplicate key value violates unique constraint \"tenants_pkey\"", detail: Some("Key (id)=(xxx) already exists."

This PR adds:

  • Handling of ON CONFLICT while creating the new tenant.
  • Adds missing updates of updated_at field on any updates of the record.

How Has This Been Tested?

Functional tests for multitenant.

Due Diligence

  • Breaking change
  • Requires a documentation update
  • Requires a e2e/integration test update

@geekbrother geekbrother self-assigned this Jan 31, 2024
@arein arein added the accepted The issue has been accepted into the project label Jan 31, 2024
@geekbrother geekbrother changed the title fix: tenants updating on conflict handling fix: tenants update on conflict handling Jan 31, 2024
@geekbrother geekbrother marked this pull request as ready for review January 31, 2024 13:36
@@ -314,7 +318,7 @@ impl TenantStore for PgPool {
#[instrument(skip(self))]
async fn update_tenant(&self, id: &str, params: TenantUpdateParams) -> Result<Tenant> {
let res = sqlx::query_as::<sqlx::postgres::Postgres, Tenant>(
"UPDATE public.tenants SET id = $2 WHERE id = $1 RETURNING *;",
"UPDATE public.tenants SET id = $2, updated_at = NOW() WHERE id = $1 RETURNING *;",
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose even of this function? It looks like this is never called anyway. Should just remove as id shouldn't be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was added a long ago, probably the author expect to use it somehow. I'll remove this rudiment.

Copy link
Member

@chris13524 chris13524 left a comment

Choose a reason for hiding this comment

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

Perfect.

@geekbrother geekbrother merged commit 994ec79 into main Feb 1, 2024
10 checks passed
@geekbrother geekbrother deleted the fix/teanants_updates branch February 1, 2024 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The issue has been accepted into the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants