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

fix: Add proper unique constraints and remove soft deletion from models #7098

Merged
merged 14 commits into from
Jul 4, 2020

Conversation

Haider8
Copy link
Contributor

@Haider8 Haider8 commented Jun 30, 2020

Fixes #7093

Short description of what this resolves:

Not all models requires soft deletion so we have to remove it from models like CustomForms and EventSubTopic.

In some models (like DiscountCode) we need to add a unique constraint on deleted_at column.

Checklist

  • I have read the Contribution & Best practices Guide and my PR follows them.
  • My branch is up-to-date with the Upstream development branch.
  • The unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • All the functions created/modified in this PR contain relevant docstrings.

@@ -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'

Choose a reason for hiding this comment

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

Black would make changes.

@@ -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'
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove from all?

Copy link
Member

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'),

Choose a reason for hiding this comment

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

Black would make changes.

@iamareebjamal
Copy link
Member

Please fix the tests

@iamareebjamal
Copy link
Member

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

@Haider8
Copy link
Contributor Author

Haider8 commented Jul 2, 2020

@iamareebjamal There are 4 apib dredd fails like in GET /v1/events/1/custom-form. So, should I change that now?

@iamareebjamal
Copy link
Member

Yes

@codecov
Copy link

codecov bot commented Jul 2, 2020

Codecov Report

Merging #7098 into development will decrease coverage by 0.52%.
The diff coverage is 85.71%.

Impacted file tree graph

@@               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     
Impacted Files Coverage Δ
app/api/custom/orders.py 36.99% <ø> (ø)
app/api/event_copy.py 28.57% <0.00%> (ø)
app/api/helpers/custom_forms.py 100.00% <ø> (ø)
app/models/discount_code.py 94.00% <ø> (ø)
app/models/role_invite.py 85.18% <ø> (ø)
app/api/schema/custom_forms.py 100.00% <100.00%> (ø)
app/api/schema/event_sub_topics.py 100.00% <100.00%> (ø)
app/models/custom_form.py 97.91% <100.00%> (-0.05%) ⬇️
app/models/event_sub_topic.py 94.11% <100.00%> (-0.33%) ⬇️
app/api/helpers/speaker.py 50.00% <0.00%> (-40.00%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e2e038c...2787ed9. Read the comment docs.

@iamareebjamal
Copy link
Member

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

.

@Haider8
Copy link
Contributor Author

Haider8 commented Jul 2, 2020

@iamareebjamal Done

@iamareebjamal iamareebjamal changed the title enh: Add unique constraints and remove soft deletion from models feat: Add unique constraints and remove soft deletion from models Jul 2, 2020
@auto-label auto-label bot added the feature label Jul 2, 2020
@iamareebjamal iamareebjamal changed the title feat: Add unique constraints and remove soft deletion from models feat: Add proper unique constraints and remove soft deletion from models Jul 2, 2020
@iamareebjamal iamareebjamal changed the title feat: Add proper unique constraints and remove soft deletion from models fix: Add proper unique constraints and remove soft deletion from models Jul 2, 2020
@auto-label auto-label bot added fix and removed feature labels Jul 2, 2020
@@ -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')
Copy link
Member

@iamareebjamal iamareebjamal Jul 2, 2020

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

Copy link
Contributor Author

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?

@iamareebjamal
Copy link
Member

Will merge after manual testing

from app.models import db

DEFAULT_FEE = 0.0


class TicketFees(db.Model):
class TicketFees(SoftDeletionModel):
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed 👍


class Permission(db.Model):

class Permission(SoftDeletionModel):
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@iamareebjamal iamareebjamal merged commit ee0bd29 into fossasia:development Jul 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change unique constraints of soft deleted models
3 participants