feat(backend): каркас — конфиг, движок БД, базовые модели и первая миграция
SQLAlchemy 2 async на asyncpg, Alembic, pydantic-settings. Деньги везде NUMERIC(24,10) с колонкой валюты рядом (db/base.py), postgres-enum'ы хранят значения, а не имена, чтобы база читалась так же, как API. Первая миграция: app_user, account, portfolio, instrument, sync_run, sync_job. metrics/refresh.py задаёт порядок пересборки metric_* и сериализует параллельные пересчёты advisory-локом на отдельном соединении: каждый шаг заменяет свою таблицу целиком, два одновременных прогона затёрли бы друг друга.
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
"""ORM models. Importing this package registers every table on `Base.metadata`."""
|
||||
|
||||
from fintracker.models.accounts import (
|
||||
Account,
|
||||
AccountKind,
|
||||
AccountLink,
|
||||
AccountRole,
|
||||
Broker,
|
||||
EventSource,
|
||||
Portfolio,
|
||||
PortfolioAccount,
|
||||
)
|
||||
from fintracker.models.auth import AppUser, RefreshToken
|
||||
from fintracker.models.instruments import AssetClass, Instrument, InstrumentAlias
|
||||
from fintracker.models.ledger import (
|
||||
EXTERNAL_FLOW_KINDS,
|
||||
POSITION_KINDS,
|
||||
Event,
|
||||
EventKind,
|
||||
EventStatus,
|
||||
Lot,
|
||||
LotDisposal,
|
||||
)
|
||||
from fintracker.models.metrics import (
|
||||
MetricCashFlowMonthly,
|
||||
MetricDataQuality,
|
||||
MetricHolding,
|
||||
MetricNetWorthDaily,
|
||||
MetricPortfolioValueDaily,
|
||||
MetricRefreshLog,
|
||||
MetricReturns,
|
||||
MetricRunway,
|
||||
MetricSpendingByCategory,
|
||||
)
|
||||
from fintracker.models.pricing import (
|
||||
CashSnapshot,
|
||||
CorporateAction,
|
||||
CorporateActionKind,
|
||||
CorporateActionStatus,
|
||||
FxRateDaily,
|
||||
PositionSnapshot,
|
||||
PriceDaily,
|
||||
PriceLast,
|
||||
PriceManual,
|
||||
RawCbrRate,
|
||||
)
|
||||
from fintracker.models.sync import (
|
||||
JobStatus,
|
||||
RunStatus,
|
||||
SourceCredential,
|
||||
SyncJob,
|
||||
SyncRun,
|
||||
SyncState,
|
||||
)
|
||||
from fintracker.models.tinvest import (
|
||||
RawTinvestEvent,
|
||||
RawTinvestInstrument,
|
||||
RawTinvestOperation,
|
||||
RawTinvestSnapshot,
|
||||
)
|
||||
from fintracker.models.zenmoney import (
|
||||
CashTxn,
|
||||
CashTxnTag,
|
||||
Category,
|
||||
FlowType,
|
||||
Merchant,
|
||||
RawZenmoneyDeletion,
|
||||
RawZenmoneyEntity,
|
||||
Rule,
|
||||
RuleKind,
|
||||
RuleMatchType,
|
||||
Trip,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"EXTERNAL_FLOW_KINDS",
|
||||
"POSITION_KINDS",
|
||||
"Account",
|
||||
"AccountKind",
|
||||
"AccountLink",
|
||||
"AccountRole",
|
||||
"AppUser",
|
||||
"AssetClass",
|
||||
"Broker",
|
||||
"CashSnapshot",
|
||||
"CashTxn",
|
||||
"CashTxnTag",
|
||||
"Category",
|
||||
"CorporateAction",
|
||||
"CorporateActionKind",
|
||||
"CorporateActionStatus",
|
||||
"Event",
|
||||
"EventKind",
|
||||
"EventSource",
|
||||
"EventStatus",
|
||||
"FlowType",
|
||||
"FxRateDaily",
|
||||
"Instrument",
|
||||
"InstrumentAlias",
|
||||
"JobStatus",
|
||||
"Lot",
|
||||
"LotDisposal",
|
||||
"Merchant",
|
||||
"MetricCashFlowMonthly",
|
||||
"MetricDataQuality",
|
||||
"MetricHolding",
|
||||
"MetricNetWorthDaily",
|
||||
"MetricPortfolioValueDaily",
|
||||
"MetricRefreshLog",
|
||||
"MetricReturns",
|
||||
"MetricRunway",
|
||||
"MetricSpendingByCategory",
|
||||
"Portfolio",
|
||||
"PortfolioAccount",
|
||||
"PositionSnapshot",
|
||||
"PriceDaily",
|
||||
"PriceLast",
|
||||
"PriceManual",
|
||||
"RawCbrRate",
|
||||
"RawTinvestEvent",
|
||||
"RawTinvestInstrument",
|
||||
"RawTinvestOperation",
|
||||
"RawTinvestSnapshot",
|
||||
"RawZenmoneyDeletion",
|
||||
"RawZenmoneyEntity",
|
||||
"RefreshToken",
|
||||
"Rule",
|
||||
"RuleKind",
|
||||
"RuleMatchType",
|
||||
"RunStatus",
|
||||
"SourceCredential",
|
||||
"SyncJob",
|
||||
"SyncRun",
|
||||
"SyncState",
|
||||
"Trip",
|
||||
]
|
||||
Reference in New Issue
Block a user