Update user_id for bigint and update secure

This commit is contained in:
2025-12-04 16:11:38 +03:00
parent d67371dcee
commit e74ab668ce
3 changed files with 72 additions and 5 deletions

View File

@@ -0,0 +1,66 @@
"""change_user_id_to_bigint
Revision ID: 44f93e0fb396
Revises: 7ac28bbbc5ee
Create Date: 2025-12-04 01:38:07.580350
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '44f93e0fb396'
down_revision: Union[str, Sequence[str], None] = '7ac28bbbc5ee'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# Change user_id from Integer to BigInteger in all tables
# PostgreSQL allows direct type change from INTEGER to BIGINT
# First, change foreign keys in tasks table
op.alter_column('tasks', 'user_id',
existing_type=sa.Integer(),
type_=sa.BigInteger(),
existing_nullable=False)
# Change foreign key in otp_codes table
op.alter_column('otp_codes', 'user_id',
existing_type=sa.Integer(),
type_=sa.BigInteger(),
existing_nullable=False)
# Finally, change primary key in users table
op.alter_column('users', 'user_id',
existing_type=sa.Integer(),
type_=sa.BigInteger(),
existing_nullable=False)
def downgrade() -> None:
"""Downgrade schema."""
# Change user_id back from BigInteger to Integer
# Note: This may fail if there are values larger than INTEGER max value
# Change primary key in users table first
op.alter_column('users', 'user_id',
existing_type=sa.BigInteger(),
type_=sa.Integer(),
existing_nullable=False)
# Change foreign key in otp_codes table
op.alter_column('otp_codes', 'user_id',
existing_type=sa.BigInteger(),
type_=sa.Integer(),
existing_nullable=False)
# Change foreign key in tasks table
op.alter_column('tasks', 'user_id',
existing_type=sa.BigInteger(),
type_=sa.Integer(),
existing_nullable=False)