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
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/models/custom_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from app.api.helpers.utilities import to_snake_case
from app.models import db
from app.models.base import SoftDeletionModel

SESSION_FORM = {
"title": {"include": 1, "require": 1},
Expand Down Expand Up @@ -135,7 +134,7 @@
}


class CustomForms(SoftDeletionModel):
class CustomForms(db.Model):
"""custom form model class"""

__tablename__ = 'custom_forms'
Expand Down
2 changes: 1 addition & 1 deletion app/models/discount_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

)

id = db.Column(db.Integer, primary_key=True)
Expand Down
3 changes: 1 addition & 2 deletions app/models/event_sub_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

from app.api.helpers.db import get_new_slug
from app.models import db
from app.models.base import SoftDeletionModel


class EventSubTopic(SoftDeletionModel):
class EventSubTopic(db.Model):
"""Event sub topic object table"""

__tablename__ = 'event_sub_topics'
Expand Down
8 changes: 6 additions & 2 deletions app/models/permission.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from app.models import db

from app.models.base import SoftDeletionModel

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.

👍

"""Role-Service Permissions
"""

__tablename__ = 'permissions'
__table_args__ = (
db.UniqueConstraint('role_id', 'service_id', name='role_service_uc'),
db.UniqueConstraint(
'role_id', 'service_id', 'deleted_at', name='role_service_uc'
),
)

id = db.Column(db.Integer, primary_key=True)
Expand Down
4 changes: 3 additions & 1 deletion app/models/role_invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def generate_hash():
class RoleInvite(SoftDeletionModel):
__tablename__ = 'role_invites'
__table_args__ = (
UniqueConstraint('email', 'role_id', 'event_id', name='email_role_event_uc'),
UniqueConstraint(
'email', 'role_id', 'event_id', 'deleted_at', name='email_role_event_uc',
),
)

id = db.Column(db.Integer, primary_key=True)
Expand Down
4 changes: 3 additions & 1 deletion app/models/ticket_fee.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from sqlalchemy import desc
from sqlalchemy.schema import UniqueConstraint

from app.models.base import SoftDeletionModel

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 👍

"""Persists service and maximum fees for a currency in a country"""

__tablename__ = 'ticket_fees'
Expand Down
30 changes: 30 additions & 0 deletions migrations/versions/rev-2020-06-30-20:07:55-f177c14710f1_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""empty message

Revision ID: f177c14710f1
Revises: 64439b77fa6d
Create Date: 2020-06-30 20:07:55.320285

"""

from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'f177c14710f1'
down_revision = '64439b77fa6d'


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('custom_forms', 'deleted_at')
op.drop_column('event_sub_topics', 'deleted_at')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('event_sub_topics', sa.Column('deleted_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True))
op.add_column('custom_forms', sa.Column('deleted_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True))
# ### end Alembic commands ###
42 changes: 42 additions & 0 deletions migrations/versions/rev-2020-06-30-23:53:04-600567d07668_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""empty message

Revision ID: 600567d07668
Revises: f177c14710f1
Create Date: 2020-06-30 23:53:04.633840

"""

from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils


# revision identifiers, used by Alembic.
revision = '600567d07668'
down_revision = 'f177c14710f1'


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('uq_event_discount_code', 'discount_codes', type_='unique')
op.create_unique_constraint('uq_event_discount_code', 'discount_codes', ['event_id', 'code', 'deleted_at'])
op.add_column('permissions', sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True))
op.drop_constraint('role_service_uc', 'permissions', type_='unique')
op.create_unique_constraint('role_service_uc', 'permissions', ['role_id', 'service_id', 'deleted_at'])
op.drop_constraint('email_role_event_uc', 'role_invites', type_='unique')
op.create_unique_constraint('email_role_event_uc', 'role_invites', ['email', 'role_id', 'event_id', 'deleted_at'])
op.add_column('ticket_fees', sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('ticket_fees', 'deleted_at')
op.drop_constraint('email_role_event_uc', 'role_invites', type_='unique')
op.create_unique_constraint('email_role_event_uc', 'role_invites', ['email', 'role_id', 'event_id'])
op.drop_constraint('role_service_uc', 'permissions', type_='unique')
op.create_unique_constraint('role_service_uc', 'permissions', ['role_id', 'service_id'])
op.drop_column('permissions', 'deleted_at')
op.drop_constraint('uq_event_discount_code', 'discount_codes', type_='unique')
op.create_unique_constraint('uq_event_discount_code', 'discount_codes', ['event_id', 'code'])
# ### end Alembic commands ###