odapi/migrations/versions/970563653ece_set_modified_u...

49 lines
1.2 KiB
Python
Raw Normal View History

2020-07-22 22:38:48 +02:00
"""set modified/updated as nullable
Revision ID: 970563653ece
Revises:
Create Date: 2020-07-22 23:40:07.674252
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "970563653ece"
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
tables = {
2020-09-10 23:59:06 +02:00
"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"],
2020-07-22 22:38:48 +02:00
}
for table, field in tables.items():
2020-09-10 23:59:06 +02:00
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)
2020-07-22 22:38:48 +02:00
def downgrade():
pass