-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: Add proper unique constraints and remove soft deletion from models #7098
Conversation
app/models/discount_code.py
Outdated
@@ -13,7 +13,9 @@ | |||
class DiscountCode(SoftDeletionModel): | |||
__tablename__ = "discount_codes" | |||
__table_args__ = ( | |||
UniqueConstraint('event_id', 'code', name='uq_event_discount_code'), | |||
UniqueConstraint( | |||
'event_id', 'code', 'deleted_at', name='uq_event_discount_code_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.
Black would make changes.
app/models/discount_code.py
Outdated
@@ -13,7 +13,9 @@ | |||
class DiscountCode(SoftDeletionModel): | |||
__tablename__ = "discount_codes" | |||
__table_args__ = ( | |||
UniqueConstraint('event_id', 'code', name='uq_event_discount_code'), | |||
UniqueConstraint( | |||
'event_id', 'code', 'deleted_at', name='uq_event_discount_code_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.
Don't add deleted_at in constraint name, it's an implementation detail
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.
Remove from all?
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.
Yes
@@ -13,7 +13,7 @@ | |||
class DiscountCode(SoftDeletionModel): | |||
__tablename__ = "discount_codes" | |||
__table_args__ = ( | |||
UniqueConstraint('event_id', 'code', name='uq_event_discount_code'), | |||
UniqueConstraint('event_id', 'code', 'deleted_at', name='uq_event_discount_code'), |
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.
Black would make changes.
Please fix the tests |
Also, for all the models where deleted_at was removed, you need to delete the items with non null deleted_at before removing the column |
@iamareebjamal There are 4 apib dredd fails like in |
Yes |
Codecov Report
@@ Coverage Diff @@
## development #7098 +/- ##
===============================================
- Coverage 62.51% 61.99% -0.53%
===============================================
Files 262 262
Lines 13006 12996 -10
===============================================
- Hits 8131 8057 -74
- Misses 4875 4939 +64
Continue to review full report at Codecov.
|
. |
@iamareebjamal Done |
@@ -18,6 +18,9 @@ | |||
|
|||
def upgrade(): | |||
# ### commands auto generated by Alembic - please adjust! ### | |||
op.execute('DELETE FROM custom_forms WHERE deleted_at IS NOT NULL') | |||
op.execute('DELETE FROM event_sub_topics WHERE deleted_at IS NOT NULL') |
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.
Add equivalent statements in downgrade as well
Sorry, you can't
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.
What will be the equivalent?
Will merge after manual testing |
app/models/ticket_fee.py
Outdated
from app.models import db | ||
|
||
DEFAULT_FEE = 0.0 | ||
|
||
|
||
class TicketFees(db.Model): | ||
class TicketFees(SoftDeletionModel): |
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.
Don't add more soft deletion
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.
Removed 👍
app/models/permission.py
Outdated
|
||
class Permission(db.Model): | ||
|
||
class Permission(SoftDeletionModel): |
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.
Here as well. Don't add more soft deletion. It has already complicated matters a lot
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.
👍
Fixes #7093
Short description of what this resolves:
Not all models requires soft deletion so we have to remove it from models like
CustomForms
andEventSubTopic
.In some models (like
DiscountCode
) we need to add a unique constraint ondeleted_at
column.Checklist
development
branch.