fix docker file and move trade-dashboard
This commit is contained in:
parent
12ab52de91
commit
c5dd91d112
11 changed files with 1 additions and 1 deletions
62
trade-dashboard/alembic/env.py
Normal file
62
trade-dashboard/alembic/env.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
"""Alembic environment configuration."""
|
||||
|
||||
import sys
|
||||
from logging.config import fileConfig
|
||||
from pathlib import Path
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
from sqlalchemy.ext.asyncio import AsyncEngine
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent / "app"))
|
||||
|
||||
config = context.config
|
||||
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
from models import metadata # noqa: E402
|
||||
|
||||
target_metadata = metadata
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
"""Run migrations in 'offline' mode."""
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(
|
||||
url=url,
|
||||
target_metadata=target_metadata,
|
||||
literal_binds=True,
|
||||
dialect_opts={"paramstyle": "named"},
|
||||
)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def do_run_migrations(connection):
|
||||
context.configure(connection=connection, target_metadata=target_metadata)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
async def run_migrations_online() -> None:
|
||||
"""Run migrations in 'online' mode."""
|
||||
connectable = AsyncEngine(
|
||||
engine_from_config(
|
||||
config.get_section(config.config_ini_section) or {},
|
||||
prefix="sqlalchemy.",
|
||||
poolclass=pool.NullPool,
|
||||
future=True,
|
||||
)
|
||||
)
|
||||
async with connectable.connect() as connection:
|
||||
await connection.run_sync(do_run_migrations)
|
||||
await connectable.dispose()
|
||||
|
||||
|
||||
import asyncio
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
asyncio.run(run_migrations_online())
|
||||
2
trade-dashboard/alembic/script.py.mako
Normal file
2
trade-dashboard/alembic/script.py.mako
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# Alembic migration script - DO NOT EDIT MANUALLY
|
||||
# Use: alembic revision --autogenerate -m "description"
|
||||
43
trade-dashboard/alembic/versions/001_initial.py
Normal file
43
trade-dashboard/alembic/versions/001_initial.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
"""initial schema — positions table
|
||||
|
||||
Revision ID: 001_initial
|
||||
Create Date: 2026-05-02
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision = "001_initial"
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.execute('CREATE TYPE position_direction AS ENUM (\'long\', \'short\')')
|
||||
|
||||
op.create_table(
|
||||
"positions",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
||||
sa.Column("symbol", sa.String(32), nullable=False),
|
||||
sa.Column("direction", postgresql.ENUM("long", "short", name="position_direction", create_type=False), nullable=False),
|
||||
sa.Column("entry_price", sa.Numeric(precision=16, scale=8), nullable=False),
|
||||
sa.Column("exit_price", sa.Numeric(precision=16, scale=8)),
|
||||
sa.Column("quantity", sa.Numeric(precision=16, scale=8), nullable=False),
|
||||
sa.Column("exchange", sa.String(32), nullable=False),
|
||||
sa.Column("opened_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.Column("closed_at", sa.DateTime(timezone=True)),
|
||||
sa.Column("pnl", sa.Numeric(precision=16, scale=2)),
|
||||
sa.Column("metadata", sa.JSON),
|
||||
)
|
||||
|
||||
op.create_index(op.f("ix_positions_symbol"), "positions", ["symbol"])
|
||||
op.create_index(op.f("ix_positions_exchange"), "positions", ["exchange"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(op.f("ix_positions_exchange"), table_name="positions")
|
||||
op.drop_index(op.f("ix_positions_symbol"), table_name="positions")
|
||||
op.drop_table("positions")
|
||||
op.execute("DROP TYPE IF EXISTS position_direction")
|
||||
Loading…
Reference in a new issue