fix(trade-dashboard): fix import errors and alembic migration
- database.py: remove dead pre-definition of DATABASE_URL with undefined db_user/db_pass variables - models.py: add missing Table import from sqlalchemy - alembic/env.py: replace deprecated run_async() with asyncio.run() (removed in SQLAlchemy 2.0) - alembic 001_initial: use raw SQL for CREATE TYPE instead of op.create_enum() which requires alembic_postgresql_enum Migration 001_initial successfully applied to trading_data DB.
This commit is contained in:
parent
6599249d65
commit
23c7c707d8
4 changed files with 8 additions and 16 deletions
|
|
@ -54,8 +54,9 @@ async def run_migrations_online() -> None:
|
|||
await connectable.dispose()
|
||||
|
||||
|
||||
import asyncio
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
from sqlalchemy.ext.asyncio import run_async # noqa: E402
|
||||
run_async(run_migrations_online())
|
||||
asyncio.run(run_migrations_online())
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ depends_on = None
|
|||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_enum("position_direction", "long", "short", schema="public", create_type=True)
|
||||
op.execute('CREATE TYPE position_direction AS ENUM (\'long\', \'short\')')
|
||||
|
||||
op.create_table(
|
||||
"positions",
|
||||
|
|
|
|||
|
|
@ -1,17 +1,8 @@
|
|||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
||||
from sqlalchemy import MetaData
|
||||
|
||||
# Connection to hermes-pgdb CNPG cluster
|
||||
DATABASE_URL = (
|
||||
f"postgresql+asyncpg://{db_user}:{db_pass}"
|
||||
f"@hermes-pgdb-rw.customer1.svc.cluster.local:5432/trading_data"
|
||||
).format(
|
||||
db_user="trading",
|
||||
db_pass="TRADING_DB_PASSWORD", # overridden by env
|
||||
)
|
||||
|
||||
import os
|
||||
|
||||
from sqlalchemy import MetaData
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
||||
|
||||
DB_USER = os.getenv("DB_USER", "trading")
|
||||
DB_PASS = os.getenv("DB_PASSWORD", "")
|
||||
DB_HOST = os.getenv("DB_HOST", "hermes-pgdb-rw.customer1.svc.cluster.local")
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from sqlalchemy import Column, String, Numeric, Enum, DateTime, JSON, func
|
||||
from sqlalchemy import Column, String, Numeric, Enum, DateTime, JSON, func, Table
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
import uuid
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue