[+] add Ticker table
This commit is contained in:
parent
3f1e8c57ac
commit
60ef0e386d
@ -8,6 +8,8 @@ from sqlalchemy.ext.asyncio import async_engine_from_config
|
|||||||
from sqlalchemy import engine_from_config
|
from sqlalchemy import engine_from_config
|
||||||
from sqlalchemy import pool
|
from sqlalchemy import pool
|
||||||
|
|
||||||
|
from sqlalchemy.engine.base import Connection
|
||||||
|
|
||||||
from alembic import context
|
from alembic import context
|
||||||
|
|
||||||
from online.fxreader.pr34.test_task_2025_06_30_v1.tickers.settings import Settings
|
from online.fxreader.pr34.test_task_2025_06_30_v1.tickers.settings import Settings
|
||||||
@ -47,7 +49,9 @@ target_metadata = Base.metadata
|
|||||||
# ... etc.
|
# ... etc.
|
||||||
|
|
||||||
|
|
||||||
def do_run_migrations(connection):
|
def do_run_migrations(
|
||||||
|
connection: Connection,
|
||||||
|
):
|
||||||
context.configure(connection=connection, target_metadata=target_metadata)
|
context.configure(connection=connection, target_metadata=target_metadata)
|
||||||
|
|
||||||
with context.begin_transaction():
|
with context.begin_transaction():
|
||||||
|
38
deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/tickers/alembic/versions/eb63f793db3a_add_ticker_table.py
vendored
Normal file
38
deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/tickers/alembic/versions/eb63f793db3a_add_ticker_table.py
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
"""add Ticker table
|
||||||
|
|
||||||
|
Revision ID: eb63f793db3a
|
||||||
|
Revises: 335b4c4f052c
|
||||||
|
Create Date: 2025-07-07 10:32:49.812738
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = 'eb63f793db3a'
|
||||||
|
down_revision: Union[str, Sequence[str], None] = '335b4c4f052c'
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
"""Upgrade schema."""
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('tickers_ticker',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('timestamp', sa.DateTime(), nullable=False),
|
||||||
|
sa.Column('value', sa.Numeric(precision=32, scale=6), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['id'], ['tickers_market.id'], ondelete='CASCADE'),
|
||||||
|
sa.UniqueConstraint('id', 'timestamp')
|
||||||
|
)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
"""Downgrade schema."""
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_table('tickers_ticker')
|
||||||
|
# ### end Alembic commands ###
|
28
deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/tickers/models.py
vendored
28
deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/tickers/models.py
vendored
@ -1,3 +1,6 @@
|
|||||||
|
import datetime
|
||||||
|
import decimal
|
||||||
|
|
||||||
from sqlalchemy.orm import (
|
from sqlalchemy.orm import (
|
||||||
mapped_column,
|
mapped_column,
|
||||||
Mapped,
|
Mapped,
|
||||||
@ -6,6 +9,8 @@ from sqlalchemy.orm import (
|
|||||||
from sqlalchemy import (
|
from sqlalchemy import (
|
||||||
String,
|
String,
|
||||||
ForeignKey,
|
ForeignKey,
|
||||||
|
Numeric,
|
||||||
|
UniqueConstraint,
|
||||||
)
|
)
|
||||||
|
|
||||||
from typing import (Optional,)
|
from typing import (Optional,)
|
||||||
@ -21,3 +26,26 @@ class Market(Base):
|
|||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"Market(id={self.id!r}, name={self.name!r})"
|
return f"Market(id={self.id!r}, name={self.name!r})"
|
||||||
|
|
||||||
|
class Ticker(Base):
|
||||||
|
__tablename__ = 'tickers_ticker'
|
||||||
|
|
||||||
|
id: Mapped[int] = mapped_column(ForeignKey(
|
||||||
|
'tickers_market.id',
|
||||||
|
ondelete='CASCADE',
|
||||||
|
))
|
||||||
|
timestamp: Mapped[datetime.datetime] = mapped_column()
|
||||||
|
value: Mapped[decimal.Decimal] = mapped_column(Numeric(
|
||||||
|
precision=32, scale=6,
|
||||||
|
))
|
||||||
|
|
||||||
|
__table_args__ = (
|
||||||
|
UniqueConstraint('id', 'timestamp'),
|
||||||
|
)
|
||||||
|
|
||||||
|
__mapper_args__ = dict(
|
||||||
|
primary_key=('id', 'timestamp',)
|
||||||
|
)
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f"Ticker(id={self.id!r}, timestamp={self.timestamp!r}, value={self.value!r})"
|
||||||
|
Loading…
Reference in New Issue
Block a user