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

Update cleaning suspended workspace job #9999

Merged
merged 2 commits into from
Feb 4, 2025

Conversation

etiennejouan
Copy link
Contributor

  • split workspace metadata deletion into multiple queries
  • delete all subscriptions when workspace is deleted

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR enhances workspace deletion by implementing a more thorough cleanup process for workspace metadata and subscriptions.

  • Added deletion of field and relation metadata through new TypeORM repositories in packages/twenty-server/src/engine/workspace-manager/workspace-manager.service.ts
  • Modified deleteSubscription to deleteSubscriptions in packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.ts to remove all workspace-associated subscriptions
  • Implemented ordered metadata deletion (relations → fields → objects → migrations → data source → schema) in workspace-manager service for proper referential integrity
  • Added FieldMetadataEntity and RelationMetadataEntity to WorkspaceManagerModule's metadata connection

4 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

}
await this.billingSubscriptionRepository.delete({ workspaceId });
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: This bulk delete operation could potentially leave orphaned BillingSubscriptionItems. Consider cascading the delete or explicitly cleaning up related subscription items.

}
await this.billingSubscriptionRepository.delete({ workspaceId });
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure i follow: which additional billingSubscriptions could we have ? why do we not need to cancel them too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A workspace can have multiple subscriptions but only one in a not canceled status. (If workspace users have a subscription, cancel it and then subscribe again. Workspace has two subscriptions)
So when a workspace is deleted, we check if there is a not canceled subscription, if yes, we cancel it (in stripe) and then we delete all subscriptions (all in canceled status) in db

Copy link
Collaborator

Choose a reason for hiding this comment

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

very clear thank you !

@etiennejouan etiennejouan merged commit cc14c7e into main Feb 4, 2025
35 checks passed
@etiennejouan etiennejouan deleted the ej/worksapce-cleaning-command branch February 4, 2025 14:49
Copy link
Contributor

github-actions bot commented Feb 4, 2025

Fails
🚫

node failed.

Log

�[31mError: �[39m SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
�[90m    at parseJSONFromBytes (node:internal/deps/undici/undici:5591:19)�[39m
�[90m    at successSteps (node:internal/deps/undici/undici:5562:27)�[39m
�[90m    at fullyReadBody (node:internal/deps/undici/undici:1665:9)�[39m
�[90m    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)�[39m
�[90m    at async specConsumeBody (node:internal/deps/undici/undici:5571:7)�[39m
danger-results://tmp/danger-results-f8e9333a.json

Generated by 🚫 dangerJS against 5412cf0

etiennejouan added a commit that referenced this pull request Feb 7, 2025
- split workspace metadata deletion into multiple queries
- delete all subscriptions when workspace is deleted

---------

Co-authored-by: etiennejouan <jouan.etienne@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants