-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: main
Are you sure you want to change the base?
feat(soft-delete): implement soft delete for PaymentOrder and LockPay… #409
Conversation
…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.
@Fidel-wole Please edit your PR description so that issue #407 is not closed. |
@Fidel-wole thanks for the PR, could you resolve the issue with the issue that the PR is closing. |
Ok will do that |
type SoftDeleteMixin struct { | ||
mixin.Schema | ||
} | ||
|
||
// Fields of the SoftDeleteMixin. | ||
func (SoftDeleteMixin) Fields() []ent.Field { | ||
return []ent.Field{ | ||
field.Time("deleted_at"). | ||
Optional(). | ||
Nillable(), | ||
} | ||
} |
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.
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"
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.
Ok sir
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.
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.
@Fidel-wole can you ask under "Aggregator" topic in the dev community https://t.me/+Stx-wLOdj49iNDM0
|
||
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 | ||
} |
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.
these aren't needed... SkipSoftDelete is already be in the mixin.go
snippet from ent docs
Soft Delete Implementation for PaymentOrder
Summary
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.