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(soft-delete): implement soft delete for PaymentOrder and LockPay… #409

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Fidel-wole
Copy link

@Fidel-wole Fidel-wole commented Jan 31, 2025

Soft Delete Implementation for PaymentOrder

Summary

  1. Created SoftDeleteMixin in schema/mixins.go, following Ent’s documentation for soft delete.
  2. Integrated SoftDeleteMixin into LockPaymentOrder and PaymentOrder schemas.
  3. Updated the PaymentOrder edge in SenderProfile to use entsql.Cascade for proper deletion handling.
  4. Added SkipSoftDelete context utility function to allow conditional bypass of soft delete logic.

Description
This PR introduces soft delete functionality for PaymentOrder and LockPaymentOrder, ensuring that deleted records are retained while being excluded from queries. The update aligns with Ent’s recommended approach, enhancing data integrity and traceability.

Key changes and rationale:

Soft delete implementation: Prevents permanent loss of data while allowing safe deletions.
Cascade deletion fix: Ensures dependent entities in SenderProfile are correctly handled.
Bypass option: Introduces SkipSoftDelete to enable scenarios where soft delete logic should be skipped (e.g., admin overrides).
These changes improve system reliability and maintainability without introducing breaking changes.

References
Closes #401

By submitting this PR, I acknowledge and agree to Paycrest’s Contributor Code of Conduct and Contribution Guide.

…mentOrder

- Created SoftDeleteMixin in schema/mixins.go following Ent documentation for soft delete.
- Added SoftDeleteMixin to LockPaymentOrder and PaymentOrder schemas.
- Updated PaymentOrder edge in SenderProfile to use entsql.Cascade for proper deletion handling.
- Added SkipSoftDelete context utility function to conditionally bypass soft delete logic.
@believemanasseh
Copy link
Contributor

@Fidel-wole Please edit your PR description so that issue #407 is not closed.

@OnahProsperity
Copy link
Collaborator

@Fidel-wole thanks for the PR, could you resolve the issue with the issue that the PR is closing.

@Fidel-wole
Copy link
Author

@Fidel-wole Please edit your PR description so that issue #407 is not closed.

Ok will do that

Comment on lines +35 to +46
type SoftDeleteMixin struct {
mixin.Schema
}

// Fields of the SoftDeleteMixin.
func (SoftDeleteMixin) Fields() []ent.Field {
return []ent.Field{
field.Time("deleted_at").
Optional().
Nillable(),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can you copy all the mixin code that's here? https://entgo.io/docs/interceptors/#soft-delete

the only change should be "delete_time" to "deleted_at"

Copy link
Author

Choose a reason for hiding this comment

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

Ok sir

Copy link
Author

Choose a reason for hiding this comment

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

image
I keep getting this error, do you know of a way around it?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Fidel-wole can you ask under "Aggregator" topic in the dev community https://t.me/+Stx-wLOdj49iNDM0

Comment on lines +535 to +552

type contextKey string

const skipSoftDeleteKey contextKey = "skipSoftDelete"

// SkipSoftDelete adds a context value to skip soft delete logic.
func SkipSoftDelete(ctx context.Context) context.Context {
return context.WithValue(ctx, skipSoftDeleteKey, true)
}

// IsSkipSoftDelete returns true if the context indicates that soft delete should be skipped.
func IsSkipSoftDelete(ctx context.Context) bool {
val := ctx.Value(skipSoftDeleteKey)
if val != nil {
return val.(bool)
}
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

these aren't needed... SkipSoftDelete is already be in the mixin.go snippet from ent docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Soft Delete for Payment Orders
4 participants