-
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
Changes from 12 commits
faa1da0
bb4c74c
93c649c
c120d2a
8d22f7e
01d308a
08f153e
88bb9c4
aee231c
4393a56
85cc1ad
6eb0aff
1574bbc
2787ed9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""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.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 commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry, you can't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will be the equivalent? |
||
|
||
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 ### |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""empty message | ||
|
||
Revision ID: 4e9450c16147 | ||
Revises: f177c14710f1 | ||
Create Date: 2020-07-03 01:29:29.959740 | ||
|
||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
import sqlalchemy_utils | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '4e9450c16147' | ||
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']) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
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 ### |
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.