Sanitize database fields
This commit is contained in:
@@ -27,6 +27,7 @@ def upgrade():
|
||||
"sports": "modified",
|
||||
"teams": "modified",
|
||||
"user_ratings": "modified",
|
||||
"users": "modified",
|
||||
"venues": "modified",
|
||||
}
|
||||
for table, field in tables.items():
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
"""set users status default value
|
||||
|
||||
Revision ID: 0a4f01e489de
|
||||
Revises: 15a14d428bff
|
||||
Create Date: 2020-09-10 23:54:22.624598
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "0a4f01e489de"
|
||||
down_revision = "15a14d428bff"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
with op.batch_alter_table("users") as batch_op:
|
||||
batch_op.alter_column(column_name="status", server_default=sa.text("0"))
|
||||
|
||||
|
||||
def downgrade():
|
||||
pass
|
||||
@@ -0,0 +1,59 @@
|
||||
"""sanitize nullable and non-nullable fields
|
||||
|
||||
Revision ID: 15a14d428bff
|
||||
Revises: 05f3ae5db7c7
|
||||
Create Date: 2020-09-10 12:27:31.889962
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "15a14d428bff"
|
||||
down_revision = "05f3ae5db7c7"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
nullable = {
|
||||
"full_name": "users",
|
||||
"email": "users",
|
||||
"mobile": "users",
|
||||
"name": "cities",
|
||||
"name": "games",
|
||||
"price": "games",
|
||||
"name": "web_bookings",
|
||||
"email": "web_bookings",
|
||||
"contact": "web_bookings",
|
||||
"message": "web_bookings",
|
||||
"game": "web_bookings",
|
||||
"city": "web_bookings",
|
||||
"address": "venues",
|
||||
"name": "venues",
|
||||
"spanish_name": "sports",
|
||||
"rating": "user_ratings",
|
||||
"name": "sports",
|
||||
}
|
||||
non_nullable = {
|
||||
"social_id": "users",
|
||||
"type": "users",
|
||||
}
|
||||
for field, table in nullable.items():
|
||||
query = "UPDATE {0} SET {1} = '' WHERE {1} IS NULL".format(table, field)
|
||||
op.execute(query)
|
||||
with op.batch_alter_table(table) as batch_op:
|
||||
batch_op.alter_column(
|
||||
column_name=field, nullable=False, server_default=None
|
||||
)
|
||||
for field, table in non_nullable.items():
|
||||
with op.batch_alter_table(table) as batch_op:
|
||||
batch_op.alter_column(column_name=field, nullable=True, server_default=None)
|
||||
query = "UPDATE {0} SET {1} = NULL WHERE {1} = '' OR {1} = '0'".format(
|
||||
table, field
|
||||
)
|
||||
op.execute(query)
|
||||
|
||||
|
||||
def downgrade():
|
||||
pass
|
||||
@@ -18,26 +18,30 @@ depends_on = None
|
||||
|
||||
def upgrade():
|
||||
tables = {
|
||||
"cities": "updated",
|
||||
"games": "updated",
|
||||
"payments": "updated",
|
||||
"player_availabilities": "updated",
|
||||
"player_cancel_games": "updated",
|
||||
"purchase_games": "updated",
|
||||
"sports": "updated",
|
||||
"teams": "updated",
|
||||
"user_ratings": "updated",
|
||||
"venues": "updated",
|
||||
"venue_images": "updated",
|
||||
"web_bookings": "updated",
|
||||
"cities": ["modified"],
|
||||
"games": ["modified", "cancel_date"],
|
||||
"payments": ["modified"],
|
||||
"player_availabilities": ["modified"],
|
||||
"player_cancel_games": ["modified"],
|
||||
"purchase_games": ["modified"],
|
||||
"sports": ["modified"],
|
||||
"teams": ["modified"],
|
||||
"user_ratings": ["modified"],
|
||||
"users": ["modified"],
|
||||
"venues": ["modified"],
|
||||
"venue_images": ["updated"],
|
||||
"web_bookings": ["updated"],
|
||||
}
|
||||
for table, field in tables.items():
|
||||
with op.batch_alter_table(table) as batch_op:
|
||||
batch_op.alter_column(column_name=field, nullable=True, server_default=None)
|
||||
query = "UPDATE {0} SET {1} = NULL WHERE {1} = '0000-00-00 00:00:00'".format(
|
||||
table, field
|
||||
)
|
||||
op.execute(query)
|
||||
for item in field:
|
||||
with op.batch_alter_table(table) as batch_op:
|
||||
batch_op.alter_column(
|
||||
column_name=item, nullable=True, server_default=None
|
||||
)
|
||||
query = "UPDATE {0} SET {1} = NULL WHERE {1} = '0000-00-00 00:00:00'".format(
|
||||
table, item
|
||||
)
|
||||
op.execute(query)
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
Reference in New Issue
Block a user