Karan6124 commited on
Commit
ccc846c
·
1 Parent(s): e0883b3

feat: generate and apply initial database migrations to NeonDB

Browse files
alembic/versions/3d7629451f7d_initial_schema.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """initial_schema
2
+
3
+ Revision ID: 3d7629451f7d
4
+ Revises:
5
+ Create Date: 2026-06-11 18:35:41.987996
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 = '3d7629451f7d'
16
+ down_revision: Union[str, Sequence[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
+ """Upgrade schema."""
23
+ # ### commands auto generated by Alembic - please adjust! ###
24
+ op.create_table('stock_history',
25
+ sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
26
+ sa.Column('ticker', sa.String(length=50), nullable=False),
27
+ sa.Column('timestamp', sa.DateTime(timezone=True), nullable=False),
28
+ sa.Column('open', sa.Float(), nullable=False),
29
+ sa.Column('high', sa.Float(), nullable=False),
30
+ sa.Column('low', sa.Float(), nullable=False),
31
+ sa.Column('close', sa.Float(), nullable=False),
32
+ sa.Column('volume', sa.BigInteger(), nullable=False),
33
+ sa.PrimaryKeyConstraint('id'),
34
+ sa.UniqueConstraint('ticker', 'timestamp', name='uq_ticker_timestamp')
35
+ )
36
+ op.create_index(op.f('ix_stock_history_ticker'), 'stock_history', ['ticker'], unique=False)
37
+ op.create_index(op.f('ix_stock_history_timestamp'), 'stock_history', ['timestamp'], unique=False)
38
+ op.create_table('users',
39
+ sa.Column('id', sa.Uuid(), nullable=False),
40
+ sa.Column('email', sa.String(length=255), nullable=False),
41
+ sa.Column('full_name', sa.String(length=255), nullable=True),
42
+ sa.Column('google_id', sa.String(length=255), nullable=False),
43
+ sa.Column('picture_url', sa.String(length=500), nullable=True),
44
+ sa.Column('credits', sa.Integer(), nullable=False),
45
+ sa.Column('last_credit_refresh', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
46
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
47
+ sa.PrimaryKeyConstraint('id')
48
+ )
49
+ op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
50
+ op.create_index(op.f('ix_users_google_id'), 'users', ['google_id'], unique=True)
51
+ op.create_table('alerts',
52
+ sa.Column('id', sa.Uuid(), nullable=False),
53
+ sa.Column('user_id', sa.Uuid(), nullable=False),
54
+ sa.Column('ticker', sa.String(length=50), nullable=False),
55
+ sa.Column('target_price', sa.Float(), nullable=False),
56
+ sa.Column('condition', sa.String(length=20), nullable=False),
57
+ sa.Column('is_active', sa.Boolean(), nullable=False),
58
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
59
+ sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
60
+ sa.PrimaryKeyConstraint('id')
61
+ )
62
+ op.create_index(op.f('ix_alerts_ticker'), 'alerts', ['ticker'], unique=False)
63
+ op.create_index(op.f('ix_alerts_user_id'), 'alerts', ['user_id'], unique=False)
64
+ op.create_table('payment_transactions',
65
+ sa.Column('id', sa.Uuid(), nullable=False),
66
+ sa.Column('user_id', sa.Uuid(), nullable=False),
67
+ sa.Column('razorpay_order_id', sa.String(length=255), nullable=False),
68
+ sa.Column('razorpay_payment_id', sa.String(length=255), nullable=True),
69
+ sa.Column('amount', sa.Integer(), nullable=False),
70
+ sa.Column('status', sa.String(length=50), nullable=False),
71
+ sa.Column('credits_credited', sa.Integer(), nullable=False),
72
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
73
+ sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
74
+ sa.PrimaryKeyConstraint('id')
75
+ )
76
+ op.create_index(op.f('ix_payment_transactions_razorpay_order_id'), 'payment_transactions', ['razorpay_order_id'], unique=True)
77
+ op.create_index(op.f('ix_payment_transactions_razorpay_payment_id'), 'payment_transactions', ['razorpay_payment_id'], unique=True)
78
+ op.create_table('watchlists',
79
+ sa.Column('id', sa.Uuid(), nullable=False),
80
+ sa.Column('user_id', sa.Uuid(), nullable=False),
81
+ sa.Column('ticker', sa.String(length=50), nullable=False),
82
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
83
+ sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
84
+ sa.PrimaryKeyConstraint('id')
85
+ )
86
+ op.create_index(op.f('ix_watchlists_ticker'), 'watchlists', ['ticker'], unique=False)
87
+ op.create_index(op.f('ix_watchlists_user_id'), 'watchlists', ['user_id'], unique=False)
88
+ # ### end Alembic commands ###
89
+
90
+
91
+ def downgrade() -> None:
92
+ """Downgrade schema."""
93
+ # ### commands auto generated by Alembic - please adjust! ###
94
+ op.drop_index(op.f('ix_watchlists_user_id'), table_name='watchlists')
95
+ op.drop_index(op.f('ix_watchlists_ticker'), table_name='watchlists')
96
+ op.drop_table('watchlists')
97
+ op.drop_index(op.f('ix_payment_transactions_razorpay_payment_id'), table_name='payment_transactions')
98
+ op.drop_index(op.f('ix_payment_transactions_razorpay_order_id'), table_name='payment_transactions')
99
+ op.drop_table('payment_transactions')
100
+ op.drop_index(op.f('ix_alerts_user_id'), table_name='alerts')
101
+ op.drop_index(op.f('ix_alerts_ticker'), table_name='alerts')
102
+ op.drop_table('alerts')
103
+ op.drop_index(op.f('ix_users_google_id'), table_name='users')
104
+ op.drop_index(op.f('ix_users_email'), table_name='users')
105
+ op.drop_table('users')
106
+ op.drop_index(op.f('ix_stock_history_timestamp'), table_name='stock_history')
107
+ op.drop_index(op.f('ix_stock_history_ticker'), table_name='stock_history')
108
+ op.drop_table('stock_history')
109
+ # ### end Alembic commands ###