Major overhaul of db -> hypertable conversion, updated GUI, added inventory
This commit is contained in:
parent
fdf9f04bc6
commit
f218350959
8 changed files with 1565 additions and 210 deletions
28
db_async.py
28
db_async.py
|
|
@ -7,12 +7,12 @@ import os
|
|||
import sqlalchemy
|
||||
from databases import Database
|
||||
from sqlalchemy import MetaData, Table, Column, Integer, String, Float, DateTime, text
|
||||
from sqlalchemy import Index
|
||||
from sqlalchemy import Index, BigInteger, JSON, Boolean, UniqueConstraint
|
||||
|
||||
# Environment: Postgres/TimescaleDB connection URL
|
||||
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://postgres:password@localhost:5432/dereth")
|
||||
# Async database client
|
||||
database = Database(DATABASE_URL)
|
||||
# Async database client with explicit connection pool configuration
|
||||
database = Database(DATABASE_URL, min_size=5, max_size=20)
|
||||
# Metadata for SQLAlchemy Core
|
||||
# SQLAlchemy metadata container for table definitions
|
||||
metadata = MetaData()
|
||||
|
|
@ -35,6 +35,7 @@ telemetry_events = Table(
|
|||
Column("kills_per_hour", Float, nullable=True),
|
||||
Column("onlinetime", String, nullable=True),
|
||||
Column("deaths", Integer, nullable=False),
|
||||
Column("total_deaths", Integer, nullable=True),
|
||||
Column("rares_found", Integer, nullable=False),
|
||||
Column("prismatic_taper_count", Integer, nullable=False),
|
||||
Column("vt_state", String, nullable=True),
|
||||
|
|
@ -104,6 +105,27 @@ rare_events = Table(
|
|||
Column("z", Float, nullable=False),
|
||||
)
|
||||
|
||||
character_inventories = Table(
|
||||
# Stores complete character inventory snapshots with searchable fields
|
||||
"character_inventories",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True),
|
||||
Column("character_name", String, nullable=False, index=True),
|
||||
Column("item_id", BigInteger, nullable=False),
|
||||
Column("timestamp", DateTime(timezone=True), nullable=False),
|
||||
# Extracted searchable fields
|
||||
Column("name", String),
|
||||
Column("icon", Integer),
|
||||
Column("object_class", Integer, index=True),
|
||||
Column("value", Integer, index=True),
|
||||
Column("burden", Integer),
|
||||
Column("has_id_data", Boolean),
|
||||
# Complete item data as JSONB
|
||||
Column("item_data", JSON, nullable=False),
|
||||
# Unique constraint to prevent duplicate items per character
|
||||
UniqueConstraint("character_name", "item_id", name="uq_char_item"),
|
||||
)
|
||||
|
||||
async def init_db_async():
|
||||
"""Initialize PostgreSQL/TimescaleDB schema and hypertable.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue