|
| 1 | +"""initial |
| 2 | +
|
| 3 | +Revision ID: 801b86be184b |
| 4 | +Revises: |
| 5 | +Create Date: 2025-12-24 03:31:04.712921 |
| 6 | +""" |
| 7 | +from typing import Sequence, Union |
| 8 | + |
| 9 | +from alembic import op |
| 10 | +import sqlalchemy as sa |
| 11 | + |
| 12 | + |
| 13 | +revision: str = '801b86be184b' |
| 14 | +down_revision: Union[str, None] = None |
| 15 | +branch_labels: Union[str, Sequence[str], None] = None |
| 16 | +depends_on: Union[str, Sequence[str], None] = None |
| 17 | + |
| 18 | + |
| 19 | +def upgrade() -> None: |
| 20 | + # ### commands auto generated by Alembic - please adjust! ### |
| 21 | + op.create_table('users', |
| 22 | + sa.Column('email', sa.String(length=320), nullable=False), |
| 23 | + sa.Column('hashed_password', sa.String(length=1024), nullable=False), |
| 24 | + sa.Column('full_name', sa.String(length=255), nullable=True), |
| 25 | + sa.Column('is_active', sa.Boolean(), nullable=False), |
| 26 | + sa.Column('is_verified', sa.Boolean(), nullable=False), |
| 27 | + sa.Column('role', sa.Enum('unknown', 'user', 'admin', name='userrole'), nullable=False), |
| 28 | + sa.Column('token_version', sa.Integer(), nullable=False), |
| 29 | + sa.Column('id', sa.Uuid(), nullable=False), |
| 30 | + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), |
| 31 | + sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True), |
| 32 | + sa.PrimaryKeyConstraint('id', name=op.f('pk_users')) |
| 33 | + ) |
| 34 | + op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True) |
| 35 | + op.create_table('refresh_tokens', |
| 36 | + sa.Column('token_hash', sa.String(length=64), nullable=False), |
| 37 | + sa.Column('user_id', sa.Uuid(), nullable=False), |
| 38 | + sa.Column('family_id', sa.Uuid(), nullable=False), |
| 39 | + sa.Column('device_id', sa.String(length=255), nullable=True), |
| 40 | + sa.Column('device_name', sa.String(length=100), nullable=True), |
| 41 | + sa.Column('ip_address', sa.String(length=45), nullable=True), |
| 42 | + sa.Column('expires_at', sa.DateTime(timezone=True), nullable=False), |
| 43 | + sa.Column('is_revoked', sa.Boolean(), nullable=False), |
| 44 | + sa.Column('revoked_at', sa.DateTime(timezone=True), nullable=True), |
| 45 | + sa.Column('id', sa.Uuid(), nullable=False), |
| 46 | + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), |
| 47 | + sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True), |
| 48 | + sa.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('fk_refresh_tokens_user_id_users'), ondelete='CASCADE'), |
| 49 | + sa.PrimaryKeyConstraint('id', name=op.f('pk_refresh_tokens')) |
| 50 | + ) |
| 51 | + op.create_index(op.f('ix_refresh_tokens_expires_at'), 'refresh_tokens', ['expires_at'], unique=False) |
| 52 | + op.create_index(op.f('ix_refresh_tokens_family_id'), 'refresh_tokens', ['family_id'], unique=False) |
| 53 | + op.create_index(op.f('ix_refresh_tokens_token_hash'), 'refresh_tokens', ['token_hash'], unique=True) |
| 54 | + op.create_index(op.f('ix_refresh_tokens_user_id'), 'refresh_tokens', ['user_id'], unique=False) |
| 55 | + # ### end Alembic commands ### |
| 56 | + |
| 57 | + |
| 58 | +def downgrade() -> None: |
| 59 | + # ### commands auto generated by Alembic - please adjust! ### |
| 60 | + op.drop_index(op.f('ix_refresh_tokens_user_id'), table_name='refresh_tokens') |
| 61 | + op.drop_index(op.f('ix_refresh_tokens_token_hash'), table_name='refresh_tokens') |
| 62 | + op.drop_index(op.f('ix_refresh_tokens_family_id'), table_name='refresh_tokens') |
| 63 | + op.drop_index(op.f('ix_refresh_tokens_expires_at'), table_name='refresh_tokens') |
| 64 | + op.drop_table('refresh_tokens') |
| 65 | + op.drop_index(op.f('ix_users_email'), table_name='users') |
| 66 | + op.drop_table('users') |
| 67 | + # ### end Alembic commands ### |
0 commit comments