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