-
Notifications
You must be signed in to change notification settings - Fork 484
feat: delete old environments (and refactor delete old data) #3928
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
Conversation
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.
Not tested yet, looks good overall, just a few comments here and there 🙏🏻
deleteFn: async () => { | ||
const endUsers = await db.knex.from<DBEndUser>('end_users').where({ environment_id: environment.id }).limit(opts.limit); | ||
|
||
for (const endUser of endUsers) { | ||
await deleteEndUserData(endUser, opts); | ||
} | ||
|
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.
You can also directly batch delete since connections will be deleted in an other loop
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.
Where else are connections deleted? You mean the soft-deleted ones in the base cron?
There's a conflict between having our delete function do what you'd think they would (delete all it's dependencies), and things being deleted elsewhere, meaning we trusts other parts of the cron job to clean things properly. I was going for redundancy in most cases, but I'll remove redundancy where performance could be significantly affected (removed for oauth sessions and connect sessions, for instance).
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.
Sorry I was not very clear. end_users table is not an entry point to connections.
They should be considered independent, because legacy customers are not using this system and it's optional for new customers.
So you can batch delete them without selecting (e.g: DELETE WHERE IN
)
And delete connections independently
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.
Moved to isolated delete under deleteEnvironment
.
@@ -0,0 +1,31 @@ | |||
import { setTimeout } from 'node:timers/promises'; |
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.
I'll rename the crons/utils
subfolder to crons/delete
.
|
GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
---|---|---|---|---|---|
16627964 | Triggered | Username Password | fa7f53a | packages/shared/lib/utils/utils.unit.test.ts | View secret |
16627965 | Triggered | Generic Password | fa7f53a | packages/shared/lib/utils/utils.unit.test.ts | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
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.
Sorry this back and forth is a bit annoying, maybe we should have made it testable.
It's currently not working, for providers and env, it's missing the deletion of connections
deleteFn: async () => { | ||
const endUsers = await db.knex.from<DBEndUser>('end_users').where({ environment_id: environment.id }).limit(opts.limit); | ||
|
||
for (const endUser of endUsers) { | ||
await deleteEndUserData(endUser, opts); | ||
} | ||
|
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.
Sorry I was not very clear. end_users table is not an entry point to connections.
They should be considered independent, because legacy customers are not using this system and it's optional for new customers.
So you can batch delete them without selecting (e.g: DELETE WHERE IN
)
And delete connections independently
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.
Working great 🚀
Description
This adds environments to our
deleteOldData
cron job. It goes very in depth on deleting anything under an environment. To achieve so, some existing parts ofdeleteOldEnvironments
was refactored / modified. It should go down the whole graph of dependencies under environments. Here's how the dependency graph looks, meaning that deleting a node means also deleting all it's child nodes:I'll add some comments throughout with some more details
Testing
I have not yet tested this anywhere. It's very unlikely that I got it all right out of the gate. I'm taking suggestions on how to test it.