Skip to content

Commit

Permalink
Add Alembic migration for new Order model and update import path
Browse files Browse the repository at this point in the history
  • Loading branch information
beeguy74 committed Mar 7, 2025
1 parent 2a3cd63 commit 5bef1ce
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
40 changes: 40 additions & 0 deletions margin_app/app/alembic/versions/2025-03-07_new_model_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""new model order
Revision ID: af5d55a78a12
Revises: fe041c2f01ee
Create Date: 2025-03-07 21:31:32.954832
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'af5d55a78a12'
down_revision: Union[str, None] = 'fe041c2f01ee'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('order',
sa.Column('user_id', sa.UUID(), nullable=False),
sa.Column('price', sa.Numeric(precision=10, scale=2), nullable=False),
sa.Column('token', sa.VARCHAR(), nullable=False),
sa.Column('position', sa.UUID(), nullable=False),
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('user_id', 'id')
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('order')
# ### end Alembic commands ###
8 changes: 5 additions & 3 deletions margin_app/app/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, mapped_column

from base import BaseModel
from app.models.base import BaseModel


class Order(BaseModel):
Expand All @@ -24,9 +24,11 @@ class Order(BaseModel):
Table:
- Name: "order"
"""

__tablename__ = "order"
user_id: Mapped[UUID] = mapped_column(UUID(as_uuid=True),
ForeignKey("user.id"), primary_key=True)
user_id: Mapped[UUID] = mapped_column(
UUID(as_uuid=True), ForeignKey("user.id"), primary_key=True
)
price: Mapped[float] = mapped_column(Numeric(precision=10, scale=2))
token: Mapped[str] = mapped_column(VARCHAR)
position: Mapped[UUID] = mapped_column(UUID(as_uuid=True))

0 comments on commit 5bef1ce

Please sign in to comment.