Skip to content

Commit ee0bd29

Browse files
fix: Add proper unique constraints and remove soft deletion from models (#7098)
Co-authored-by: Areeb Jamal <[email protected]>
1 parent e2e038c commit ee0bd29

File tree

12 files changed

+80
-21
lines changed

12 files changed

+80
-21
lines changed

app/api/custom/orders.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,7 @@ def complete_order(order_id):
229229
)
230230
form_fields = (
231231
db.session.query(CustomForms)
232-
.filter_by(
233-
event_id=order.event_id, form='attendee', is_included=True, deleted_at=None
234-
)
232+
.filter_by(event_id=order.event_id, form='attendee', is_included=True)
235233
.all()
236234
)
237235
for attendee, updated_attendee in zip(attendees, updated_attendees):

app/api/event_copy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def create_event_copy(identifier):
5151
event_id=event.id, deleted_at=None
5252
).all()
5353
tracks = Track.query.filter_by(event_id=event.id, deleted_at=None).all()
54-
custom_forms = CustomForms.query.filter_by(event_id=event.id, deleted_at=None).all()
54+
custom_forms = CustomForms.query.filter_by(event_id=event.id).all()
5555
discount_codes = DiscountCode.query.filter_by(
5656
event_id=event.id, deleted_at=None
5757
).all()

app/api/helpers/custom_forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_schema(form_fields):
3131

3232
def validate_custom_form_constraints(form, obj):
3333
form_fields = CustomForms.query.filter_by(
34-
form=form, event_id=obj.event_id, is_included=True, deleted_at=None,
34+
form=form, event_id=obj.event_id, is_included=True,
3535
).all()
3636
required_form_fields = filter(lambda field: field.is_required, form_fields)
3737
missing_required_fields = []

app/api/schema/custom_forms.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
from marshmallow import validate as validate
22
from marshmallow_jsonapi import fields
3-
from marshmallow_jsonapi.flask import Relationship
3+
from marshmallow_jsonapi.flask import Relationship, Schema
44

55
from app.api.helpers.utilities import dasherize
6-
from app.api.schema.base import SoftDeletionSchema
76
from utils.common import use_defaults
87

98

109
@use_defaults()
11-
class CustomFormSchema(SoftDeletionSchema):
10+
class CustomFormSchema(Schema):
1211
"""
1312
API Schema for Custom Forms database model
1413
"""

app/api/schema/event_sub_topics.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from marshmallow_jsonapi import fields
2-
from marshmallow_jsonapi.flask import Relationship
2+
from marshmallow_jsonapi.flask import Relationship, Schema
33

44
from app.api.helpers.utilities import dasherize
5-
from app.api.schema.base import SoftDeletionSchema
65

76

8-
class EventSubTopicSchema(SoftDeletionSchema):
7+
class EventSubTopicSchema(Schema):
98
"""
109
Api Schema for event sub topic model
1110
"""

app/models/custom_form.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from app.api.helpers.utilities import to_snake_case
77
from app.models import db
8-
from app.models.base import SoftDeletionModel
98

109
SESSION_FORM = {
1110
"title": {"include": 1, "require": 1},
@@ -135,7 +134,7 @@
135134
}
136135

137136

138-
class CustomForms(SoftDeletionModel):
137+
class CustomForms(db.Model):
139138
"""custom form model class"""
140139

141140
__tablename__ = 'custom_forms'

app/models/discount_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class DiscountCode(SoftDeletionModel):
1414
__tablename__ = "discount_codes"
1515
__table_args__ = (
16-
UniqueConstraint('event_id', 'code', name='uq_event_discount_code'),
16+
UniqueConstraint('event_id', 'code', 'deleted_at', name='uq_event_discount_code'),
1717
)
1818

1919
id = db.Column(db.Integer, primary_key=True)

app/models/event_sub_topic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
from app.api.helpers.db import get_new_slug
44
from app.models import db
5-
from app.models.base import SoftDeletionModel
65

76

8-
class EventSubTopic(SoftDeletionModel):
7+
class EventSubTopic(db.Model):
98
"""Event sub topic object table"""
109

1110
__tablename__ = 'event_sub_topics'

app/models/role_invite.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def generate_hash():
1717
class RoleInvite(SoftDeletionModel):
1818
__tablename__ = 'role_invites'
1919
__table_args__ = (
20-
UniqueConstraint('email', 'role_id', 'event_id', name='email_role_event_uc'),
20+
UniqueConstraint(
21+
'email', 'role_id', 'event_id', 'deleted_at', name='email_role_event_uc',
22+
),
2123
)
2224

2325
id = db.Column(db.Integer, primary_key=True)

docs/api/blueprint/custom_forms.apib

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ Create a new Custom Form with event_id.
7272
"field-identifier": "name",
7373
"is-included": false,
7474
"is-fixed": false,
75-
"deleted-at": null,
7675
"type": "text"
7776
},
7877
"type": "custom-form",
@@ -123,7 +122,6 @@ Get a single custom form.
123122
"field-identifier": "name",
124123
"is-fixed": false,
125124
"is-included": false,
126-
"deleted-at": null,
127125
"type": "text"
128126
},
129127
"type": "custom-form",
@@ -187,7 +185,6 @@ Update a single custom form with `id`.
187185
"form": "speaker",
188186
"field-identifier": "name",
189187
"is-fixed": false,
190-
"deleted-at": null,
191188
"is-included": false,
192189
"type": "text"
193190
},
@@ -271,7 +268,6 @@ Get a list of Custom Forms for an event.
271268
"field-identifier": "name",
272269
"is-included": false,
273270
"is-fixed": false,
274-
"deleted-at": null,
275271
"type": "text"
276272
},
277273
"type": "custom-form",

0 commit comments

Comments
 (0)