|
| 1 | +"""add_wallet_and_transaction_models |
| 2 | +
|
| 3 | +Revision ID: fd8dcfe8d4fd |
| 4 | +Revises: 1a31ce608336 |
| 5 | +Create Date: 2025-09-12 22:28:29.785616 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | +import sqlmodel.sql.sqltypes |
| 11 | + |
| 12 | + |
| 13 | +# revision identifiers, used by Alembic. |
| 14 | +revision = 'fd8dcfe8d4fd' |
| 15 | +down_revision = '1a31ce608336' |
| 16 | +branch_labels = None |
| 17 | +depends_on = None |
| 18 | + |
| 19 | + |
| 20 | +def upgrade(): |
| 21 | + # Create wallet table |
| 22 | + op.create_table( |
| 23 | + 'wallet', |
| 24 | + sa.Column('id', sa.UUID(), nullable=False), |
| 25 | + sa.Column('user_id', sa.UUID(), nullable=False), |
| 26 | + sa.Column('currency', sa.Enum('USD', 'EUR', 'RUB', name='currencyenum'), nullable=False), |
| 27 | + sa.Column('balance', sa.Numeric(precision=10, scale=2), nullable=False), |
| 28 | + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE'), |
| 29 | + sa.PrimaryKeyConstraint('id') |
| 30 | + ) |
| 31 | + |
| 32 | + # Create transaction table |
| 33 | + op.create_table( |
| 34 | + 'transaction', |
| 35 | + sa.Column('id', sa.UUID(), nullable=False), |
| 36 | + sa.Column('wallet_id', sa.UUID(), nullable=False), |
| 37 | + sa.Column('amount', sa.Numeric(precision=10, scale=2), nullable=False), |
| 38 | + sa.Column('type', sa.Enum('credit', 'debit', name='transactiontypeenum'), nullable=False), |
| 39 | + sa.Column('currency', sa.Enum('USD', 'EUR', 'RUB', name='currencyenum'), nullable=False), |
| 40 | + sa.Column('timestamp', sa.DateTime(), nullable=False), |
| 41 | + sa.ForeignKeyConstraint(['wallet_id'], ['wallet.id'], ondelete='CASCADE'), |
| 42 | + sa.PrimaryKeyConstraint('id') |
| 43 | + ) |
| 44 | + |
| 45 | + |
| 46 | +def downgrade(): |
| 47 | + # Drop transaction table |
| 48 | + op.drop_table('transaction') |
| 49 | + |
| 50 | + # Drop wallet table |
| 51 | + op.drop_table('wallet') |
| 52 | + |
| 53 | + # Drop enums |
| 54 | + op.execute('DROP TYPE IF EXISTS transactiontypeenum') |
| 55 | + op.execute('DROP TYPE IF EXISTS currencyenum') |
0 commit comments