Migrate OTP attribute to integer

This commit is contained in:
coolneng 2020-09-25 09:57:51 +02:00
parent d8e90f74fc
commit 43bcc703d0
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
2 changed files with 30 additions and 1 deletions

View File

@ -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)

View File

@ -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