|
| 1 | +"""auto generated db tables |
| 2 | +
|
| 3 | +Revision ID: da30e7c419f2 |
| 4 | +Revises: |
| 5 | +Create Date: 2024-11-04 23:45:59.654459 |
| 6 | +
|
| 7 | +""" |
| 8 | +from typing import Sequence, Union |
| 9 | + |
| 10 | +from alembic import op |
| 11 | +import sqlalchemy as sa |
| 12 | + |
| 13 | + |
| 14 | +# revision identifiers, used by Alembic. |
| 15 | +revision: str = 'da30e7c419f2' |
| 16 | +down_revision: Union[str, None] = None |
| 17 | +branch_labels: Union[str, Sequence[str], None] = None |
| 18 | +depends_on: Union[str, Sequence[str], None] = None |
| 19 | + |
| 20 | + |
| 21 | +def upgrade() -> None: |
| 22 | + # ### commands auto generated by Alembic - please adjust! ### |
| 23 | + op.create_table('registration_requests', |
| 24 | + sa.Column('user_id', sa.Integer(), autoincrement=True, nullable=False), |
| 25 | + sa.Column('user_name', sa.String(length=150), nullable=False), |
| 26 | + sa.Column('email', sa.String(length=255), nullable=False), |
| 27 | + sa.Column('password', sa.String(length=100), nullable=False), |
| 28 | + sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False), |
| 29 | + sa.PrimaryKeyConstraint('user_id'), |
| 30 | + sa.UniqueConstraint('user_id') |
| 31 | + ) |
| 32 | + op.create_index(op.f('ix_registration_requests_email'), 'registration_requests', ['email'], unique=True) |
| 33 | + op.create_table('roles', |
| 34 | + sa.Column('role_id', sa.Integer(), autoincrement=True, nullable=False), |
| 35 | + sa.Column('role_name', sa.String(length=50), nullable=False), |
| 36 | + sa.PrimaryKeyConstraint('role_id'), |
| 37 | + sa.UniqueConstraint('role_id'), |
| 38 | + sa.UniqueConstraint('role_name') |
| 39 | + ) |
| 40 | + op.create_table('users', |
| 41 | + sa.Column('user_id', sa.Integer(), autoincrement=True, nullable=False), |
| 42 | + sa.Column('user_name', sa.String(length=150), nullable=False), |
| 43 | + sa.Column('email', sa.String(length=255), nullable=False), |
| 44 | + sa.Column('password', sa.String(length=100), nullable=False), |
| 45 | + sa.Column('status', sa.String(), server_default=sa.text("'active'"), nullable=False), |
| 46 | + sa.Column('verified_at', sa.TIMESTAMP(timezone=True), nullable=True), |
| 47 | + sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False), |
| 48 | + sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False), |
| 49 | + sa.PrimaryKeyConstraint('user_id'), |
| 50 | + sa.UniqueConstraint('user_id') |
| 51 | + ) |
| 52 | + op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True) |
| 53 | + op.create_table('codes', |
| 54 | + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), |
| 55 | + sa.Column('user_id', sa.Integer(), nullable=False), |
| 56 | + sa.Column('code', sa.String(), nullable=False), |
| 57 | + sa.Column('expires_at', sa.TIMESTAMP(timezone=True), nullable=False), |
| 58 | + sa.ForeignKeyConstraint(['user_id'], ['users.user_id'], ondelete='CASCADE'), |
| 59 | + sa.PrimaryKeyConstraint('id'), |
| 60 | + sa.UniqueConstraint('id') |
| 61 | + ) |
| 62 | + op.create_index(op.f('ix_codes_code'), 'codes', ['code'], unique=False) |
| 63 | + op.create_index(op.f('ix_codes_user_id'), 'codes', ['user_id'], unique=False) |
| 64 | + op.create_table('user_roles', |
| 65 | + sa.Column('user_id', sa.Integer(), nullable=True), |
| 66 | + sa.Column('role_id', sa.Integer(), nullable=True), |
| 67 | + sa.ForeignKeyConstraint(['role_id'], ['roles.role_id'], ondelete='CASCADE'), |
| 68 | + sa.ForeignKeyConstraint(['user_id'], ['users.user_id'], ondelete='CASCADE') |
| 69 | + ) |
| 70 | + op.create_table('user_tokens', |
| 71 | + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), |
| 72 | + sa.Column('user_id', sa.Integer(), nullable=False), |
| 73 | + sa.Column('access_key', sa.String(length=250), nullable=False), |
| 74 | + sa.Column('refresh_key', sa.String(length=250), nullable=False), |
| 75 | + sa.Column('device_id', sa.String(), nullable=False), |
| 76 | + sa.Column('device_name', sa.String(), server_default=sa.text("'NONAME'"), nullable=False), |
| 77 | + sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False), |
| 78 | + sa.Column('last_used_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False), |
| 79 | + sa.Column('expires_at', sa.TIMESTAMP(timezone=True), nullable=False), |
| 80 | + sa.ForeignKeyConstraint(['user_id'], ['users.user_id'], ondelete='CASCADE'), |
| 81 | + sa.PrimaryKeyConstraint('id') |
| 82 | + ) |
| 83 | + op.create_index(op.f('ix_user_tokens_access_key'), 'user_tokens', ['access_key'], unique=False) |
| 84 | + op.create_index(op.f('ix_user_tokens_device_id'), 'user_tokens', ['device_id'], unique=False) |
| 85 | + op.create_index(op.f('ix_user_tokens_refresh_key'), 'user_tokens', ['refresh_key'], unique=False) |
| 86 | + op.create_index(op.f('ix_user_tokens_user_id'), 'user_tokens', ['user_id'], unique=False) |
| 87 | + op.create_table('verification_codes', |
| 88 | + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), |
| 89 | + sa.Column('user_id', sa.Integer(), nullable=False), |
| 90 | + sa.Column('code', sa.String(), nullable=False), |
| 91 | + sa.Column('expires_at', sa.TIMESTAMP(timezone=True), nullable=False), |
| 92 | + sa.ForeignKeyConstraint(['user_id'], ['users.user_id'], ondelete='CASCADE'), |
| 93 | + sa.PrimaryKeyConstraint('id'), |
| 94 | + sa.UniqueConstraint('id') |
| 95 | + ) |
| 96 | + op.create_index(op.f('ix_verification_codes_code'), 'verification_codes', ['code'], unique=False) |
| 97 | + op.create_index(op.f('ix_verification_codes_user_id'), 'verification_codes', ['user_id'], unique=False) |
| 98 | + op.create_table('verification_codes_opt', |
| 99 | + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), |
| 100 | + sa.Column('user_id', sa.Integer(), nullable=False), |
| 101 | + sa.Column('code', sa.String(), nullable=False), |
| 102 | + sa.Column('expires_at', sa.TIMESTAMP(timezone=True), nullable=False), |
| 103 | + sa.ForeignKeyConstraint(['user_id'], ['registration_requests.user_id'], ondelete='CASCADE'), |
| 104 | + sa.PrimaryKeyConstraint('id'), |
| 105 | + sa.UniqueConstraint('id') |
| 106 | + ) |
| 107 | + op.create_index(op.f('ix_verification_codes_opt_code'), 'verification_codes_opt', ['code'], unique=False) |
| 108 | + op.create_index(op.f('ix_verification_codes_opt_user_id'), 'verification_codes_opt', ['user_id'], unique=False) |
| 109 | + # ### end Alembic commands ### |
| 110 | + |
| 111 | + |
| 112 | +def downgrade() -> None: |
| 113 | + # ### commands auto generated by Alembic - please adjust! ### |
| 114 | + op.drop_index(op.f('ix_verification_codes_opt_user_id'), table_name='verification_codes_opt') |
| 115 | + op.drop_index(op.f('ix_verification_codes_opt_code'), table_name='verification_codes_opt') |
| 116 | + op.drop_table('verification_codes_opt') |
| 117 | + op.drop_index(op.f('ix_verification_codes_user_id'), table_name='verification_codes') |
| 118 | + op.drop_index(op.f('ix_verification_codes_code'), table_name='verification_codes') |
| 119 | + op.drop_table('verification_codes') |
| 120 | + op.drop_index(op.f('ix_user_tokens_user_id'), table_name='user_tokens') |
| 121 | + op.drop_index(op.f('ix_user_tokens_refresh_key'), table_name='user_tokens') |
| 122 | + op.drop_index(op.f('ix_user_tokens_device_id'), table_name='user_tokens') |
| 123 | + op.drop_index(op.f('ix_user_tokens_access_key'), table_name='user_tokens') |
| 124 | + op.drop_table('user_tokens') |
| 125 | + op.drop_table('user_roles') |
| 126 | + op.drop_index(op.f('ix_codes_user_id'), table_name='codes') |
| 127 | + op.drop_index(op.f('ix_codes_code'), table_name='codes') |
| 128 | + op.drop_table('codes') |
| 129 | + op.drop_index(op.f('ix_users_email'), table_name='users') |
| 130 | + op.drop_table('users') |
| 131 | + op.drop_table('roles') |
| 132 | + op.drop_index(op.f('ix_registration_requests_email'), table_name='registration_requests') |
| 133 | + op.drop_table('registration_requests') |
| 134 | + # ### end Alembic commands ### |
0 commit comments