From 43bcc703d017228249f4ad833fbf8afb6f8ee967 Mon Sep 17 00:00:00 2001 From: coolneng Date: Fri, 25 Sep 2020 09:57:51 +0200 Subject: [PATCH] Migrate OTP attribute to integer --- database/models.py | 2 +- .../d994081ed483_set_otp_as_integer.py | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 migrations/versions/d994081ed483_set_otp_as_integer.py diff --git a/database/models.py b/database/models.py index 66fa818..040f078 100644 --- a/database/models.py +++ b/database/models.py @@ -18,7 +18,7 @@ class Users(Base): user_image = Column(String(255)) city_id = Column(Integer, ForeignKey("cities.id")) user_type = Column(Integer) - otp = Column(String(255)) + otp = Column(Integer) otp_valid_time = Column(DateTime) access_key = Column(Text, unique=True) lang_type = Column(Integer) diff --git a/migrations/versions/d994081ed483_set_otp_as_integer.py b/migrations/versions/d994081ed483_set_otp_as_integer.py new file mode 100644 index 0000000..2ad76a0 --- /dev/null +++ b/migrations/versions/d994081ed483_set_otp_as_integer.py @@ -0,0 +1,29 @@ +"""set otp as integer + +Revision ID: d994081ed483 +Revises: 1387db583e1d +Create Date: 2020-09-25 07:11:21.603504 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "d994081ed483" +down_revision = "1387db583e1d" +branch_labels = None +depends_on = None + + +def upgrade(): + with op.batch_alter_table("users") as batch_op: + batch_op.alter_column( + column_name="otp", existing_type=sa.String(length=255), type_=sa.Integer, + ) + query = "SELECT CAST(otp AS INTEGER) from users" + op.execute(query) + + +def downgrade(): + pass