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

feat(2589): soft delete unused asset #2699

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

lengyel-arpad85
Copy link
Contributor

@lengyel-arpad85 lengyel-arpad85 commented May 3, 2024

Soft delete asset including the Admin frontend part, by adding a deletedAt date and filtering get & getAll calls for deletedAt being NULL
This approach was adopted instead of hard delete since TigerBeetle has no support for deleting rows

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Documentation added
  • Make sure that all checks pass
  • Bruno collection updated

@lengyel-arpad85 lengyel-arpad85 self-assigned this May 3, 2024
@github-actions github-actions bot added type: tests Testing related pkg: backend Changes in the backend package. pkg: frontend Changes in the frontend package. type: source Changes business logic pkg: mock-ase pkg: mock-account-service-lib labels May 3, 2024
Copy link

netlify bot commented May 3, 2024

Deploy Preview for brilliant-pasca-3e80ec canceled.

Name Link
🔨 Latest commit bdc5e1b
🔍 Latest deploy log https://app.netlify.com/sites/brilliant-pasca-3e80ec/deploys/66525ff288f2810008a91358

@lengyel-arpad85 lengyel-arpad85 changed the title feat(2589) soft delete unused asset feat(2589): soft delete unused asset May 3, 2024
@lengyel-arpad85 lengyel-arpad85 linked an issue May 3, 2024 that may be closed by this pull request
Copy link
Contributor

@mkurapov mkurapov left a comment

Choose a reason for hiding this comment

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

My main question is, what should we do when we delete an asset, then try to re-create another one with the same code and scale (via createAsset mutation)?

Right now, we will get a "duplicate asset" error, but that might be a bit confusing given the asset isn't visible in the UI. Maybe we can just set deletedAt to be null again, and return the asset?

packages/backend/src/asset/model.ts Outdated Show resolved Hide resolved
packages/backend/src/asset/errors.ts Outdated Show resolved Hide resolved
@lengyel-arpad85
Copy link
Contributor Author

My main question is, what should we do when we delete an asset, then try to re-create another one with the same code and scale (via createAsset mutation)?

Right now, we will get a "duplicate asset" error, but that might be a bit confusing given the asset isn't visible in the UI. Maybe we can just set deletedAt to be null again, and return the asset?

yes, that might work, but if the scale is different from what we had before, do we just update the scale to the new one ?

@mkurapov
Copy link
Contributor

mkurapov commented May 8, 2024

@arpad-lengyel

yes, that might work, but if the scale is different from what we had before, do we just update the scale to the new one ?

An asset is unique on scale and code together, so that would signify a new/different asset

@lengyel-arpad85
Copy link
Contributor Author

@arpad-lengyel

yes, that might work, but if the scale is different from what we had before, do we just update the scale to the new one ?

An asset is unique on scale and code together, so that would signify a new/different asset

@mkurapov It's an unused asset, so in theory it should not matter what the previous scale was, it was never used, so it won't have an effect on anything, no ?

@mkurapov
Copy link
Contributor

It's an unused asset, so in theory it should not matter what the previous scale was, it was never used, so it won't have an effect on anything, no ?

Right, however I would say to be safe, we should treat e.g. USD/9 vs USD/2 as completely different assets (even if they have the same asset code). This is reflected in the DB as well:

packages/backend/src/asset/service.ts Outdated Show resolved Hide resolved
packages/backend/src/asset/service.ts Outdated Show resolved Hide resolved
packages/backend/src/graphql/resolvers/asset.ts Outdated Show resolved Hide resolved
packages/backend/src/asset/errors.ts Outdated Show resolved Hide resolved
@lengyel-arpad85
Copy link
Contributor Author

It's an unused asset, so in theory it should not matter what the previous scale was, it was never used, so it won't have an effect on anything, no ?

Right, however I would say to be safe, we should treat e.g. USD/9 vs USD/2 as completely different assets (even if they have the same asset code). This is reflected in the DB as well:

yes, you are right, I've corrected the condition in my code

Copy link
Contributor

@mkurapov mkurapov left a comment

Choose a reason for hiding this comment

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

Looks good, just minor test comment

packages/backend/src/asset/service.test.ts Outdated Show resolved Hide resolved
packages/backend/src/asset/service.test.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: backend Changes in the backend package. pkg: frontend Changes in the frontend package. pkg: mock-account-service-lib pkg: mock-ase type: source Changes business logic type: tests Testing related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delete an unused asset
2 participants