From b1f1ffd0e2e1ad68a4907d4cf79c3569b6d4c0b3 Mon Sep 17 00:00:00 2001 From: coolneng Date: Wed, 22 Jul 2020 22:38:48 +0200 Subject: [PATCH] Set updated/modified field as nullable --- migrations/env.py | 2 +- ...653ece_set_modified_updated_as_nullable.py | 45 +++++++++++++++++++ ...aa992d1469b_make_updated_field_nullable.py | 45 ------------------- shell.nix | 1 - 4 files changed, 46 insertions(+), 47 deletions(-) create mode 100644 migrations/versions/970563653ece_set_modified_updated_as_nullable.py delete mode 100644 migrations/versions/eaa992d1469b_make_updated_field_nullable.py diff --git a/migrations/env.py b/migrations/env.py index d79bf86..70518a2 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -64,7 +64,7 @@ def run_migrations_online(): with connectable.connect() as connection: context.configure( - connection=connection, target_metadata=target_metadata, + connection=connection, target_metadata=target_metadata ) with context.begin_transaction(): diff --git a/migrations/versions/970563653ece_set_modified_updated_as_nullable.py b/migrations/versions/970563653ece_set_modified_updated_as_nullable.py new file mode 100644 index 0000000..90b343e --- /dev/null +++ b/migrations/versions/970563653ece_set_modified_updated_as_nullable.py @@ -0,0 +1,45 @@ +"""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 = { + "cities": "updated", + "games": "updated", + "games": "cancel_date", + "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", + } + 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) + + +def downgrade(): + pass diff --git a/migrations/versions/eaa992d1469b_make_updated_field_nullable.py b/migrations/versions/eaa992d1469b_make_updated_field_nullable.py deleted file mode 100644 index be3ecdd..0000000 --- a/migrations/versions/eaa992d1469b_make_updated_field_nullable.py +++ /dev/null @@ -1,45 +0,0 @@ -"""make updated field nullable - -Revision ID: eaa992d1469b -Revises: -Create Date: 2020-07-04 18:08:31.035209 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = "eaa992d1469b" -down_revision = None -branch_labels = None -depends_on = None - - -def upgrade(): - tables = { - "modified": "cities", - "modified": "games", - "cancel_date": "games", - "modified": "payments", - "modified": "player_availabilities", - "modified": "player_cancel_games", - "modified": "purchase_games", - "modified": "sports", - "modified": "teams", - "modified": "user_ratings", - "modified": "venues", - "updated": "venue_images", - "updated": "web_bookings", - } - for field, table in tables.items(): - with op.batch_alter_table(table) as batch_op: - batch_op.alter_column(column_name=field, nullable=True) - query = "UPDATE {0} SET {1} = NULL WHERE {1} = '0000-00-00 00:00:00'".format( - table, field - ) - op.execute(query) - - -def downgrade(): - pass diff --git a/shell.nix b/shell.nix index 5ea08fa..5b25c02 100644 --- a/shell.nix +++ b/shell.nix @@ -17,7 +17,6 @@ mkShell { python38Packages.twilio sqlite # Development tools - black python38Packages.isort python38Packages.pyflakes ];