refactor(models): add explicit foreign key constraints for indicators
This commit is contained in:
parent
f5aa0e5848
commit
13d5987e49
@ -1,4 +1,4 @@
|
|||||||
from sqlmodel import SQLModel, Field, Relationship
|
from sqlmodel import SQLModel, Field, Relationship, ForeignKeyConstraint
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
@ -17,18 +17,18 @@ class TickerOHLCV(SQLModel, table=True):
|
|||||||
|
|
||||||
indicators: Optional["IndicatorsData"] = Relationship(
|
indicators: Optional["IndicatorsData"] = Relationship(
|
||||||
back_populates="ohlcv",
|
back_populates="ohlcv",
|
||||||
sa_relationship_kwargs={
|
sa_relationship_kwargs={"uselist": False},
|
||||||
"foreign_keys": "[IndicatorsData.ticker, IndicatorsData.date]",
|
|
||||||
"uselist": False,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class IndicatorsData(SQLModel, table=True):
|
class IndicatorsData(SQLModel, table=True):
|
||||||
__tablename__ = "indicators"
|
__tablename__ = "indicators"
|
||||||
|
__table_args__ = (
|
||||||
|
ForeignKeyConstraint(["ticker", "date"], ["ohlcv.ticker", "ohlcv.date"]),
|
||||||
|
)
|
||||||
|
|
||||||
ticker: str = Field(foreign_key="ohlcv.ticker", primary_key=True)
|
ticker: str = Field(primary_key=True)
|
||||||
date: datetime = Field(foreign_key="ohlcv.date", primary_key=True, index=True)
|
date: datetime = Field(primary_key=True, index=True)
|
||||||
|
|
||||||
# ========================================================================
|
# ========================================================================
|
||||||
# MOMENTUM INDICATORS (Trend Direction & Strength)
|
# MOMENTUM INDICATORS (Trend Direction & Strength)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user